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

This commit is contained in:
王立帮
2025-10-24 22:43:34 +08:00
parent 17ad6d31a0
commit 00d1c46627
176 changed files with 31780 additions and 17439 deletions

View File

@@ -0,0 +1,100 @@
{
"ble_central": {
"__require__": [
"time",
"gc",
"bluetooth",
"micropython",
"ubinascii",
"ble_advertising"
],
"__file__": true,
"__size__": 7378,
"__name__": "ble_central.py"
},
"mini_bot": {
"__require__": [
"time",
"math",
"esp",
"micropython",
"framebuf"
],
"__file__": true,
"__size__": 15556,
"__name__": "mini_bot.py"
},
"mini_go": {
"__require__": [
"time",
"gc",
"math",
"tm1931",
"machine"
],
"__file__": true,
"__size__": 8481,
"__name__": "mini_go.py"
},
"mini_gx": {
"__require__": [
"gc",
"machine",
"rc522",
"ci130x"
],
"__file__": true,
"__size__": 736,
"__name__": "mini_gx.py"
},
"mini_xunfei": {
"__require__": [
"time",
"hmac",
"json",
"hashlib",
"rtctime",
"websocket",
"mixgo_mini",
"base64",
"urllib"
],
"__file__": true,
"__size__": 9645,
"__name__": "mini_xunfei.py"
},
"mixgo_mini": {
"__require__": [
"time",
"gc",
"esp32",
"machine",
"musicx",
"ws2812x",
"sc7a20",
"ap3216c",
"mini_bot"
],
"__file__": true,
"__size__": 4920,
"__name__": "mixgo_mini.py"
},
"musicx": {
"__require__": [
"_thread",
"time"
],
"__file__": true,
"__size__": 3926,
"__name__": "musicx.py"
},
"ws2812x": {
"__require__": [
"time",
"machine"
],
"__file__": true,
"__size__": 1979,
"__name__": "ws2812x.py"
}
}

View File

@@ -383,7 +383,7 @@ class BOT035(FrameBuffer):
else:
self._wreg(_BOT035_STA, (self._rreg(_BOT035_STA) & 0xF7) | (power & 0x01) << 3)
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):
return bool(self._rreg(_BOT035_STA) & 0x80)
@@ -392,23 +392,20 @@ class BOT035(FrameBuffer):
return self._rreg(_BOT035_PCM, ibuf)
def pcm_record(self, path='mixly.wav', seconds=5, ibuf=1600, timeout=2000):
if self._version >= 3:
self.pcm_en(True)
_star = time.ticks_ms()
_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')
with open(path, 'wb') as f:
f.write(_header)
while _size > 0:
if self.pcm_any():
f.write(self.pcm_read(ibuf))
_size -= ibuf
_star = time.ticks_ms()
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
raise OSError("Timeout write error")
self.pcm_en(False)
else:
print("Warning: Please upgrade the coprocessor firmware to use this feature")
self.pcm_en(True)
_star = time.ticks_ms()
_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')
with open(path, 'wb') as f:
f.write(_header)
while _size > 0:
if self.pcm_any():
f.write(self.pcm_read(ibuf))
_size -= ibuf
_star = time.ticks_ms()
if time.ticks_diff(time.ticks_ms(), _star) > timeout:
raise OSError("Timeout write error")
self.pcm_en(False)
"""Graph module"""
HEART =b'\x00\x0c\x1e?~\xfc~?\x1e\x0c\x00\x00'

View File

