Committed by
GitHub
Reduce vad-sense-voice example code. (#1510)
正在显示
1 个修改的文件
包含
8 行增加
和
32 行删除
| @@ -99,11 +99,16 @@ int32_t main() { | @@ -99,11 +99,16 @@ int32_t main() { | ||
| 99 | 99 | ||
| 100 | int32_t window_size = vadConfig.silero_vad.window_size; | 100 | int32_t window_size = vadConfig.silero_vad.window_size; |
| 101 | int32_t i = 0; | 101 | int32_t i = 0; |
| 102 | + int is_eof = 0; | ||
| 102 | 103 | ||
| 103 | - while (i + window_size < wave->num_samples) { | 104 | + while (!is_eof) { |
| 105 | + if (i + window_size < wave->num_samples) { | ||
| 104 | SherpaOnnxVoiceActivityDetectorAcceptWaveform(vad, wave->samples + i, | 106 | SherpaOnnxVoiceActivityDetectorAcceptWaveform(vad, wave->samples + i, |
| 105 | window_size); | 107 | window_size); |
| 106 | - i += window_size; | 108 | + } else { |
| 109 | + SherpaOnnxVoiceActivityDetectorFlush(vad); | ||
| 110 | + is_eof = 1; | ||
| 111 | + } | ||
| 107 | 112 | ||
| 108 | while (!SherpaOnnxVoiceActivityDetectorEmpty(vad)) { | 113 | while (!SherpaOnnxVoiceActivityDetectorEmpty(vad)) { |
| 109 | const SherpaOnnxSpeechSegment *segment = | 114 | const SherpaOnnxSpeechSegment *segment = |
| @@ -132,36 +137,7 @@ int32_t main() { | @@ -132,36 +137,7 @@ int32_t main() { | ||
| 132 | SherpaOnnxDestroySpeechSegment(segment); | 137 | SherpaOnnxDestroySpeechSegment(segment); |
| 133 | SherpaOnnxVoiceActivityDetectorPop(vad); | 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 | SherpaOnnxDestroyOfflineRecognizer(recognizer); | 143 | SherpaOnnxDestroyOfflineRecognizer(recognizer); |
-
请 注册 或 登录 后发表评论