Reduce vad-whisper-c-api example code. (#1891)
This commit is contained in:
@@ -96,12 +96,17 @@ int32_t main() {
|
|||||||
|
|
||||||
int32_t window_size = vadConfig.silero_vad.window_size;
|
int32_t window_size = vadConfig.silero_vad.window_size;
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
|
int is_eof = 0;
|
||||||
|
|
||||||
while (i + window_size < wave->num_samples) {
|
while (!is_eof) {
|
||||||
SherpaOnnxVoiceActivityDetectorAcceptWaveform(vad, wave->samples + i,
|
if (i + window_size < wave->num_samples) {
|
||||||
window_size);
|
SherpaOnnxVoiceActivityDetectorAcceptWaveform(vad, wave->samples + i,
|
||||||
i += window_size;
|
window_size);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SherpaOnnxVoiceActivityDetectorFlush(vad);
|
||||||
|
is_eof = 1;
|
||||||
|
}
|
||||||
while (!SherpaOnnxVoiceActivityDetectorEmpty(vad)) {
|
while (!SherpaOnnxVoiceActivityDetectorEmpty(vad)) {
|
||||||
const SherpaOnnxSpeechSegment *segment =
|
const SherpaOnnxSpeechSegment *segment =
|
||||||
SherpaOnnxVoiceActivityDetectorFront(vad);
|
SherpaOnnxVoiceActivityDetectorFront(vad);
|
||||||
@@ -129,36 +134,7 @@ int32_t main() {
|
|||||||
SherpaOnnxDestroySpeechSegment(segment);
|
SherpaOnnxDestroySpeechSegment(segment);
|
||||||
SherpaOnnxVoiceActivityDetectorPop(vad);
|
SherpaOnnxVoiceActivityDetectorPop(vad);
|
||||||
}
|
}
|
||||||
}
|
i += window_size;
|
||||||
|
|
||||||
SherpaOnnxVoiceActivityDetectorFlush(vad);
|
|
||||||
|
|
||||||
while (!SherpaOnnxVoiceActivityDetectorEmpty(vad)) {
|
|
||||||
const SherpaOnnxSpeechSegment *segment =
|
|
||||||
SherpaOnnxVoiceActivityDetectorFront(vad);
|
|
||||||
|
|
||||||
const SherpaOnnxOfflineStream *stream =
|
|
||||||
SherpaOnnxCreateOfflineStream(recognizer);
|
|
||||||
|
|
||||||
SherpaOnnxAcceptWaveformOffline(stream, wave->sample_rate, segment->samples,
|
|
||||||
segment->n);
|
|
||||||
|
|
||||||
SherpaOnnxDecodeOfflineStream(recognizer, stream);
|
|
||||||
|
|
||||||
const SherpaOnnxOfflineRecognizerResult *result =
|
|
||||||
SherpaOnnxGetOfflineStreamResult(stream);
|
|
||||||
|
|
||||||
float start = segment->start / 16000.0f;
|
|
||||||
float duration = segment->n / 16000.0f;
|
|
||||||
float stop = start + duration;
|
|
||||||
|
|
||||||
fprintf(stderr, "%.3f -- %.3f: %s\n", start, stop, result->text);
|
|
||||||
|
|
||||||
SherpaOnnxDestroyOfflineRecognizerResult(result);
|
|
||||||
SherpaOnnxDestroyOfflineStream(stream);
|
|
||||||
|
|
||||||
SherpaOnnxDestroySpeechSegment(segment);
|
|
||||||
SherpaOnnxVoiceActivityDetectorPop(vad);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SherpaOnnxDestroyOfflineRecognizer(recognizer);
|
SherpaOnnxDestroyOfflineRecognizer(recognizer);
|
||||||
|
|||||||
Reference in New Issue
Block a user