ASR Unit
Unit ASR 是一款 AI 离线语音识别单元,内置 CI-03T AI 智能离线语音模块。该单元具备强大的语音识别、声纹识别、语音增强和语音检测等功能。支持 AEC(回声消除)功能,有效去除回声和噪声干扰,提升语音识别准确性。同时支持中途语音打断功能,允许在语音识别过程中灵活打断并快速响应新的指令。产品出厂时已预设了42条英文唤醒词和反馈命令词,该设备采用 UART 串口通信进行数据传输,同时支持通过 UART 或语音关键词唤醒设备。该单元支持用户自定义修改多语言唤醒识别词,用户可以通过重新生成固件来修改唤醒词,最多支持 300 条命令词的识别。配备麦克风用于清晰音频采集,并内置扬声器提供高质量的音频反馈。该产品广泛应用于 AI 助手、智能家居、安防监控、车载系统、机器人与智能硬件、医疗健康等领域,是实现智能语音交互的理想选择。
支持下列产品:
UiFlow2 应用示例
ASR 示例程序
在 UiFlow2 上打开 asr_cores3_example.m5f2 项目。
本例展示了如何使用 Unit ASR 获取当前命令词、命令编号,并在说出”你好“时触发事件,以执行你想做的事情。
UiFlow2 代码块:
示例输出:
None
MicroPython 应用示例
ASR 示例程序
本例展示了如何使用 Unit ASR 获取当前命令词、命令编号,并在说出”你好“时触发事件,以执行你想做的事情。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from unit import ASRUnit 9 10 11title0 = None 12label0 = None 13label1 = None 14label2 = None 15label3 = None 16asr_0 = None 17 18 19def asr_0_hello_event(args): 20 global title0, label0, label1, label2, label3, asr_0 21 print("Rec Hello") 22 23 24def setup(): 25 global title0, label0, label1, label2, label3, asr_0 26 27 M5.begin() 28 Widgets.fillScreen(0x222222) 29 title0 = Widgets.Title( 30 "UnitASR M5CoreSe Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 31 ) 32 label0 = Widgets.Label("msg:", 0, 51, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 33 label1 = Widgets.Label("rec cmd num:", 0, 93, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 34 label2 = Widgets.Label( 35 "rec cmd word:", 0, 134, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 36 ) 37 label3 = Widgets.Label( 38 "rec cmd handler state:", 0, 178, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 39 ) 40 41 asr_0 = ASRUnit(2, port=(1, 2)) 42 print(asr_0.search_command_num("hello")) 43 print(asr_0.search_command_word(0x32)) 44 asr_0.add_command_word(0x32, "hello", asr_0_hello_event) 45 46 47def loop(): 48 global title0, label0, label1, label2, label3, asr_0 49 M5.update() 50 if asr_0.get_received_status(): 51 label0.setText(str((str("msg:") + str((asr_0.get_current_raw_message()))))) 52 label1.setText(str((str("rec cmd num:") + str((asr_0.get_current_command_num()))))) 53 label2.setText(str((str("rec cmd word:") + str((asr_0.get_current_command_word()))))) 54 label3.setText(str((str("rec cmd handler state:") + str((asr_0.get_command_handler()))))) 55 56 57if __name__ == "__main__": 58 try: 59 setup() 60 while True: 61 loop() 62 except (Exception, KeyboardInterrupt) as e: 63 try: 64 from utility import print_error_msg 65 66 print_error_msg(e) 67 except ImportError: 68 print("please update to latest firmware")
示例输出:
None
API
ASRUnit
- class unit.asr.ASRUnit(id=1, port=None, verbose=False)
基类:
object
语音识别硬件模块
UiFlow2 代码块:
MicroPython 代码块:
from unit import ASRUnit # Initialize with UART1, TX on pin 2, RX on pin 1 asr = ASRUnit(id=1, port=(1, 2))
- get_received_status()
获取信息接收状态。
- 返回:
如果收到信息则为 True,否则为 False。
- 返回类型:
UiFlow2 代码块:
MicroPython 代码块:
asr.get_received_status()
- send_message(command_num)
通过 UART 发送命令。
- 参数:
command_num (int) – 要发送的命令编号(0-255)
- 返回类型:
None
UiFlow2 代码块:
MicroPython 代码块:
asr.send_message(0x30)
- get_current_raw_message()
以十六进制格式获取接收到的原始信息。
- 返回:
十六进制格式的原始报文字符串。
- 返回类型:
UiFlow2 代码块:
MicroPython 代码块:
asr.get_current_raw_message()
- get_current_command_word()
获取与当前命令编号相对应的命令词。
- 返回:
以字符串形式显示的命令词。
- 返回类型:
UiFlow2 代码块:
MicroPython 代码块:
asr.get_current_command_word()
- get_current_command_num()
获取当前命令编号。
- 返回:
字符串形式的当前命令编号。
- 返回类型:
UiFlow2 代码块:
MicroPython 代码块:
asr.get_current_command_num()
- get_command_handler()
检查当前命令是否有关联回调函数。
- 返回:
如果命令有关联回调函数,则为 True;否则为 False。
- 返回类型:
UiFlow2 代码块:
MicroPython 代码块:
asr.get_command_handler()
- add_command_word(command_num, command_word, event_handler=None)
注册自定义命令和回调函数。
- 参数:
- 返回类型:
None
UiFlow2 代码块:
MicroPython 代码块:
def custom_handler(unit): print("Custom command detected!") asr.add_command_word(0x50, "custom command", custom_handler)
- remove_command_word(command_word)
从命令列表中删除命令词。
- 参数:
command_word (str) – 要删除的命令词
- 返回类型:
None
UiFlow2 代码块:
MicroPython 代码块:
asr.remove_command_word("custom command")
- search_command_num(command_word)
搜索与命令词相关的命令编号。
UiFlow2 代码块:
MicroPython 代码块:
asr.search_command_num("custom command")
- search_command_word(command_num)
搜索与命令编号相关的命令词。
UiFlow2 代码块:
MicroPython 代码块:
asr.search_command_word(0x50)
- get_command_list()
获取所有命令词及其相关回调函数的列表。
- 返回:
包含命令编号及其相应命令词和回调函数的字典。
- 返回类型:
UiFlow2 代码块:
MicroPython 代码块:
asr.get_command_list()
- check_tick_callback()
检查当前命令是否定义了回调函数,并安排其执行。
- 返回:
回调函数(如果已定义),否则无
- 返回类型:
None
MicroPython 代码块:
asr.check_tick_callback()