|
@@ -332,8 +332,8 @@ class XunfeiAsr:
|
|
|
# 业务参数(business),更多个性化参数可在官网查看
|
|
|
self.BusinessArgs = {"domain": "iat", "language": "zh_cn", "accent": "mandarin", "vinfo":1,"vad_eos":2000}
|
|
|
|
|
|
- self.__event = threading.Event()
|
|
|
- self.__th = threading.Thread(target=self.__run())
|
|
|
+ # self.__event = threading.Event()
|
|
|
+ self.__th = threading.Thread(target=self.__run)
|
|
|
|
|
|
def create_url(self):
|
|
|
import hashlib
|
|
@@ -378,28 +378,28 @@ class XunfeiAsr:
|
|
|
import websocket
|
|
|
|
|
|
count = 0
|
|
|
- self.__event.clear()
|
|
|
+ # self.__event.clear()
|
|
|
websocket.enableTrace(True)
|
|
|
- while not self.__event.is_set():
|
|
|
- try:
|
|
|
- # 测试时候在此处正确填写相关信息即可运行
|
|
|
- time1 = datetime.now()
|
|
|
- ws_url = self.create_url()
|
|
|
- self.logger.info("xunfei.Asr.call_id:%s, ws_url:%s", self.__id, ws_url)
|
|
|
- self.ws = websocket.WebSocketApp(ws_url, on_message=self.on_message, on_error=self.on_error, on_close=self.on_close)
|
|
|
- self.logger.info("xunfei.Asr.call_id:%s, 111111111", self.__id)
|
|
|
- self.ws.on_open = self.on_open
|
|
|
- self.logger.info("xunfei.Asr.call_id:%s, 2222222222", self.__id)
|
|
|
- self.ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
|
|
|
- self.logger.info("xunfei.Asr.call_id:%s, 3333333333", self.__id)
|
|
|
- time_cost = (datetime.now() - time1)
|
|
|
- self.logger.info(f"xunfei.Asr.started. call_id:{self.__id}, timeCost:{time_cost}, count:{count}")
|
|
|
- self.__event.wait(timeout=1)
|
|
|
- self.logger.info(f"xunfei.Asr.started. call_id:{self.__id}, {count}")
|
|
|
- except Exception as e:
|
|
|
- traceback.print_exc()
|
|
|
- self.logger.info(f"[{self.__id}]ASR session start exception. {e}")
|
|
|
- count += 1
|
|
|
+ # while not self.__event.is_set():
|
|
|
+ try:
|
|
|
+ # 测试时候在此处正确填写相关信息即可运行
|
|
|
+ time1 = datetime.now()
|
|
|
+ ws_url = self.create_url()
|
|
|
+ self.logger.info("xunfei.Asr.call_id:%s, ws_url:%s", self.__id, ws_url)
|
|
|
+ self.ws = websocket.WebSocketApp(ws_url, on_message=self.on_message, on_error=self.on_error, on_close=self.on_close)
|
|
|
+ self.logger.info("xunfei.Asr.call_id:%s, 111111111", self.__id)
|
|
|
+ self.ws.on_open = self.on_open
|
|
|
+ self.logger.info("xunfei.Asr.call_id:%s, 2222222222", self.__id)
|
|
|
+ self.ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
|
|
|
+ self.logger.info("xunfei.Asr.call_id:%s, 3333333333", self.__id)
|
|
|
+ time_cost = (datetime.now() - time1)
|
|
|
+ self.logger.info(f"xunfei.Asr.started. call_id:{self.__id}, timeCost:{time_cost}, count:{count}")
|
|
|
+ # self.__event.wait(timeout=1)
|
|
|
+ # self.logger.info(f"xunfei.Asr.started. call_id:{self.__id}, {count}")
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ self.logger.info(f"[{self.__id}]ASR session start exception. {e}")
|
|
|
+ # count += 1
|
|
|
|
|
|
def start(self):
|
|
|
self.__th.start()
|
|
@@ -448,7 +448,7 @@ class XunfeiAsr:
|
|
|
# 收到websocket连接建立的处理
|
|
|
def on_open(self, ws):
|
|
|
self.logger.info("xunfei.Asr.open: call_id: %s", self.__id)
|
|
|
- self.__event.set()
|
|
|
+ # self.__event.set()
|
|
|
|
|
|
# 收到websocket消息的处理
|
|
|
def on_message(self, ws, message):
|
|
@@ -474,14 +474,14 @@ class XunfeiAsr:
|
|
|
# 收到websocket错误的处理
|
|
|
def on_error(self, ws, error):
|
|
|
self.logger.error("xunfei.Asr.recv::error, call_id:%s, msg:%s", self.__id, error)
|
|
|
- if not self.__event.is_set():
|
|
|
- self.__event.set()
|
|
|
+ # if not self.__event.is_set():
|
|
|
+ # self.__event.set()
|
|
|
|
|
|
# 收到websocket关闭的处理
|
|
|
def on_close(self, ws, a, b):
|
|
|
self.logger.error("xunfei.Asr.recv::close, call_id:%s", self.__id)
|
|
|
- if not self.__event.is_set():
|
|
|
- self.__event.set()
|
|
|
+ # if not self.__event.is_set():
|
|
|
+ # self.__event.set()
|
|
|
|
|
|
def convert_message(self, message):
|
|
|
final_result = {}
|