python asr recognizer lib
| 16 | |
| 17 | # class for recognizer in websocket |
| 18 | class 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 |
no outgoing calls
no test coverage detected
searching dependent graphs…