chatWithAudio method
Send a multimodal chat message (text + audio) - Gemma 3n E4B only
Implementation
Stream<String> chatWithAudio(
String text,
Uint8List audioBytes, {
String? conversationId,
}) async* {
_assertInitialized();
final convId = conversationId ?? _currentConversationId;
if (convId == null) {
throw StateError('No conversation. Call createConversation() first.');
}
final request = ChatWithAudioRequest()
..conversationId = convId
..text = text
..audio = audioBytes;
// Add timeout to prevent infinite hanging
await for (final response in _client!.chatWithAudio(request).timeout(
_streamTimeout,
onTimeout: (sink) {
sink.addError(TimeoutException(
'Model response timed out after ${_streamTimeout.inMinutes} minutes',
));
sink.close();
},
)) {
if (response.hasError() && response.error.isNotEmpty) {
throw Exception('Chat error: ${response.error}');
}
if (response.hasText()) {
yield response.text;
}
}
}