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  #s

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,有语音变成6
  if sr.Done == sr.record(0): #有语音信号
    data = sr.get(0) #获取语音信号数据
    print(data) #打印数据
    break #退出循环
  if sr.Speak == sr.state(): #持续等待语音输入
    print('Please speak: 0')

.3.正常情况下一开始显示如下信息:

K210(SiPEED MaixBit)MicroPython使用参考(四、孤立词语音识别)

几秒钟后,将连续循环显示以下信息:

[En]

After a few seconds, the following information is displayed in a continuous loop:

K210(SiPEED MaixBit)MicroPython使用参考(四、孤立词语音识别)

此时,对着开发板麦克风大声说“0”,出现以下信息,程序停止运行:

[En]

At this point, say “0” loudly into the development board microphone, the following message appears and the program stops running:

K210(SiPEED MaixBit)MicroPython使用参考(四、孤立词语音识别)

如果无反应或显示不与上述一致,说明固件错误或者配置有误,主要是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  #s

io_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,有语音变成6
  if 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)
    break
  if 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,有语音变成6
   print('DTW value:',sr.dtw(data)) #DTW值
   if sr.Done == sr.recognize():
     res = sr.result()
     print('res value:',res)
     if res!=None:  #无法识别输出None
       led_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

Original: https://blog.csdn.net/weixin_41784968/article/details/124784290
Author: SDAU2005
Title: K210(SiPEED MaixBit)MicroPython使用参考(四、孤立词语音识别)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/497688/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球