Skip to main content

Voice Endpoint Format

Cedar OS provides two approaches for handling voice, depending on your provider configuration:
  1. Mastra/Custom backends: Direct voice endpoint handling
  2. AI SDK/OpenAI providers: Automatic transcription and speech generation

Provider-Specific Voice Handling

Mastra and Custom Backends

When using Mastra or custom backends, Cedar OS sends voice data directly to your voice endpoint. You have full control over:
  • Audio transcription
  • Response generation
  • Text-to-speech synthesis
  • Response format

AI SDK and OpenAI Providers

When using AI SDK or OpenAI providers, Cedar OS automatically:
  1. Transcribes audio using OpenAI’s Whisper model
  2. Generates a text response using the configured LLM
  3. Optionally generates speech using OpenAI’s TTS model (when useBrowserTTS is false)

Request Format (Mastra/Custom)

Cedar OS sends voice data to your endpoint as a multipart form data request:

Voice Settings Structure

The settings field contains a JSON object with the following structure:
  • language: Language code for speech recognition/synthesis
  • voiceId: Voice identifier for TTS (provider-specific)
  • pitch, rate, volume: Voice modulation parameters
  • useBrowserTTS: Whether to use browser’s built-in TTS
  • autoAddToMessages: Whether to add voice interactions to chat history

Context

The context field contains stringified additional context from the Cedar state, which may include:
  • Current chat messages
  • Application state
  • User-defined context

Response Format (All Providers)

Your endpoint can return different types of responses:
All fields are optional:
  • text: The text response from the assistant
  • transcription: The transcribed user input
  • audioData: Base64-encoded audio response
  • audioUrl: URL to an audio file
  • audioFormat: MIME type of the audio
  • usage: Token usage statistics
  • object: Structured response for actions

2. Audio Response

Return raw audio data with appropriate content type:

3. Plain Text Response

Implementation Example (Mastra)

Here’s an example of implementing a voice endpoint in a Mastra backend:

Voice Response Handling

Cedar OS provides a unified handleLLMVoice function that processes voice responses consistently across all providers:
  1. Audio Playback: Handles base64 audio data, audio URLs, or browser TTS
  2. Message Integration: Automatically adds transcriptions and responses to chat history
  3. Action Execution: Processes structured responses to trigger state changes

Structured Responses

Cedar OS supports structured responses that can trigger actions in your application:

SetState Response

To execute a state change:
This will call myCustomState.setValue(42) in your Cedar state.

Error Handling

Return appropriate HTTP status codes:
  • 200 OK: Successful response
  • 400 Bad Request: Invalid request format
  • 401 Unauthorized: Missing or invalid API key
  • 500 Internal Server Error: Server-side error

Voice Configuration

Configure voice settings when initializing Cedar:

Provider-Specific Notes

OpenAI/AI SDK

  • Transcription: Uses Whisper model (whisper-1)
  • Speech: Uses TTS model (tts-1) with configurable voices
  • Audio format: MP3 (audio/mpeg)

Mastra/Custom

  • Full control over transcription and TTS services
  • Can integrate with any speech service (Google, Azure, AWS, etc.)
  • Flexible audio format support