()
| 26 | print("recognizer by buffer result=",text) |
| 27 | |
| 28 | def recognizer_stream_example(): |
| 29 | |
| 30 | rcg = FunasrApi( |
| 31 | uri="wss://www.funasr.com:10096/" |
| 32 | ) |
| 33 | #define call_back function for msg |
| 34 | def on_msg(msg): |
| 35 | print("stream msg=",msg) |
| 36 | stream=rcg.create_stream(msg_callback=on_msg) |
| 37 | |
| 38 | wav_path = "asr_example.wav" |
| 39 | |
| 40 | with open(wav_path, "rb") as f: |
| 41 | audio_bytes = f.read() |
| 42 | |
| 43 | # use FunasrApi's audio2wav to covert other audio to PCM if needed |
| 44 | #import os |
| 45 | #from funasr_tools import FunasrTools |
| 46 | #file_ext=os.path.splitext(wav_path)[-1].upper() |
| 47 | #if not file_ext =="PCM" and not file_ext =="WAV": |
| 48 | # audio_bytes=FunasrTools.audio2wav(audio_bytes) |
| 49 | |
| 50 | stride = int(60 * 10 / 10 / 1000 * 16000 * 2) |
| 51 | chunk_num = (len(audio_bytes) - 1) // stride + 1 |
| 52 | |
| 53 | for i in range(chunk_num): |
| 54 | beg = i * stride |
| 55 | data = audio_bytes[beg : beg + stride] |
| 56 | stream.feed_chunk(data) |
| 57 | final_result=stream.wait_for_end() |
| 58 | print("asr_example.wav stream_result=",final_result) |
| 59 | |
| 60 | |
| 61 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…