ASRPRO-CORE
开发板。本篇笔记分享下使用ASRPRO开发板,语音控制emo表情机器人
。1、ASRPRO模块介绍
天问五幺ASRPRO-CORE
模块是一款针对低成本离线语音应用方案开发的通用、便携、低功耗高性能语音识别模组。它采用最新的ASRPRO芯片,内置神经网络处理器,支持DNN、TDNN、RNN等神经网络及卷积运算,实现语音识别、声纹识别、语音增强、语音检测等功能,具备强劲的回声消除和环境噪声抑制能力。
2、emo表情机器人介绍
详见《ESP32C3手表变身桌面emo表情机器人》。这块手表的主控是ESP32C3,配备了一块1.69英寸
的触摸屏,分辨率达到240x320
,显示驱动采用的是ST7789
,触摸驱动则是CST816T
。

3、ASRPRO程序
选择串口通信的示例,适当修改,增加语音控制命令:

点击生成模型:

点击下载:

当提示“是否连接设备ASR-PRO?”时,关闭GND开关,再迅速打开,即可进行下载。如果没有进入下载模式,多重复关开GND开关试试。
4、语音控制
语音控制原理:ASRPRO接收语音,根据语音内容通过串口1输出字符串,ESP32C3通过串口接收字符串,并根据字符串内容显示出不同的表情。
测试代码如下:
from machineimportUART, Pin, SPI
importst7789
importtime
# 初始化串口
uart = UART(1, baudrate=9600, bits=8, parity=None, stop=1, tx=Pin(21), rx=Pin(20))
# 初始化屏幕
def config():
spi = SPI(1, baudrate=26666666, polarity=0, sck=Pin(5), mosi=Pin(6), miso=Pin(8))
returnst7789.ST7789(spi,240,320, dc=Pin(2, Pin.OUT), cs=Pin(3, Pin.OUT),
inversion=False, rotation=3, options=0)
tft = config()
tft.init()
# 定义眼睛的位置和大小
eye_radius =40 # 圆的半径
eye_distance =120 # 两个圆心之间的距离
left_eye_x =100
right_eye_x = left_eye_x + eye_distance
eye_y =100
# 定义眼珠的位置和大小
eyeball_radius =25 # 圆的半径
eyeball_width =50 # 眯眼矩形的宽度
eyeball_height =10 # 眯眼矩形的高度
move_dis = eye_radius - eyeball_radius -2
def draw_open_eyes():
# 绘制睁开的眼睛
tft.fill_circle(left_eye_x, eye_y, eye_radius, st7789.WHITE) # 左眼
tft.fill_circle(right_eye_x, eye_y, eye_radius, st7789.WHITE) # 右眼
tft.fill_circle(left_eye_x, eye_y, eyeball_radius, st7789.BLACK) # 左眼球
tft.fill_circle(right_eye_x, eye_y, eyeball_radius, st7789.BLACK) # 右眼球
def draw_closed_eyes():
# 绘制闭上的眼睛
tft.fill_circle(left_eye_x, eye_y, eye_radius, st7789.WHITE) # 左眼
tft.fill_circle(right_eye_x, eye_y, eye_radius, st7789.WHITE) # 右眼
tft.fill_rect(left_eye_x - eye_radius, eye_y - eye_radius, eye_radius *2+ eye_distance +2, eye_radius -5, st7789.BLACK)# 上眼皮
tft.fill_rect(left_eye_x - eye_radius, eye_y +5, eye_radius *2+ eye_distance +2, eye_radius, st7789.BLACK)# 下眼皮
def draw_ji_eyes():
# 绘制斗鸡眼
tft.fill_circle(left_eye_x, eye_y, eye_radius, st7789.WHITE) # 左眼
tft.fill_circle(right_eye_x, eye_y, eye_radius, st7789.WHITE) # 右眼
triangle_eye = [(100,80), (80,115), (88,120), (100,95), (112,120), (120,115)]
cen_x, cen_y = tft.polygon_center(triangle_eye)
tft.fill_polygon(triangle_eye,0,0, st7789.BLACK,1.57, cen_x, cen_y)
tft.fill_circle(left_eye_x, eye_y,5, st7789.BLACK) # 左眼球
tft.fill_polygon(triangle_eye, eye_distance,0, st7789.BLACK,4.71, cen_x, cen_y)
tft.fill_circle(right_eye_x, eye_y,5, st7789.BLACK) # 右眼球
def draw_happy_eyes():
# 绘制快乐的眼睛
tft.fill_circle(left_eye_x, eye_y, eye_radius, st7789.WHITE) # 左眼
tft.fill_circle(right_eye_x, eye_y, eye_radius, st7789.WHITE) # 右眼
tft.fill_circle(left_eye_x, eye_y, eyeball_radius, st7789.BLACK) # 左眼球
tft.fill_circle(right_eye_x, eye_y, eyeball_radius, st7789.BLACK) # 右眼球
tft.fill_circle(left_eye_x, eye_y + move_dis, eyeball_radius, st7789.WHITE) # 左眼球
tft.fill_circle(right_eye_x, eye_y + move_dis, eyeball_radius, st7789.WHITE) # 右眼球
def draw_angry_eyes():
# 绘制愤怒的眼睛
draw_ji_eyes()
tft.fill_circle(40,35,10, st7789.WHITE) # 生气标志
tft.fill_circle(38,33,10, st7789.BLACK)
tft.fill_circle(65,35,10, st7789.WHITE)
tft.fill_circle(67,33,10, st7789.BLACK)
tft.fill_circle(40,60,10, st7789.WHITE)
tft.fill_circle(38,62,10, st7789.BLACK)
tft.fill_circle(65,60,10, st7789.WHITE)
tft.fill_circle(67,62,10, st7789.BLACK)
def draw_sweat_eyes():
# 绘制流汗的表情
tft.fill_circle(left_eye_x, eye_y, eye_radius, st7789.WHITE) # 左眼
tft.fill_circle(right_eye_x, eye_y, eye_radius, st7789.WHITE) # 右眼
tft.fill_circle(left_eye_x, eye_y + move_dis, eyeball_radius, st7789.BLACK) # 左眼球
tft.fill_circle(right_eye_x, eye_y + move_dis, eyeball_radius, st7789.BLACK) # 右眼球
tft.vline(right_eye_x + eye_radius, eye_y - eye_radius,10, st7789.WHITE)
tft.vline(right_eye_x + eye_radius +5, eye_y - eye_radius,15, st7789.WHITE)
tft.vline(right_eye_x + eye_radius +10, eye_y - eye_radius,20, st7789.WHITE)
def main():
# 初始状态为黑屏
tft.fill(st7789.BLACK)
draw_open_eyes()
whileTrue:
# 读取从串口接收的数据
ifuart.any():
uart_MSG = uart.read()
print("Received:", uart_MSG)
ifuart_MSG == b'happyrn':
tft.fill(st7789.BLACK)
draw_happy_eyes()
elif uart_MSG == b'angryrn':
tft.fill(st7789.BLACK)
draw_angry_eyes()
elif uart_MSG == b'sweatrn':
tft.fill(st7789.BLACK)
draw_sweat_eyes()
elif uart_MSG == b'closedrn':
tft.fill(st7789.BLACK)
draw_closed_eyes()
elif uart_MSG == b'openrn':
tft.fill(st7789.BLACK)
draw_open_eyes()
time.sleep_ms(100)
if__name__ =="__main__":
main()
① 注意,ASRPRO输出的字符串带有'rn'。
② 我只列了5种表情,可自行增加,也可以显示文字、图片。
推荐阅读:
-
ESP8266通过MQTT接入Home Assistant(二)
-
群晖NAS安装Home Assistant OS和ha_xiaomi_home米家集成
-
行空板K10基于LVGL打造三轴水平仪 -
自制ESP8266开发板:打造智能温湿度与电池监测系统 -
完整版lvgl_micropython固件编译教程,完美支持中文显示 -
华为云服务器安装frp实现群晖NAS内网穿透 -
不到100元手搓一个摄像遥控小车(一)
-
基于ADS1115的高精度电压测量实验装置(1.硬件介绍)