I'm developing a Flutter application that needs to capture voice input and automatically detect when the user has finished speaking, then send the recorded audio to an API for processing.
Here's what I'm trying to achieve:
However, this requires manual stopping of the recording. I need a way to automatically detect when the user has finished speaking.
Yes, you can use the finalResult
property from the SpeechRecognitionResult
class to determine if the result is considered final by the platform. This boolean flag indicates whether the result is the ultimate or final output.
_speech.listen(
onResult: (result) {
if (result.finalResult) {
_handleSpeechEnd(result.recognizedWords);
}
},
);
Here is link
UPD:
I understand the issue. To address it, you’ll need to implement your own VAD class that tracks the audio levels (decibels) during recording.
Here’s how you can approach it with flutter_sound:
void _startSilenceDetection() {
_recorder.onProgress.listen((event) {
// Calculate the amplitude from the recording data
double amplitude = _calculateAmplitudeDecibels(event);
// Use the VAD class to check if the amplitude indicates silence
if (_vad.isSilent(amplitude)) {
// If silence persists for 1-2 seconds (configurable), take the necessary action
}
});
}