Text-to-Speech
Convert text to audio using ElevenLabs voices.
POST /api/ai/generate-audio
Request Body
Text to convert to speech (max ~5000 characters)
Voice ID or name. Options: rachel, adam, josh, bella, antoni, domi
Response
Returns raw MP3 audio with Content-Type: audio/mpeg header.
Example
const response = await fetch ( 'http://localhost:3001/api/ai/generate-audio' , {
method: 'POST' ,
headers: { 'Content-Type' : 'application/json' },
body: JSON . stringify ({
text: 'Your simulation shows a 78% probability of success.' ,
voice: 'josh'
})
})
const audioBlob = await response . blob ()
const audioUrl = URL . createObjectURL ( audioBlob )
const audio = new Audio ( audioUrl )
audio . play ()
Stream Audio
Stream audio generation for real-time playback (lower latency).
POST /api/ai/stream-audio
Request Body
Same as /generate-audio.
Response
Returns chunked audio stream with Transfer-Encoding: chunked.
Speech-to-Text
Transcribe audio to text.
Request Body
Base64-encoded audio data (MP3, WAV, or OGG)
Response
Transcribed text from the audio
Example
// Convert audio file to base64
const audioFile = await fetch ( '/path/to/audio.mp3' )
const audioBuffer = await audioFile . arrayBuffer ()
const base64Audio = btoa (
new Uint8Array ( audioBuffer ). reduce (( data , byte ) => data + String . fromCharCode ( byte ), '' )
)
const response = await fetch ( 'http://localhost:3001/api/ai/transcribe' , {
method: 'POST' ,
headers: { 'Content-Type' : 'application/json' },
body: JSON . stringify ({ audio: base64Audio })
})
const { transcript } = await response . json ()
console . log ( 'User said:' , transcript )
Voice Goal Conversation
Multi-turn voice conversation for setting financial goals.
Request Body
Base64-encoded audio (optional if text provided)
Text input (optional if audio provided)
Array of previous messages in the conversation Either “user” or “assistant”
Response
Transcribed text from user’s audio (if audio was provided)
AI assistant’s text response
Whether the goal has been fully specified
Structured goal data (only present if isComplete is true)
Base64-encoded audio of assistant’s response (if ElevenLabs configured)
Whether audio was generated
Example
const response = await fetch ( 'http://localhost:3001/api/ai/voice-goal' , {
method: 'POST' ,
headers: { 'Content-Type' : 'application/json' },
body: JSON . stringify ({
text: 'I want to save for a house' ,
conversationHistory: []
})
})
const { assistantResponse , isComplete , parsedGoal } = await response . json ()
console . log ( assistantResponse )
// "Great! How much are you looking to save, and when do you want to achieve this goal?"
if ( isComplete ) {
console . log ( 'Goal:' , parsedGoal )
}
Voice Results Conversation
Discuss simulation results through voice interaction.
POST /api/ai/voice-results
Request Body
Base64-encoded audio (optional if text provided)
Text input (optional if audio provided)
Previous conversation messages
Simulation context for the conversation Results from the simulation
Response
Base64-encoded audio response
Whether audio was generated
Get Available Voices
List all available ElevenLabs voices.
Response
Whether ElevenLabs is configured
Array of available voices Voice ID for API requests
Human-readable voice name
Example
const response = await fetch ( 'http://localhost:3001/api/ai/voices' )
const { configured , voices } = await response . json ()
voices . forEach ( voice => {
console . log ( ` ${ voice . name } : ${ voice . description } ` )
})
// Josh: Energetic, celebratory
// Adam: Confident, encouraging
// Bella: Empathetic, supportive
All voice endpoints require ELEVENLABS_API_KEY to be configured. Without it, endpoints return 503 Service Unavailable.