回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

掌控板语音识别+简单的ai 简单

头像 dfrwh 2025.04.04 83 0

复制代码到mind+中的上传模式,切换语言为mpython。要用WiFi,可以实现以下简单AI

1.说“你好”(打招呼)

2.说“1+1等于几”

3.说“666”

4.说“时间”

5.说“钢琴”

 

####################################################################

deepseek仅为图片,不要当真!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

deepseek仅为图片,不要当真!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

deepseek仅为图片,不要当真!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

####################################################################

 

# MindPlus
# mpython
from mpython import *
import ubinascii
import urequests
import network
import ntptime
import machine
import audio
import music
import time
import json


mpyPostFileParamAddr = "http://119.23.66.134:8085/file_upload"
mpyPostFileParamPath = "1.wav"
mpyPostFileParamType = "audio/wav"

touch_threshold = {'P': 400, 'Y': 400, 'T': 400, 'H': 400, 'O': 400, 'N': 400}

# 自定义函数
def GangQin():
 global mac_address, dict, resp, ShiChang
 oled.DispChar((str("结果:") + str((resp["text"]))), 0, (1-1)*16, 1)
 touch_threshold = {'P': 500, 'Y': 500, 'T': 500, 'H': 500, 'O': 500, 'N': 500}
 while not ((button_a.value() == 0 or button_b.value() == 0)):
   if touchPad_P.read() < touch_threshold['P']:
     while not (touchPad_P.read() > touch_threshold['P']):
       music.pitch(131, 250)
   elif touchPad_Y.read() < touch_threshold['Y']:
     while not (touchPad_Y.read() > touch_threshold['Y']):
       music.pitch(147, 250)
   elif touchPad_T.read() < touch_threshold['T']:
     while not (touchPad_T.read() > touch_threshold['T']):
       music.pitch(165, 250)
   elif touchPad_H.read() < touch_threshold['H']:
     while not (touchPad_H.read() > touch_threshold['H']):
       music.pitch(196, 250)
   elif touchPad_O.read() < touch_threshold['O']:
     while not (touchPad_O.read() > touch_threshold['O']):
       music.pitch(196, 250)
   elif touchPad_N.read() < touch_threshold['N']:
     if touchPad_N.read() > touch_threshold['N']:
       music.pitch(220, 250)

# 事件回调函数
def on_button_b_down(_):
 time.sleep_ms(10)
 if button_b.value() == 1: return
 oled.fill(0)
 oled.DispChar("加载中...", 43, 14, 1)
 oled.Bitmap(51, 32, bytearray([0x0,0x38,0x0,0x7,0x39,0xc0,0x7,0x39,0xc0,0x7,0xbb,0xc0,0x7,0xff,0xc0,0x7b,0xff,0xbc,0x7d,0xff,0x7c,0x7f,0xc3,0xfc,0x1e,0x1,0xf0,0xc,0x0,0xe0,0xf8,0x0,0x7e,0xf8,0x0,0xfe,0xf8,0x0,0xfe,0x0,0x0,0x0,0x18,0x0,0x0,0x78,0x0,0x0,0x78,0x0,0x0,0x78,0x0,0x0,0x7,0x0,0x0,0x7,0x1,0xc0,0x7,0x39,0xc0,0x7,0x39,0xc0,0x0,0x38,0x0]), 23, 23, 1)
 oled.show()
 resp = {}
 mac_address = ubinascii.hexlify(machine.unique_id()).decode().upper()
 dict = {"appid": "1", "mediatype":"2", "deviceid":0}
 dict["deviceid"]=mac_address
 _response = urequests.post(mpyPostFileParamAddr, files={"file":(mpyPostFileParamPath,mpyPostFileParamType)}, params=dict)
 oled.fill(0)
 print(_response.text)
 try:
   resp = _response.json()
   if "text" in resp:
     oled.fill(0)
     oled.DispChar("识别成功", 40, 23, 1)
     oled.show()
     time.sleep(0.1)
     oled.fill(0)
     if ((resp["text"]) == (str("你好"))):
       oled.DispChar((str("结果:") + str((resp["text"]))), 0, (1-1)*16, 1)
       oled.DispChar("AI:你好!我是掌控板AI!", 0, (2-1)*16, 1)
     elif ((resp["text"]) == (str("1+1等于几"))):
       oled.DispChar((str("结果:") + str((resp["text"]))), 0, (1-1)*16, 1)
       oled.DispChar("AI: 2", 0, (2-1)*16, 1)
     elif ((resp["text"]) == (str("666"))):
       oled.DispChar((str("结果:") + str((resp["text"]))), 0, (1-1)*16, 1)
       oled.DispChar("AI:666", 0, (2-1)*16, 1)
     elif ((resp["text"]) == (str("时间"))):
       oled.DispChar((str("结果:") + str((resp["text"]))), 0, (1-1)*16, 1)
       oled.DispChar((str("AI:") + str((str(time.localtime()[0]) + str((str("年") + str((str(time.localtime()[1]) + str((str("月") + str((str(time.localtime()[2]) + str("日")))))))))))), 0, (2-1)*16, 1)
       oled.DispChar((str(time.localtime()[3]) + str((str("时") + str((str(time.localtime()[4]) + str((str("分") + str((str(time.localtime()[5]) + str("秒")))))))))), 0, (3-1)*16, 1)
     elif ((resp["text"]) == (str("钢琴"))):
       GangQin()
     elif ((resp["text"]) == (str(""))):
       oled.DispChar((str("结果:") + str((resp["text"]))), 0, (1-1)*16, 1)
     else:
       oled.DispChar((str("结果:") + str((resp["text"]))), 0, (1-1)*16, 1)
   else:
     oled.DispChar("服务器响应异常", 0, (1-1)*16, 1)
 except:
   oled.DispChar("识别失败", 0, (1-1)*16, 1)
 oled.show()
