步骤1 改进设计分析
1、第二轮改进主要是使用Mpythom编程,接入百度AI,使用百度的语音技术(语音识别、语音合成),大大改善语音识别的准确率;
2、用微型数字功放板 2*3W D类PAM8403功放模块 更换原来的SYN6288语音合成模块(I2C通信方式;音质好中多了;
3、使用大按键触发;虽然控制很方便,但缺少科技感;尝试触摸开关、光电传感模块,选择避障传感器模块做触发开关;
4、狗头前面那块LED灯盒,有点傻傻的,没有卡通味,所有在光源上做了改进,加了两个舵机与WS2812 LED 5050 RGB 智能全彩RGB灯环做狗的眼睛,很生动。
步骤2 硬件连接
原打算两片圆环分另接完P13、P14,编程上传后,两个圆环不能同时亮灯,不知道是不是mPython编程中的BUG,改用mind+编程,两灯可正常同时亮;纠结了很久,干脆把两圆环并联后接P14,问题解决,不再出现编程崩溃的现象。
步骤3 外型改进
1、主要是设计了两个可以转动的眼睛,更换原先的大灯盒。
2、顶盖板切割光电模块口与舵机口
步骤4 电脑编程
代码
from mpython import *
import network
my_wifi = wifi()
my_wifi.connectWiFi('GT-ndwz', 'ndwz-chqzhc')
import neopixel
my_YJ1 = neopixel.NeoPixel(Pin(Pin.P14), n=8, bpp=3, timing=1)
from servo import Servo
import audio
import urequests
import gc
def _E5_88_9D_E5_A7_8B_E5_8C_96():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
B = 1
my_YJ1.fill( (0, 0, 0) )
my_YJ1.write()
color = 'C.mp3'
R = 'R.mp3'
blue = 'Blue.mp3'
G = 'G.mp3'
white = 'W.mp3'
black = 'black.mp3'
audio1 = 'my.mp3'
audio2 = 'my2.wav'
audio3 = 'my3.wav'
servo_11.write_angle(90)
servo_16.write_angle(0)
servo_5.write_angle(23)
servo_6.write_angle(23)
oled.fill(0)
oled.DispChar('语音狗狗-小黑', 28, 16, 1)
oled.DispChar('将为您服务', 34, 30, 1)
oled.show()
import gc;gc.collect()
audio.player_init(i2c)
audio.set_volume(80)
baidu_params = {"API_Key":'FaRbRg7fKOZOwGnPUs04lOjs', "Secret_Key":'APosPUm7w6D4pccXEzBS5ajynb6eW7bE', "text":'我是狗狗小黑,我来了。', "filename":audio1}
_rsp = urequests.post("http://119.23.66.134:8085/baidu_tts", params=baidu_params)
with open(audio1, "w") as _f:
while True:
dat = _rsp.recv(1024)
if not dat:
break
_f.write(dat)
audio.play(audio1)
audio.player_deinit()
gc.collect()
import time
def _E5_8A_A8_E8_80_B3_E6_9C_B5():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
for count in range(2):
servo_11.write_angle(5)
servo_16.write_angle(85)
time.sleep(0.5)
servo_11.write_angle(85)
servo_16.write_angle(5)
time.sleep(0.5)
def _E7_9C_BC_E7_9D_9B():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
if '人' in (baidu_iat_result["result"][0]):
for count in range(2):
servo_5.write_angle(0)
servo_6.write_angle(0)
time.sleep(1)
servo_5.write_angle(45)
servo_6.write_angle(45)
time.sleep(1)
my_YJ1.fill( (0, 153, 0) )
my_YJ1.write()
def _E7_BA_A2_E7_81_AF():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
if '红' in (baidu_iat_result["result"][0]):
my_YJ1.fill( (255, 0, 0) )
my_YJ1.write()
_E5_8A_A8_E8_80_B3_E6_9C_B5()
baidu_params = {"API_Key":'FaRbRg7fKOZOwGnPUs04lOjs', "Secret_Key":'APosPUm7w6D4pccXEzBS5ajynb6eW7bE', "text":'主人,大红灯笼开了', "filename":R}
_rsp = urequests.post("http://119.23.66.134:8085/baidu_tts", params=baidu_params)
with open(R, "w") as _f:
while True:
dat = _rsp.recv(1024)
if not dat:
break
_f.write(dat)
audio.play(R)
audio.player_deinit()
gc.collect()
def _E7_BB_BF_E7_81_AF():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
if '绿' in (baidu_iat_result["result"][0]):
_E5_8A_A8_E8_80_B3_E6_9C_B5()
my_YJ1.fill( (0, 153, 0) )
my_YJ1.write()
baidu_params = {"API_Key":'FaRbRg7fKOZOwGnPUs04lOjs', "Secret_Key":'APosPUm7w6D4pccXEzBS5ajynb6eW7bE', "text":'我喜欢大自然的色彩', "filename":G}
_rsp = urequests.post("http://119.23.66.134:8085/baidu_tts", params=baidu_params)
with open(G, "w") as _f:
while True:
dat = _rsp.recv(1024)
if not dat:
break
_f.write(dat)
audio.play(G)
audio.player_deinit()
gc.collect()
def _E8_93_9D_E7_81_AF():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
if '蓝' in (baidu_iat_result["result"][0]):
_E5_8A_A8_E8_80_B3_E6_9C_B5()
my_YJ1.fill( (0, 0, 153) )
my_YJ1.write()
baidu_params = {"API_Key":'FaRbRg7fKOZOwGnPUs04lOjs', "Secret_Key":'APosPUm7w6D4pccXEzBS5ajynb6eW7bE', "text":'这是蓝色妖姬吗', "filename":blue}
_rsp = urequests.post("http://119.23.66.134:8085/baidu_tts", params=baidu_params)
with open(blue, "w") as _f:
while True:
dat = _rsp.recv(1024)
if not dat:
break
_f.write(dat)
audio.play(blue)
audio.player_deinit()
gc.collect()
def _E7_99_BD_E7_81_AF():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
if '白' in (baidu_iat_result["result"][0]):
_E5_8A_A8_E8_80_B3_E6_9C_B5()
my_YJ1.fill( (255, 255, 255) )
my_YJ1.write()
baidu_params = {"API_Key":'FaRbRg7fKOZOwGnPUs04lOjs', "Secret_Key":'APosPUm7w6D4pccXEzBS5ajynb6eW7bE', "text":'主人,可以开始工作了', "filename":white}
_rsp = urequests.post("http://119.23.66.134:8085/baidu_tts", params=baidu_params)
with open(white, "w") as _f:
while True:
dat = _rsp.recv(1024)
if not dat:
break
_f.write(dat)
audio.play(white)
audio.player_deinit()
gc.collect()
p3 = MPythonPin(3, PinMode.IN)
def _E5_85_B3_E7_81_AF():
global B, color, R, G, blue, white, black, audio1, audio2, audio3
if '关' in (baidu_iat_result["result"][0]):
_E5_8A_A8_E8_80_B3_E6_9C_B5()
my_YJ1.fill( (0, 0, 0) )
my_YJ1.write()
baidu_params = {"API_Key":'FaRbRg7fKOZOwGnPUs04lOjs', "Secret_Key":'APosPUm7w6D4pccXEzBS5ajynb6eW7bE', "text":'您是节约用电吗。再见', "filename":black}
_rsp = urequests.post("http://119.23.66.134:8085/baidu_tts", params=baidu_params)
with open(black, "w") as _f:
while True:
dat = _rsp.recv(1024)
if not dat:
break
_f.write(dat)
audio.play(black)
audio.player_deinit()
gc.collect()
servo_11 = Servo(11, min_us=500, max_us=2500, actuation_range=180)
servo_16 = Servo(16, min_us=500, max_us=2500, actuation_range=180)
servo_5 = Servo(5, min_us=500, max_us=2500, actuation_range=180)
servo_6 = Servo(6, min_us=500, max_us=2500, actuation_range=180)
_E5_88_9D_E5_A7_8B_E5_8C_96()
while True:
B = p3.read_digital()
time.sleep(0.2)
if B == 0:
oled.fill(0)
oled.DispChar('语音狗狗-小黑', 28, 0, 1)
oled.DispChar('正在录音,时长 2 秒 ...', 0, 16, 1)
oled.show()
rgb[0] = (int(255), int(0), int(0))
rgb.write()
time.sleep_ms(1)
audio.recorder_init(i2c)
audio.record(audio2, 2)
audio.recorder_deinit()
oled.fill(0)
oled.DispChar('语音狗狗-小黑', 28, 0, 1)
oled.DispChar('正在识别语音文字 ...', 0, 16, 1)
oled.show()
rgb[0] = (int(51), int(255), int(51))
rgb.write()
time.sleep_ms(1)
baidu_params = {"API_Key":'FaRbRg7fKOZOwGnPUs04lOjs', "Secret_Key":'APosPUm7w6D4pccXEzBS5ajynb6eW7bE'}
_rsp = urequests.post("http://119.23.66.134:8085/baidu_asr", files={"file":(audio2, "audio/wav")}, params=baidu_params)
try:
baidu_iat_result = _rsp.json()
if not "result" in baidu_iat_result:
baidu_iat_result["result"] = ["ERRNO " + str(baidu_iat_result["err_no"])]
except:
baidu_iat_result = {"err_msg":"","result":[""]}
oled.fill(0)
oled.DispChar('语音狗狗-小黑', 28, 0, 1)
oled.DispChar(str('识别内容:') + str((baidu_iat_result["result"][0])), 0, 32, 1)
oled.show()
rgb[0] = (0, 0, 0)
rgb.write()
time.sleep_ms(1)
import gc;gc.collect()
audio.player_init(i2c)
_E7_99_BD_E7_81_AF()
_E5_85_B3_E7_81_AF()
_E7_BA_A2_E7_81_AF()
_E8_93_9D_E7_81_AF()
_E7_BB_BF_E7_81_AF()
_E7_9C_BC_E7_9D_9B()
步骤5 视频
rzyzzxw2021.04.20
赞赞