build(boards): xpython板卡执行 npm run build:prod

This commit is contained in:
王立帮
2025-12-14 21:18:41 +08:00
parent 26bae5da89
commit 0ff5878d5f
416 changed files with 12404 additions and 48341 deletions

View File

@@ -60,7 +60,7 @@
"urllib"
],
"__file__": true,
"__size__": 9645,
"__size__": 11771,
"__name__": "mini_xunfei.py"
},
"mixgo_mini": {

View File

@@ -45,7 +45,6 @@ class ASR_WebSocket(Ws_Param):
"domain": "iat",
"language": "zh_cn",
"accent": "mandarin",
"vinfo": 1,
"vad_eos": 1000,
"nbest": 1,
"wbest": 1,
@@ -56,7 +55,10 @@ class ASR_WebSocket(Ws_Param):
self.ws.settimeout(1000)
def _frame(self, status, buf):
return {"status": status, "format": "audio/L16;rate=8000", "audio": str(b64encode(buf), 'utf-8'), "encoding": "raw"}
if status == 0:
return {"common": {"app_id": self.APPID}, "business": self.business, "data": {"status": status, "format": "audio/L16;rate=8000", "audio": str(b64encode(buf), 'utf-8'), "encoding": "raw"}}
else:
return {"data": {"status": status, "format": "audio/L16;rate=8000", "audio": str(b64encode(buf), 'utf-8'), "encoding": "raw"}}
def on_message(self, message):
result = ""
@@ -98,17 +100,16 @@ class ASR_WebSocket(Ws_Param):
if pace: print('=',end ="")
# 第一帧处理
if _state == 0:
d = {"common": {"app_id": self.APPID}, "business": self.business, "data": self._frame(_state, buf)}
d = self._frame(_state, buf)
_state = 1
# 中间帧处理
else:
d = {"data": self._frame(_state, buf)}
d = self._frame(_state, buf)
self.ws.send(json.dumps(d))
#print("------",len(buf), time.ticks_diff(time.ticks_ms(), _star))
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
raise OSError("Timeout pcm read error")
# 最后一帧处理
d = {"data": self._frame(2, b'\x00')}
d = self._frame(2, b'\x00')
self.ws.send(json.dumps(d))
onboard_bot.pcm_en(False) #PCM关闭
if pace: print(']')
@@ -122,6 +123,45 @@ class ASR_WebSocket(Ws_Param):
else:
print("Run error: %s" % (e))
#中英识别大模型
class IAT_WebSocket(ASR_WebSocket):
def __init__(self, APPID, APIKey, APISecret, url='ws://iat.xf-yun.com/v1', accent="mandarin", res_id=None):
super().__init__(APPID, APIKey, APISecret, url)
self.res_id = res_id
self.business = {
"domain": "slm",
"language": "zh_cn",
"accent": accent,
"result": {
"encoding": "utf8",
"compress": "raw",
"format": "plain"
}
}
def _frame(self, status, buf):
if status == 0:
return {"header": {"status": status, "app_id": self.APPID, "res_id": self.res_id}, "parameter": {"iat": self.business}, "payload": {"audio": { "audio": str(b64encode(buf), 'utf-8'), "sample_rate": 8000, "encoding": "raw"}}}
else:
return {"header": {"status": status, "app_id": self.APPID, "res_id": self.res_id}, "payload": {"audio": { "audio": str(b64encode(buf), 'utf-8'), "sample_rate": 8000, "encoding": "raw"}}}
def on_message(self, message):
result = ""
msg = json.loads(message)
code = msg['header']["code"]
if code != 0:
raise AttributeError("%s Code:%s" % (msg['header']["message"], code))
else:
if "payload" in msg:
text = msg["payload"]["result"]["text"]
data = json.loads(b64decode(text).decode())['ws']
for i in data:
for w in i["cw"]:
result += w["w"]
if msg["header"]["status"]== 2:
return result, False
return result, True
#大模型
class LLM_WebSocket(Ws_Param):
Model_url = {
@@ -204,6 +244,10 @@ class LLM_WebSocket(Ws_Param):
if "reasoning_content" in text and reas:
print("reasoning: ", text["reasoning_content"])
#回调
if "tool_calls" in text:
function = text['tool_calls'][0]['function']
if str(function['name']) in self._function[0] and function['arguments']:
self._function[0][function['name']](json.loads(function['arguments']))
if "function_call" in text:
if str(text['function_call']['name']) in self._function[0] and text['function_call']['arguments']:
self._function[0][text['function_call']['name']](json.loads(text['function_call']['arguments']))