fix(voice): fix silent STT failure — use AAC/M4A, store onError, guard NaN amplitude

Three bugs causing silent STT failure on Android:

1. AudioEncoder.opus produces an OGG container on Android but the file
   was named .webm — faster-whisper rejected it due to format mismatch.
   Changed to AudioEncoder.aacLc + .m4a (reliable on all Android versions).
   Updated voice_api.dart to send audio/mp4 MIME type accordingly.

2. onError callback was never stored, so errors in _startListening() and
   _handleSilence() were silently swallowed. Now stored as _onError and
   called before exitVoiceMode() on any failure.

3. Amplitude stream can emit NaN or ±Infinity on some Android devices
   during recorder initialisation. NaN < -40.0 is false, so silence was
   never detected. Now treated explicitly as silence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-06 17:39:21 -04:00
parent 03dc9108a3
commit d441dcf954
2 changed files with 29 additions and 14 deletions
+2 -2
View File
@@ -46,8 +46,8 @@ class VoiceApi {
final formData = FormData.fromMap({
'audio': MultipartFile.fromBytes(
audioBytes,
filename: 'audio.webm',
contentType: DioMediaType('audio', 'webm'),
filename: 'audio.m4a',
contentType: DioMediaType('audio', 'mp4'),
),
});
final response = await _dio.post(