def on_button_a_down(_):
 time.sleep_ms(10)
 if button_a.value() == 1: return
 oled.fill(0)
 oled.DispChar("正在录音...", 36, 23, 1)
 oled.show()
 audio.recorder_init()
 while not (button_a.value() == 1):
   audio.record("1.wav", 4)
 audio.recorder_deinit()
 oled.fill(0)
 oled.DispChar("录音完成", 40, 15, 1)
 oled.DispChar("按下B键开始识别", 19, 29, 1)
 oled.show()


my_wifi = wifi()
button_b.irq(trigger=Pin.IRQ_FALLING, handler=on_button_b_down)
button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)
oled.Bitmap(14, 9, bytearray([0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x38,0x40,0x0,0x0,0x0,0x3f,0xf8,0xe0,0x40,0x0,0x0,0x7f,0xf8,0xf9,0xc0,0x0,0x1,0xff,0xfc,0xff,0xc0,0x0,0x1,0xff,0xfc,0x7f,0xc0,0x0,0x3,0xff,0xfe,0x7f,0xc0,0x0,0x3,0xff,0xff,0xff,0x80,0x0,0x7,0xff,0xff,0xff,0x0,0x0,0x7,0x1f,0xff,0xfc,0x0,0x0,0x7,0x3,0xff,0xfc,0x0,0x0,0x7,0x1,0xfd,0xfc,0x0,0x0,0x7,0x80,0xfd,0xfc,0x0,0x0,0x7,0x80,0xff,0xf8,0x0,0x0,0x7,0xc0,0x7f,0xf8,0x0,0x0,0x3,0xc0,0x3f,0xf0,0x0,0x0,0x3,0xe3,0x9f,0xf0,0x0,0x0,0x1,0xf3,0xcf,0xe0,0x0,0x0,0x1,0xf9,0xef,0xe0,0x0,0x0,0x0,0x7f,0xff,0xf0,0x0,0x0,0x0,0x3f,0xff,0xf0,0x0,0x0,0x0,0x1f,0xfc,0x0,0x0,0x0,0x0,0x3,0xf0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0]), 48, 35, 1)
oled.DispChar("deepseek", 52, 17, 1)
oled.DispChar("正在连接WiFi...", 26, 39, 1)
oled.show()
my_wifi.connectWiFi("你的WiFi名","你的WiFi密码")
while not (my_wifi.sta.isconnected()):
 pass
ntptime.settime(8, "edu.ntp.org.cn")
oled.fill(0)
oled.DispChar("按下A键开始录音", 19, 23, 1)
oled.show()
 

####################################################################

deepseek仅为图片,不要当真!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

deepseek仅为图片,不要当真!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

deepseek仅为图片,不要当真!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

####################################################################

评论

user-avatar