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

Class FunasrStream

runtime/funasr_api/funasr_stream.py:18–69  ·  view source on GitHub ↗

python asr recognizer lib

Source from the content-addressed store, hash-verified

16
17# class for recognizer in websocket
18class FunasrStream:
19 """
20 python asr recognizer lib
21
22 """
23
24 def __init__(
25 self,
26 funasr_core
27
28 ):
29 """
30 uri: ws or wss server uri
31 msg_callback: for message received
32 timeout: timeout for get result
33 """
34 try:
35 self.funasr_core=funasr_core
36
37 except Exception as e:
38 print("FunasrStream init Exception:", e)
39 traceback.print_exc()
40
41
42 # feed data to asr engine in stream way
43 def feed_chunk(self, chunk):
44 try:
45 if self.funasr_core is None:
46 print("error in stream, funasr_core is None")
47 exit(0)
48 self.funasr_core.feed_chunk(chunk)
49 return
50 except:
51 print("feed chunk error")
52 return
53
54
55
56 # return all result for this stream
57 def wait_for_end(self):
58 try:
59
60 message = json.dumps({"is_speaking": False})
61 self.funasr_core.websocket.send(message)
62 self.funasr_core.wait_for_result()
63 self.funasr_core.close()
64
65 # return the msg
66 return self.funasr_core.rec_text
67 except Exception as e:
68 print("error get_final_result ",e)
69 return ""
70
71
72

Callers 1

create_streamMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…