@@ -0,0 +1,240 @@
"""
MINI_XUNFEI
Micropython library for the MINI_XUNFEI(ASR, LLM)
=======================================================
@dahanzimin From the Mixly Team
"""
import time
import hmac
import json
import hashlib
import rtctime
import websocket
from mixgo_mini import onboard_bot
from base64 import b64decode, b64encode
from urllib import urlencode, urlparse
class Ws_Param:
def __init__(self, APPID, APIKey, APISecret, Spark_url):
self.APPID = APPID
self.APIKey = APIKey
self.APISecret = APISecret
self.url = Spark_url
self.urlparse = urlparse(Spark_url)
def create_url(self):
date = rtctime.rfc1123_time()
signature_origin = "host: " + self.urlparse.netloc + "\n"
signature_origin += "date: " + date + "\n"
signature_origin += "GET " + self.urlparse.path + " HTTP/1.1"
signature_sha = hmac.new(self.APISecret.encode('utf-8'), signature_origin.encode('utf-8'), digestmod=hashlib.sha256).digest()
signature_base64 = b64encode(signature_sha).decode('utf-8')
authorization_origin = ('api_key="{}", algorithm="hmac-sha256", headers="host date request-line", signature="{}"'.format(self.APIKey, signature_base64))
authorization = b64encode(authorization_origin.encode('utf-8')).decode('utf-8')
headers = {"authorization": authorization, "date": date, "host": self.urlparse.netloc}
return self.url + '?' + urlencode(headers)
#语音听写
class ASR_WebSocket(Ws_Param):
def __init__(self, APPID, APIKey, APISecret, url='ws://iat-api.xfyun.cn/v2/iat'):
super().__init__(APPID, APIKey, APISecret, url)
self.ws = None
self.business = {
"domain": "iat",
"language": "zh_cn",
"accent": "mandarin",
"vinfo": 1,
"vad_eos": 1000,
"nbest": 1,
"wbest": 1,
}
def connect(self):
self.ws = websocket.connect(self.create_url())
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"}
def on_message(self, message):
result = ""
msg = json.loads(message)
code = msg["code"]
if code != 0:
raise AttributeError("%s Code:%s" % (msg["message"], code))
else:
data = msg["data"]["result"]["ws"]
for i in data:
for w in i["cw"]:
result += w["w"]
if msg["data"]["status"]== 2:
return result, False
return result, True
def receive_messages(self):
msg = ""
while True:
t = self.on_message(self.ws.recv())
msg += t[0]
if not t[1]:
break
return msg
def run(self, seconds=3, pace=True, ibuf=1600, timeout=2000):
try:
_state = 0
self.connect()
_star = time.ticks_ms()
_size = int(ibuf * seconds * 10) #100ms/次
onboard_bot.pcm_en(True) #PCM开启
if pace: print('[',end ="")
while _size > 0:
if onboard_bot.pcm_any():
_size -= ibuf
_star = time.ticks_ms()
buf = onboard_bot.pcm_read(ibuf)
if pace: print('=',end ="")
# 第一帧处理
if _state == 0:
d = {"common": {"app_id": self.APPID}, "business": self.business, "data": self._frame(_state, buf)}
_state = 1
# 中间帧处理
else:
d = {"data": 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')}
self.ws.send(json.dumps(d))
onboard_bot.pcm_en(False) #PCM关闭
if pace: print(']')
msg = self.receive_messages()
self.ws.close()
return msg
except Exception as e:
onboard_bot.pcm_en(False) #PCM关闭
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):
Model_url = {
"Spark Ultra-32K": ("ws://spark-api.xf-yun.com/v4.0/chat", "4.0Ultra"),
"Spark Max-32K": ("ws://spark-api.xf-yun.com/chat/max-32k", "max-32k"),
"Spark Max": ("ws://spark-api.xf-yun.com/v3.5/chat", "generalv3.5"),
"Spark Pro-128K": (" ws://spark-api.xf-yun.com/chat/pro-128k", "pro-128k"),
"Spark Pro": ("ws://spark-api.xf-yun.com/v3.1/chat", "generalv3"),
"Spark Lite": ("ws://spark-api.xf-yun.com/v1.1/chat", "lite"),
"Spark kjwx": ("ws://spark-openapi-n.cn-huabei-1.xf-yun.com/v1.1/chat_kjwx", "kjwx"),
"Spark X1-32K": ("ws://spark-api.xf-yun.com/v1/x1", "x1"),
"Spark Customize": ("ws://sparkcube-api.xf-yun.com/v1/customize", "max"),
}
def __init__(self, APPID, APIKey, APISecret, model='Spark Ultra-32K', system="你是知识渊博的助理,习惯简短表达", answers=50):
self.ws = None
self.answers = answers
self._url = self.Model_url[model] if model in self.Model_url else model
super().__init__(APPID, APIKey, APISecret, self._url[0])
self._function = [{}, []] #[回调函数, 功能描述]
self._messages = [{"role": "system", "content": system}]
def connect(self):
self.ws = websocket.connect(self.create_url())
self.ws.settimeout(1000)
def _params(self):
d = {
"header": {"app_id": self.APPID},
"parameter": {
"chat": {
"domain": self._url[1],
"random_threshold": 0.5,
"max_tokens": 2048,
"auditing": "default"
}
},
"payload": {
"message": {
"text": self._messages
}
}
}
if self._function[1]:
d["payload"]["functions"] = {"text": self._function[1]}
self.ws.send(json.dumps(d))
def function_call(self, callback, name, description, params):
"""功能回调名称, 描述, ((参数名, 类型, 描述), ...)"""
properties = {"type": "object", "properties":{}, "required":[]}
for arg in params:
if len(arg) >= 3:
properties["properties"][arg[0]] = {"type": arg[1], "description": arg[2]}
if arg[0] not in properties["required"]:
properties["required"].append(arg[0])
else:
raise AttributeError('Invalid Input , format is (name, type, description)')
self._function[0][name] = callback
self._function[1].append({"name": name, "description": description, "parameters": properties})
def empty_history(self):
self._messages = []
def add_history(self, role, content):
self._messages.append({
"role": role,
"content": content
})
def on_message(self, message, reas):
result = ""
msg = json.loads(message)
code = msg['header']['code']
if code != 0:
raise AttributeError("%s Code:%s" % (msg["header"]["message"], code))
else:
choices = msg["payload"]["choices"]
text = choices["text"][0]
#推理
if "reasoning_content" in text and reas:
print("reasoning: ", text["reasoning_content"])
#回调
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']))
#答复
if "content" in text:
result += text["content"]
if choices["status"] == 2:
return result, False
return result, True
def receive_messages(self, reas):
msg = ""
while True:
t = self.on_message(self.ws.recv(), reas)
msg += t[0]
if not t[1]:
break
return msg
def run(self, question, reas=True):
try:
self.connect()
self.add_history("user", question)
self._params()
while self.answers < len(self._messages):
del self._messages[0]
msg = self.receive_messages(reas)
self.ws.close()
return msg
except Exception as e:
if "403 Forbidden" in str(e):
raise OSError("Access denied, Please try updating clock time")
else:
print("Run error: %s" % (e))

