Audio

Transcribe audio to text and generate speech from text via LiteLLM

Transcribe audio files to text and generate speech from text using any LiteLLM-supported provider (OpenAI Whisper, Deepgram, ElevenLabs, …).

Diagram

Audio Capability

🎙️ Audio file

📝 transcribe

📝 Text

🔊 speech

Quick Start

  1. Give an Agent a transcription tool
    python
    from praisonaiagents import Agent
    from praisonai.capabilities import transcribe
    
    agent = Agent(
        name="MeetingSummariser",
        instructions="Transcribe the audio, then produce a bullet-point summary.",
        tools=[transcribe],
    )
    agent.start("Transcribe ./meeting.mp3 and summarise the decisions.")
  2. Transcribe directly (Whisper default)
    python
    from praisonai.capabilities import transcribe
    
    result = transcribe("./meeting.mp3")
    print(result.text)
  3. Generate speech from text
    python
    from praisonai.capabilities import speech
    
    result = speech("Hello, world!", voice="nova")
    result.save("hello.mp3")
  4. Use the async variants
    python
    import asyncio
    from praisonai.capabilities import atranscribe, aspeech
    
    async def main():
        transcript = await atranscribe("./meeting.mp3")
        audio = await aspeech(transcript.text, voice="nova")
        audio.save("readback.mp3")
    
    asyncio.run(main())
  5. Switch providers without changing code
    python
    result = transcribe("./meeting.mp3", model="deepgram/nova-2", language="en")
    print(result.text)

How It Works

Calls route through LiteLLM to the provider that matches your model string.

Diagram
OpenAI / Deepgram / …LiteLLMpraisonai.capabilities.audioUserOpenAI / Deepgram / …LiteLLMpraisonai.capabilities.audioUsertranscribe(“./file.mp3″, model=”whisper-1”)litellm.transcription(model=…, file=…)HTTPS requesttranscript JSONresponseTranscriptionResult(text=…, duration=…, language=…, segments=…, words=…)

Configuration Options

transcribe(...) / atranscribe(...)

OptionTypeDefaultDescription
audio`str \bytes \BinaryIO`requiredFile path, bytes, or file-like object
modelstr"whisper-1"Model name (e.g., whisper-1, deepgram/nova-2)
languageOptional[str]NoneISO language code (e.g., en, es)
promptOptional[str]NoneOptional prompt to guide transcription
response_formatstr"json"json, text, srt, verbose_json, vtt
temperaturefloat0.0Sampling temperature (0.0-1.0)
timestamp_granularitiesOptional[List[str]]NoneList of word and/or segment
timeoutfloat600.0Request timeout in seconds
api_keyOptional[str]NoneOptional API key override
api_baseOptional[str]NoneOptional API base URL override
metadataOptional[Dict[str, Any]]NoneOptional metadata for tracing (agent_id, session_id, etc.)

speech(...) / aspeech(...)

OptionTypeDefaultDescription
textstrrequiredText to convert to speech
modelstr"tts-1"Model name (e.g., tts-1, tts-1-hd, elevenlabs/...)
voicestr"alloy"Voice name (e.g., alloy, echo, fable, onyx, nova, shimmer)
response_formatstr"mp3"mp3, opus, aac, flac, wav, pcm
speedfloat1.0Speed multiplier (0.25-4.0)
timeoutfloat600.0Request timeout in seconds
api_keyOptional[str]NoneOptional API key override
api_baseOptional[str]NoneOptional API base URL override
metadataOptional[Dict[str, Any]]NoneOptional metadata for tracing

Result objects

ClassFieldTypeDefaultNotes
TranscriptionResulttextstr—The transcribed text
durationOptional[float]NoneAudio duration in seconds
languageOptional[str]NoneDetected/echoed language
segmentsOptional[List[Dict]]NonePresent when response_format="verbose_json"
wordsOptional[List[Dict]]NonePresent when timestamp_granularities=["word"]
modelOptional[str]NoneModel used
metadataDict[str, Any]{}Metadata echoed back
SpeechResultaudiobytes—Raw audio bytes
content_typestr"audio/mpeg"Set per response_format
modelOptional[str]NoneModel used
metadataDict[str, Any]{}Tracing metadata
save(path)method—Writes bytes to disk, returns path

Common Patterns

Transcribe → summarise pipeline

python
from praisonaiagents import Agent
from praisonai.capabilities import transcribe

transcript = transcribe("./meeting.mp3")

agent = Agent(
    name="Summariser",
    instructions="Summarise the transcript into bullet-point decisions.",
)
agent.start(transcript.text)

Multilingual dubbing

python
import asyncio
from praisonaiagents import Agent
from praisonai.capabilities import atranscribe, aspeech

async def dub(path):
    transcript = await atranscribe(path, language="es")
    translator = Agent(name="Translator", instructions="Translate Spanish to English.")
    english = translator.start(transcript.text)
    result = await aspeech(english, voice="nova")
    return result.save("dubbed.mp3")

asyncio.run(dub("./clip_es.mp3"))

Word-level timestamps for captions

python
from praisonai.capabilities import transcribe

result = transcribe(
    "./meeting.mp3",
    response_format="verbose_json",
    timestamp_granularities=["word"],
)
for word in result.words or []:
    print(word)

Best Practices

Pick the right model per provider

Use whisper-1 for OpenAI parity, deepgram/nova-2 for lower latency, and tts-1-hd when audio fidelity matters more than cost.

Set language when you know it

Passing language="en" skips detection — faster and more accurate for short clips.

Use save() on SpeechResult

SpeechResult.save("out.mp3") writes the bytes and returns the path — no manual file handling needed.

Route through metadata for tracing

Pass metadata={"agent_id": ..., "session_id": ...} so LiteLLM callbacks correlate audio calls with an Agent turn.


Related