调试目标
- 考虑到K210的交互界面比较少,因此考虑用户的信息录入采用二维码的方式,可以用ID名字等一次二维码扫描搞定,然后通过语音提示用户录入成功
调试准备
- 基于之前的帖子有提到wav语音的播放,因此首先需要用GoldenWav CN软件,用文字转换语音的方式,准备一段 “识别成功” 的语音文件
- 使用草料二维码(https://cli.im/text)转换出一段 包含如下信息“eeworld,123654,01:02:03:04:05:06,cs” 信息的二维码。
调试代码
import sensor
import image
import lcd
import time
from fpioa_manager import *
from Maix import I2S, GPIO
import audio
def audio_init():
# register i2s(i2s0) pin
fm.register(34, fm.fpioa.I2S0_OUT_D1, force=True)
fm.register(35, fm.fpioa.I2S0_SCLK, force=True)
fm.register(33, fm.fpioa.I2S0_WS, force=True)
# init i2s(i2s0)
wav_dev = I2S(I2S.DEVICE_0)
print("i2s init")
return wav_dev
def audio_play(wav_dev, volume):
# init audio
player = audio.Audio(path="/sd/2.wav")
player.volume(volume)
print("audio init")
# read audio info
wav_info = player.play_process(wav_dev)
# config i2s according to audio info
wav_dev.channel_config(wav_dev.CHANNEL_1, I2S.TRANSMITTER, resolution=I2S.RESOLUTION_16_BIT,
cycles=I2S.SCLK_CYCLES_16, align_mode=I2S.RIGHT_JUSTIFYING_MODE)
wav_dev.set_sample_rate(wav_info[1])
# loop to play audio
while True:
ret = player.play()
if ret == None:
print("format error")
break
elif ret == 0:
print("end")
break
player.finish()
#-----------------------------------------------------------
clock = time.clock()
dev = audio_init()
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(1)
sensor.run(1)
sensor.skip_frames(30)
while True:
clock.tick()
img = sensor.snapshot()
res = img.find_qrcodes()
fps =clock.fps()
if len(res) > 0:
img.draw_string(2, 2, res[0].payload(), color=(0,128,0), scale=2)
print(res[0].payload())
audio_play(dev, 50)
lcd.display(img)
调试结果
- 当用手机出示二维码时候,界面出现识别后字符串,同时播放出一段语音提示,识别成功!