@@ -98,12 +98,16 @@ int32_t main() {
9898
9999 int32_t window_size = vadConfig .silero_vad .window_size ;
100100 int32_t i = 0 ;
101-
102- while (i + window_size < wave -> num_samples ) {
103- SherpaOnnxVoiceActivityDetectorAcceptWaveform (vad , wave -> samples + i ,
104- window_size );
105- i += window_size ;
106-
101+ int is_eof = 0 ;
102+
103+ while (!is_eof ) {
104+ if (i + window_size < wave -> num_samples ) {
105+ SherpaOnnxVoiceActivityDetectorAcceptWaveform (vad , wave -> samples + i ,
106+ window_size );
107+ } else {
108+ SherpaOnnxVoiceActivityDetectorFlush (vad );
109+ is_eof = 1 ;
110+ }
107111 while (!SherpaOnnxVoiceActivityDetectorEmpty (vad )) {
108112 const SherpaOnnxSpeechSegment * segment =
109113 SherpaOnnxVoiceActivityDetectorFront (vad );
@@ -131,36 +135,7 @@ int32_t main() {
131135 SherpaOnnxDestroySpeechSegment (segment );
132136 SherpaOnnxVoiceActivityDetectorPop (vad );
133137 }
134- }
135-
136- SherpaOnnxVoiceActivityDetectorFlush (vad );
137-
138- while (!SherpaOnnxVoiceActivityDetectorEmpty (vad )) {
139- const SherpaOnnxSpeechSegment * segment =
140- SherpaOnnxVoiceActivityDetectorFront (vad );
141-
142- const SherpaOnnxOfflineStream * stream =
143- SherpaOnnxCreateOfflineStream (recognizer );
144-
145- SherpaOnnxAcceptWaveformOffline (stream , wave -> sample_rate , segment -> samples ,
146- segment -> n );
147-
148- SherpaOnnxDecodeOfflineStream (recognizer , stream );
149-
150- const SherpaOnnxOfflineRecognizerResult * result =
151- SherpaOnnxGetOfflineStreamResult (stream );
152-
153- float start = segment -> start / 16000.0f ;
154- float duration = segment -> n / 16000.0f ;
155- float stop = start + duration ;
156-
157- fprintf (stderr , "%.3f -- %.3f: %s\n" , start , stop , result -> text );
158-
159- SherpaOnnxDestroyOfflineRecognizerResult (result );
160- SherpaOnnxDestroyOfflineStream (stream );
161-
162- SherpaOnnxDestroySpeechSegment (segment );
163- SherpaOnnxVoiceActivityDetectorPop (vad );
138+ i += window_size ;
164139 }
165140
166141 SherpaOnnxDestroyOfflineRecognizer (recognizer );
0 commit comments