Add Flush to VAD so that the last segment can be detected. (#1099)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ environment:
|
||||
|
||||
# Add regular dependencies here.
|
||||
dependencies:
|
||||
sherpa_onnx: ^1.10.11
|
||||
sherpa_onnx: ^1.10.12
|
||||
path: ^1.9.0
|
||||
args: ^2.5.0
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ environment:
|
||||
|
||||
# Add regular dependencies here.
|
||||
dependencies:
|
||||
sherpa_onnx: ^1.10.11
|
||||
sherpa_onnx: ^1.10.12
|
||||
path: ^1.9.0
|
||||
args: ^2.5.0
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ environment:
|
||||
|
||||
# Add regular dependencies here.
|
||||
dependencies:
|
||||
sherpa_onnx: ^1.10.11
|
||||
sherpa_onnx: ^1.10.12
|
||||
path: ^1.9.0
|
||||
args: ^2.5.0
|
||||
|
||||
|
||||
@@ -65,6 +65,12 @@ void main(List<String> arguments) async {
|
||||
}
|
||||
}
|
||||
|
||||
vad.flush();
|
||||
while (!vad.isEmpty()) {
|
||||
allSamples.add(vad.front().samples);
|
||||
vad.pop();
|
||||
}
|
||||
|
||||
vad.free();
|
||||
|
||||
final s = Float32List.fromList(allSamples.expand((x) => x).toList());
|
||||
|
||||
@@ -9,7 +9,7 @@ environment:
|
||||
sdk: ^3.4.0
|
||||
|
||||
dependencies:
|
||||
sherpa_onnx: ^1.10.11
|
||||
sherpa_onnx: ^1.10.12
|
||||
path: ^1.9.0
|
||||
args: ^2.5.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user