Audio

Text-to-speech and speech-to-text

Agents can speak and listen – convert text to speech and transcribe audio.

Diagram

Audio Processing

speak

listen

👤 User

🤖 Agent

🔊 Audio

📝 Text

Quick Start

  1. Simple Usage
    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({
      instructions: 'You are a helpful assistant',
      audio: true
    });
    
    // Agent response as audio
    const audio = await agent.speak('Hello! How can I help you today?');
    // Returns audio buffer
  2. With Configuration
    typescript
    // Transcribe audio file
    const text = await agent.transcribe('./recording.mp3');
    console.log(text);
    // "This is what was said in the recording..."

User Interaction Flow

Diagram
AudioAgentUserAudioAgentUser“Read this aloud”Generate speech🔊 Audio playback[voice recording]TranscribeText content“You said…”

Configuration Levels

typescript
// Level 1: Bool - Enable with defaults
const agent = new Agent({
  audio: true
});

// Level 2: String - Specify voice
const agent = new Agent({
  audio: 'alloy'  // OpenAI voice name
});

// Level 3: Dict - Full options
const agent = new Agent({
  audio: {
    voice: 'nova',
    model: 'tts-1-hd',
    speed: 1.0,
    format: 'mp3'
  }
});

// Level 4: Instance - AudioAgent
import { AudioAgent } from 'praisonai';

const audio = new AudioAgent({
  provider: 'elevenlabs',
  voice: 'rachel'
});

Audio Options

OptionDescription
voiceVoice name (alloy, echo, nova, etc.)
modelTTS model (tts-1, tts-1-hd)
speedPlayback speed (0.25 to 4.0)
formatOutput format (mp3, wav, opus)

API Reference

AudioConfig

Complete configuration options


Best Practices

Use HD for quality

tts-1-hd sounds more natural but costs more.

Match voice to content

Choose voices that match your content’s tone and audience.

Handle long text

Break long text into chunks for better audio quality.


Related