|
@@ -175,6 +175,7 @@ class TestSt:
|
|
|
|
|
|
# 讯飞ASR实时转写
|
|
# 讯飞ASR实时转写
|
|
class XfAsr:
|
|
class XfAsr:
|
|
|
|
+
|
|
def __init__(self, tid, logger, message_receiver=None):
|
|
def __init__(self, tid, logger, message_receiver=None):
|
|
import hashlib
|
|
import hashlib
|
|
import hmac
|
|
import hmac
|
|
@@ -203,11 +204,13 @@ class XfAsr:
|
|
signa = hmac.new(apiKey, baseString, hashlib.sha1).digest()
|
|
signa = hmac.new(apiKey, baseString, hashlib.sha1).digest()
|
|
signa = base64.b64encode(signa)
|
|
signa = base64.b64encode(signa)
|
|
signa = str(signa, 'utf-8')
|
|
signa = str(signa, 'utf-8')
|
|
|
|
+
|
|
self.end_tag = "{\"end\": true}"
|
|
self.end_tag = "{\"end\": true}"
|
|
self.tid = tid
|
|
self.tid = tid
|
|
self.logger = logger
|
|
self.logger = logger
|
|
self.message_receiver = message_receiver
|
|
self.message_receiver = message_receiver
|
|
self.ws = create_connection(base_url + "?appid=" + app_id + "&ts=" + ts + "&signa=" + quote(signa))
|
|
self.ws = create_connection(base_url + "?appid=" + app_id + "&ts=" + ts + "&signa=" + quote(signa))
|
|
|
|
+ self.logger.info(f"xunfei.Asr: ws.connected:{self.ws.connected}")
|
|
self.trecv = threading.Thread(target=self.recv)
|
|
self.trecv = threading.Thread(target=self.recv)
|
|
|
|
|
|
def start(self):
|
|
def start(self):
|
|
@@ -241,6 +244,7 @@ class XfAsr:
|
|
|
|
|
|
def recv(self):
|
|
def recv(self):
|
|
try:
|
|
try:
|
|
|
|
+ self.logger.info(f"xunfei.Asr.recv: ws.connected:{self.ws.connected}")
|
|
while self.ws.connected:
|
|
while self.ws.connected:
|
|
result = str(self.ws.recv())
|
|
result = str(self.ws.recv())
|
|
if len(result) == 0:
|
|
if len(result) == 0:
|