React Native
For real-time voice on iOS and Android, the TypeScript SDK (sarvam-conv-ai-sdk/react-native) uses the same ConversationAgent client as Web. React Native has no built-in browser audio API, so you must pass your own AsyncAudioInterface for microphone capture and playback.
Install
Start a voice session
Set platform: "react-native" and pass an audioInterface that implements AsyncAudioInterface (see Custom audio interface below).
InteractionConfig
Callbacks
Pass any of these to ConversationAgent to react to what happens during the call:
Custom audio interface
Implement AsyncAudioInterface and feed 16-bit PCM mono at the configured sample rate:
Recommended libraries:
- react-native-audio-api — low-level audio API
- expo-av — Expo projects
- react-native-live-audio-stream — real-time streaming
Session methods
Call await agent.stop() on unmount so the WebSocket and audio interface are cleaned up. Reconnection is not supported: each WebSocket URL is single-use. If the connection drops, call stop() and create a new ConversationAgent.
Stop or recreate the agent when the app backgrounds. React Native suspends WebSockets in the background, and you cannot reuse the old URL:
Troubleshooting
Microphone permission denied. Request the microphone before starting a voice session.
Expo:
Bare React Native, with react-native-permissions:
No audio output. Check device volume and the iOS silent switch. Confirm output() writes to the speaker at output_sample_rate.
Connection timeout. Check connectivity, API key, org_id / workspace_id / app_id, and that the agent has a committed version.
Never embed your API key in the app binary. Point baseUrl at a backend you control, leave apiKey empty, and pass your app auth in customHeaders (cookies are not available in React Native):