Audio Tools

Text-to-Speech (TTS) and Speech-to-Text (STT) tools for agents

Enable your agents to speak and listen with TTS and STT tools.

python
from praisonaiagents import Agent

agent = Agent(
    name="voice-assistant",
    instructions="Use audio tools when the user sends voice or asks for speech.",
    tools=["text_to_speech", "speech_to_text"],
)
agent.start("Read this reply aloud.")

The user sends voice or asks for spoken output; the agent transcribes input and synthesises replies with STT/TTS tools.

Diagram

Speech-to-Text

🎵 Audio

🎤 STT Tool

📝 Text

Text-to-Speech

📝 Text

🔊 TTS Tool

🎵 Audio File


Quick Start

  1. Bot CLI
    bash
    # Enable TTS tool for your bot
    praisonai bot telegram --token $TOKEN --tts
    
    # Enable both TTS and STT
    praisonai bot telegram --token $TOKEN --tts --stt
    
    # Auto-convert all responses to speech
    praisonai bot telegram --token $TOKEN --auto-tts
  2. Python
    python
    from praisonai.tools.audio import create_tts_tool, create_stt_tool
    from praisonaiagents import Agent
    
    agent = Agent(
        name="voice-assistant",
        instructions="You can speak and listen.",
        tools=[create_tts_tool(), create_stt_tool()],
    )
    
    response = agent.chat("Say hello in audio format")

TTS Tool

Convert text to speech and get an audio file.

Diagram
OpenAI/LiteLLMAudioAgentTTS ToolAgentOpenAI/LiteLLMAudioAgentTTS ToolAgenttts(“Hello world”)speech(text)Generate audioAudio streamSave to fileMEDIA:/path/to/audio.mp3

Usage

Direct Function
from praisonai.tools.audio import tts_tool

result = tts_tool("Hello world!", voice="alloy")

if result["success"]:
    print(result["audio_path"])   # /tmp/tts_abc123.mp3
    print(result["media_line"])   # MEDIA:/tmp/tts_abc123.mp3
As Agent Tool
from praisonai.tools.audio import create_tts_tool
from praisonaiagents import Agent

agent = Agent(
    name="speaker",
    tools=[create_tts_tool()]
)

# Agent calls tts() tool internally
agent.chat("Convert 'Hello world' to speech")

Options

ParameterTypeDefaultDescription
textstrrequiredText to convert
voicestr"alloy"Voice: alloy, echo, fable, onyx, nova, shimmer
modelstr"openai/tts-1"TTS model
output_formatstr"mp3"Format: mp3, opus, aac, flac, wav
output_dirstrtemp dirDirectory to save audio

STT Tool

Transcribe audio files to text.

Diagram
OpenAI/LiteLLMAudioAgentSTT ToolAgentOpenAI/LiteLLMAudioAgentSTT ToolAgentstt(“audio.mp3”)transcribe(file)Whisper APITranscriptionText result“Hello world”

Usage

Direct Function
from praisonai.tools.audio import stt_tool

result = stt_tool("recording.mp3", language="en")

if result["success"]:
    print(result["text"])  # Transcribed text
As Agent Tool
from praisonai.tools.audio import create_stt_tool
from praisonaiagents import Agent

agent = Agent(
    name="listener",
    tools=[create_stt_tool()]
)

# Agent calls stt() tool internally
agent.chat("Transcribe the file at /path/to/audio.mp3")

Options

ParameterTypeDefaultDescription
audio_pathstrrequiredPath to audio file
languagestrautoLanguage code (en, es, fr, etc.)
modelstr"openai/whisper-1"STT model

Bot CLI Options

Enable audio tools when starting bots:

OptionDescription
--ttsEnable TTS tool
--tts-voice VOICEVoice (alloy, echo, fable, onyx, nova, shimmer)
--tts-model MODELTTS model (default: openai/tts-1)
--auto-ttsAuto-convert all responses to speech
--sttEnable STT tool
--stt-model MODELSTT model (default: openai/whisper-1)

Examples

bash
# Basic TTS
praisonai bot telegram --token $TOKEN --tts

# Custom voice
praisonai bot telegram --token $TOKEN --tts --tts-voice nova

# Auto-TTS mode (all responses become audio)
praisonai bot telegram --token $TOKEN --auto-tts

# Full audio capabilities
praisonai bot telegram --token $TOKEN --tts --stt --auto-tts

Supported Providers

Audio tools use the core AudioAgent which supports multiple providers via LiteLLM:

TTS Providers
ProviderModelNotes
OpenAIopenai/tts-1, openai/tts-1-hdDefault, high quality
Azureazure/tts-1Enterprise
ElevenLabselevenlabs/eleven_multilingual_v2Premium voices
Geminigemini/gemini-2.5-flash-preview-ttsGoogle
STT Providers
ProviderModelNotes
OpenAIopenai/whisper-1Default, accurate
Azureazure/whisperEnterprise
Groqgroq/whisper-large-v3Fast
Deepgramdeepgram/nova-2Real-time

Voice Options

Available voices for OpenAI TTS:

VoiceDescription
alloyNeutral, balanced (default)
echoWarm, conversational
fableExpressive, storytelling
onyxDeep, authoritative
novaFriendly, upbeat
shimmerClear, professional

Architecture

Diagram

External

Core SDK (praisonaiagents)

Wrapper Layer (praisonai)

tts_tool

stt_tool

Bot CLI –tts/–stt

AudioAgent

LiteLLM

OpenAI/Azure/etc


Best Practices

Add only the tools the agent needs

Give an agent text_to_speech when it must speak and speech_to_text when it must listen — not both by reflex. Fewer tools keep the model focused and cut the chance it synthesises audio when plain text would do.

Use –auto-tts sparingly

--auto-tts converts every bot reply to speech, which adds cost and latency to short acknowledgements. Prefer --tts and let the model decide when audio adds value, reserving auto-conversion for voice-first channels.

Transcribe inbound voice before reasoning

When users send voice notes, run speech_to_text first so the model reasons over text. This keeps prompts small and lets you log and moderate the transcript like any other message.

Keep provider credentials in the environment

The tools wrap AudioAgent, which calls external TTS/STT providers. Store provider keys as environment variables so voice features work the same across local runs, bots, and CI without editing tool code.


Related