startVoiceSession static method
Future<VoiceSessionHandle>
startVoiceSession({
- VoiceSessionConfig config = VoiceSessionConfig.defaultConfig,
Start a voice session with audio capture, VAD, and full voice pipeline.
This is the simplest way to integrate voice assistant functionality. The session handles audio capture, VAD, and processing internally.
Example:
final session = await RunAnywhere.startVoiceSession();
// Consume events
session.events.listen((event) {
if (event is VoiceSessionListening) {
audioMeter = event.audioLevel;
} else if (event is VoiceSessionTurnCompleted) {
userText = event.transcript;
assistantText = event.response;
}
});
// Later...
session.stop();
Matches Swift: RunAnywhere.startVoiceSession(config:)
Implementation
static Future<VoiceSessionHandle> startVoiceSession({
VoiceSessionConfig config = VoiceSessionConfig.defaultConfig,
}) async {
if (!_isInitialized) {
throw SDKError.notInitialized();
}
final logger = SDKLogger('RunAnywhere.VoiceSession');
// Create the session handle with all necessary callbacks
final session = VoiceSessionHandle(
config: config,
processAudioCallback: _processVoiceAgentAudio,
isVoiceAgentReadyCallback: () async => isVoiceAgentReady,
initializeVoiceAgentCallback: _initializeVoiceAgentWithLoadedModels,
);
logger.info('Voice session created with callbacks');
// Start the session (this will verify voice agent readiness)
try {
await session.start();
logger.info('Voice session started successfully');
} catch (e) {
logger.error('Failed to start voice session: $e');
rethrow;
}
return session;
}