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