keyur2maru / vad

VAD is a cross-platform Dart binding for the VAD JavaScript library. This package provides access to a Voice Activity Detection (VAD) system, allowing Flutter applications to start and stop VAD-based listening and handle various VAD events.
https://vad.ganit.guru/
MIT License
0 stars 1 forks source link

[QUESTION] Different pause durations #2

Open iak-a-dev opened 1 week ago

iak-a-dev commented 1 week ago

I need to understand if this package can be used for voice activity detection in my project, where I want to trigger different actions based on varying pause lengths. Is it possible to achieve this functionality with this package, and if so, how can I set up different actions for different pause durations?

keyur2maru commented 1 week ago

You can listen to onSpeechEnd and use audioData.length directly to calculate the speech duration

_vadHandler.onSpeechEnd.listen((audioData) {
  final duration = audioData.length / 16000; // Duration in seconds

  if (duration < 3) triggerShortSpeechAction();
  else if (duration < 6) triggerMediumSpeechAction();
  else triggerLongSpeechAction();
});

This calculates duration from audioData and triggers actions as defined by you.

iak-a-dev commented 1 week ago

@keyur2maru Your example involves determining the length of the received audio stream, and I need to determine the length of the pause.

My goal is to use the VAD to identify small pauses and based on them to cut the audio stream into pieces and thus start transcribing it before the speech is finished

keyur2maru commented 3 days ago

In this case, you might be able to tweak redemptionFrames in startListening; by default, it is set to 8 frames. With framesSize, set to 1536 samples, 1 frame = 1536 samples = 96ms For example, setting redemptionFrames to 1 frame will finalize the speech segment after a pause of 96ms.