Add Flush to VAD so that the last segment can be detected. (#1099)

This commit is contained in:
Fangjun Kuang
2024-07-09 16:15:56 +08:00
committed by GitHub
parent 3e4307e2fb
commit c2cc9dec58
35 changed files with 237 additions and 29 deletions

View File

@@ -93,6 +93,28 @@ void main(List<String> arguments) async {
}
}
vad.flush();
while (!vad.isEmpty()) {
final stream = recognizer.createStream();
final segment = vad.front();
stream.acceptWaveform(
samples: segment.samples, sampleRate: waveData.sampleRate);
recognizer.decode(stream);
final result = recognizer.getResult(stream);
final startTime = segment.start * 1.0 / waveData.sampleRate;
final duration = segment.samples.length * 1.0 / waveData.sampleRate;
final stopTime = startTime + duration;
if (result.text != '') {
print(
'${startTime.toStringAsPrecision(4)} -- ${stopTime.toStringAsPrecision(4)}: ${result.text}');
}
stream.free();
vad.pop();
}
vad.free();
recognizer.free();
}