| | |
| | | import soundfile |
| | | import os |
| | | |
| | | speech, sample_rate = soundfile.read(os.path.expanduser('~')+ |
| | | "/.cache/modelscope/hub/damo/"+ |
| | | "speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online/"+ |
| | | "example/asr_example.wav") |
| | | wav_file = os.path.join(model.model_path, "example/asr_example.wav") |
| | | speech, sample_rate = soundfile.read(wav_file) |
| | | |
| | | chunk_stride = chunk_size[1] * 960 # 600ms、480ms |
| | | |
| | | cache = {} |
| | | |
| | | for i in range(int(len((speech)-1)/chunk_stride+1)): |
| | | total_chunk_num = int(len((speech)-1)/chunk_stride+1) |
| | | for i in range(total_chunk_num): |
| | | speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride] |
| | | is_final = i == int(len((speech)-1)/chunk_stride+1) |
| | | is_final = i == total_chunk_num - 1 |
| | | res = model(input=speech_chunk, |
| | | cache=cache, |
| | | is_final=is_final, |