MCPcopy Create free account
hub / github.com/modelscope/FunASR / recognizer_stream_example

Function recognizer_stream_example

runtime/funasr_api/example.py:28–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 print("recognizer by buffer result=",text)
27
28def 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
61if __name__ == "__main__":

Callers 1

example.pyFile · 0.85

Calls 5

create_streamMethod · 0.95
FunasrApiClass · 0.90
wait_for_endMethod · 0.80
readMethod · 0.45
feed_chunkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…