本文主要是介绍K210(SiPEED MaixBit)MicroPython使用参考(四、孤立词语音识别),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.首先确定K210使用带语音功能的固件:
1)固件更新工具Kflash_gui 1.6.5_2:kflash_gui_v1.6.5_2_windows.7z_kflash_gui下载-深度学习文档类资源-CSDN文库或
下载站 - Sipeed33
2)带语音功能简化版固件0.6.2_78:
http://cn.dl.sipeed.com/fileList/MAIX/MaixPy/release/master/maixpy_v0.6.2_77_g11806960d/maixpy_v0.6.2_77_g11806960d_minimum_speech_with_ide_support.bin
2.运行以下代码:
import time
from Maix import GPIO, I2S
from fpioa_manager import fm
from speech_recognizer import isolated_word
# user setting
sample_rate = 16000
record_time = 4 #sfm.register(20,fm.fpioa.I2S0_IN_D0, force=True)
fm.register(18,fm.fpioa.I2S0_SCLK, force=True)
fm.register(19,fm.fpioa.I2S0_WS, force=True)rx = I2S(I2S.DEVICE_0)
rx.channel_config(rx.CHANNEL_0, rx.RECEIVER, align_mode=I2S.STANDARD_MODE)
rx.set_sample_rate(sample_rate)
print(rx)sr = isolated_word(dmac=2, i2s=I2S.DEVICE_0, size=15, shift=1) # maix bit set shift=1
print(sr.size())
print(sr)# threshold
sr.set_threshold(0, 0, 10000)# record and get & set
while True:time.sleep_ms(100)#不停循环print('voice 0 state:',sr.state()) #等待语音输入时是5,有语音变成6if sr.Done == sr.record(0): #有语音信号data = sr.get(0) #获取语音信号数据print(data) #打印数据break #退出循环if sr.Speak == sr.state(): #持续等待语音输入print('Please speak: 0')
.3.正常情况下一开始显示如下信息:
等几秒钟后,以下信息不停循环显示:
这时候,对着开发板话筒大声说“0”,此时出现以下信息且停止程序运行:
如果无反应或显示不与上述一致,说明固件错误或者配置有误,主要是I2S的引脚以及声道(即shift)的设置。
4.运行以下代码:
import time
from Maix import GPIO, I2S
from fpioa_manager import fm
from speech_recognizer import isolated_word
# user setting
sample_rate = 16000
record_time = 4 #sio_led_red = 13
fm.register(io_led_red, fm.fpioa.GPIO0)
led_r=GPIO(GPIO.GPIO0, GPIO.OUT)
fm.register(20,fm.fpioa.I2S0_IN_D0, force=True)
fm.register(18,fm.fpioa.I2S0_SCLK, force=True)
fm.register(19,fm.fpioa.I2S0_WS, force=True)rx = I2S(I2S.DEVICE_0)
rx.channel_config(rx.CHANNEL_0, rx.RECEIVER, align_mode=I2S.STANDARD_MODE)
rx.set_sample_rate(sample_rate)
print(rx)sr = isolated_word(dmac=2, i2s=I2S.DEVICE_0, size=15, shift=1) # maix bit set shift=1
print(sr.size())
print(sr)# threshold
sr.set_threshold(0, 0, 10000)# record and get & set
while True:time.sleep_ms(100)#不停循环print('voice 0 state:',sr.state()) #等待语音输入时是5,有语音变成6if sr.Done == sr.record(0): #有语音信号data = sr.get(0) #获取语音信号数据print(data) #打印数据break #退出循环if sr.Speak == sr.state(): #持续等待语音输入print('Please speak: 0') #要求对着话筒说0
while True:time.sleep_ms(100)print('voice 0 state:',sr.state())if sr.Done == sr.record(1):data = sr.get(1)print(data)breakif sr.Speak == sr.state():print('Please speak: 1') #要求对着话筒说1# recognizer
time.sleep_ms(1000)#等待一段时间
print('recognizer\n')
while True:time.sleep_ms(3000)print('SR recognize state:',sr.state()) #等待语音输入时是5,有语音变成6print('DTW value:',sr.dtw(data)) #DTW值if sr.Done == sr.recognize():res = sr.result()print('res value:',res)if res!=None: #无法识别输出Noneled_r.value(res[0]) #根据识别的语音开关灯,0点亮,1关闭
根据提示,先录入语音0,然后录入语音1,等待几秒后,当串行终端出现“SR recognize state: 5”时,再次对着开发板话筒说0或者1,系统将进行识别,实现对led的控制,0点亮,1关闭。
5.本开发板板载硅麦型号为MSM261S4030H0R,查手册知其为标准I2S输出,故在此设置为align_mode=I2S.STANDARD_MODE,称之为飞利浦格式,对于部分DAC语音设备,较常采用align_mode=I2S.RIGHT_JUSTIFYING_MODE,也被称为日本格式。
6.参考资料来自官方网站:
isolated word - Sipeed Wiki
这篇关于K210(SiPEED MaixBit)MicroPython使用参考(四、孤立词语音识别)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!