更新mini的讯飞报错问题及统一回调格式
This commit is contained in:
@@ -383,7 +383,7 @@ class BOT035(FrameBuffer):
|
|||||||
else:
|
else:
|
||||||
self._wreg(_BOT035_STA, (self._rreg(_BOT035_STA) & 0xF7) | (power & 0x01) << 3)
|
self._wreg(_BOT035_STA, (self._rreg(_BOT035_STA) & 0xF7) | (power & 0x01) << 3)
|
||||||
else:
|
else:
|
||||||
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
raise OSError("This feature is only supported on version 2.0 ~")
|
||||||
|
|
||||||
def pcm_any(self):
|
def pcm_any(self):
|
||||||
return bool(self._rreg(_BOT035_STA) & 0x80)
|
return bool(self._rreg(_BOT035_STA) & 0x80)
|
||||||
@@ -392,23 +392,20 @@ class BOT035(FrameBuffer):
|
|||||||
return self._rreg(_BOT035_PCM, ibuf)
|
return self._rreg(_BOT035_PCM, ibuf)
|
||||||
|
|
||||||
def pcm_record(self, path='mixly.wav', seconds=5, ibuf=1600, timeout=2000):
|
def pcm_record(self, path='mixly.wav', seconds=5, ibuf=1600, timeout=2000):
|
||||||
if self._version >= 3:
|
self.pcm_en(True)
|
||||||
self.pcm_en(True)
|
_star = time.ticks_ms()
|
||||||
_star = time.ticks_ms()
|
_size = int(ibuf * seconds * 10)
|
||||||
_size = int(ibuf * seconds * 10)
|
_header = b'RIFF' + (36 + _size).to_bytes(4, 'little') + b'WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00' + (ibuf * 5).to_bytes(4, 'little') + (ibuf * 10).to_bytes(4, 'little') + b'\x02\x00\x10\x00data' + _size.to_bytes(4, 'little')
|
||||||
_header = b'RIFF' + (36 + _size).to_bytes(4, 'little') + b'WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00' + (ibuf * 5).to_bytes(4, 'little') + (ibuf * 10).to_bytes(4, 'little') + b'\x02\x00\x10\x00data' + _size.to_bytes(4, 'little')
|
with open(path, 'wb') as f:
|
||||||
with open(path, 'wb') as f:
|
f.write(_header)
|
||||||
f.write(_header)
|
while _size > 0:
|
||||||
while _size > 0:
|
if self.pcm_any():
|
||||||
if self.pcm_any():
|
f.write(self.pcm_read(ibuf))
|
||||||
f.write(self.pcm_read(ibuf))
|
_size -= ibuf
|
||||||
_size -= ibuf
|
_star = time.ticks_ms()
|
||||||
_star = time.ticks_ms()
|
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
|
||||||
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
|
raise OSError("Timeout write error")
|
||||||
raise OSError("Timeout write error")
|
self.pcm_en(False)
|
||||||
self.pcm_en(False)
|
|
||||||
else:
|
|
||||||
print("Warning: Please upgrade the coprocessor firmware to use this feature")
|
|
||||||
|
|
||||||
"""Graph module"""
|
"""Graph module"""
|
||||||
HEART =b'\x00\x0c\x1e?~\xfc~?\x1e\x0c\x00\x00'
|
HEART =b'\x00\x0c\x1e?~\xfc~?\x1e\x0c\x00\x00'
|
||||||
|
|||||||
@@ -117,7 +117,10 @@ class ASR_WebSocket(Ws_Param):
|
|||||||
return msg
|
return msg
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
onboard_bot.pcm_en(False) #PCM关闭
|
onboard_bot.pcm_en(False) #PCM关闭
|
||||||
print("Run error: %s" % (e))
|
if "403 Forbidden" in str(e):
|
||||||
|
raise OSError("Access denied, Please try updating clock time")
|
||||||
|
else:
|
||||||
|
print("Run error: %s" % (e))
|
||||||
|
|
||||||
#大模型
|
#大模型
|
||||||
class LLM_WebSocket(Ws_Param):
|
class LLM_WebSocket(Ws_Param):
|
||||||
@@ -166,10 +169,10 @@ class LLM_WebSocket(Ws_Param):
|
|||||||
d["payload"]["functions"] = {"text": self._function[1]}
|
d["payload"]["functions"] = {"text": self._function[1]}
|
||||||
self.ws.send(json.dumps(d))
|
self.ws.send(json.dumps(d))
|
||||||
|
|
||||||
def function_call(self, callback, name, description, *args):
|
def function_call(self, callback, name, description, params):
|
||||||
"""功能回调名称, 描述, (参数名, 类型, 描述) """
|
"""功能回调名称, 描述, ((参数名, 类型, 描述), ...)"""
|
||||||
properties = {"type": "object", "properties":{}, "required":[]}
|
properties = {"type": "object", "properties":{}, "required":[]}
|
||||||
for arg in args:
|
for arg in params:
|
||||||
if len(arg) >= 3:
|
if len(arg) >= 3:
|
||||||
properties["properties"][arg[0]] = {"type": arg[1], "description": arg[2]}
|
properties["properties"][arg[0]] = {"type": arg[1], "description": arg[2]}
|
||||||
if arg[0] not in properties["required"]:
|
if arg[0] not in properties["required"]:
|
||||||
@@ -231,4 +234,7 @@ class LLM_WebSocket(Ws_Param):
|
|||||||
self.ws.close()
|
self.ws.close()
|
||||||
return msg
|
return msg
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Run error: %s" % (e))
|
if "403 Forbidden" in str(e):
|
||||||
|
raise OSError("Access denied, Please try updating clock time")
|
||||||
|
else:
|
||||||
|
print("Run error: %s" % (e))
|
||||||
|
|||||||
Reference in New Issue
Block a user