feat(stt): pass last assistant response as Whisper context to reduce mishearings

This commit is contained in:
2026-04-07 09:57:07 -04:00
parent d75d34ce8e
commit 36350d35b1
3 changed files with 18 additions and 6 deletions
+7 -3
View File
@@ -40,16 +40,20 @@ class VoiceApi {
}
/// POST WebM/Opus audio bytes and return the transcript string.
/// [context] is optional recent conversation text passed as initial_prompt
/// to Whisper, reducing mishearings of domain-specific words.
/// Returns empty string on empty or error response.
Future<String> transcribe(Uint8List audioBytes) async {
Future<String> transcribe(Uint8List audioBytes, {String? context}) async {
try {
final formData = FormData.fromMap({
final fields = <String, dynamic>{
'audio': MultipartFile.fromBytes(
audioBytes,
filename: 'audio.m4a',
contentType: DioMediaType('audio', 'mp4'),
),
});
if (context != null && context.isNotEmpty) 'context': context,
};
final formData = FormData.fromMap(fields);
final response = await _dio.post(
'/api/voice/transcribe',
data: formData,