View File

@@ -5,6 +5,7 @@ Micropython library for the Music buzzer(Coprocessor I2C communication)
=======================================================
@dahanzimin From the Mixly Team
"""
import _thread
from time import sleep_ms
normal_tone = {
@@ -24,6 +25,8 @@ class MIDI():
def __init__(self, bus, volume=100):
self.reset()
self._bus = bus
self._play = False
self._over = True
self._volume = volume // 5
def set_volume(self, volume):
@@ -86,12 +89,16 @@ class MIDI():
tone = tone[:pos]
def play(self, tune, duration=None):
self._play = True
self._over = False
if duration is None:
self.set_default(tune[0])
else:
self.set_duration(duration)
for tone in tune:
tone = tone.upper()
if not self._play:
break
if tone[0] not in Letter:
continue
midi = self.midi(tone)
@@ -100,6 +107,15 @@ class MIDI():
self._bus.buzzer(0)
sleep_ms(1)
sleep_ms(10)
self._over = True
def play_thread(self, tune, duration=None):
self._play = False
while not self._over:
pass
if not self._play:
_thread.start_new_thread(self.play, (tune, duration))
sleep_ms(50)
def pitch(self, freq):
self._bus.buzzer(self._volume, int(freq))
@@ -112,6 +128,7 @@ class MIDI():
def stop(self):
self._bus.buzzer(0)
self._play = False
sleep_ms(10)
BA_DING=('b5:1','e6:3')