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