Next, I want to integrate recording and keyword recognition into one program.
The first thing that comes to mind when performing voice operations in Python is PyAudio. However, installing PyAudio on the board is a bit troublesome. There is no ready-made software package corresponding to this board in the Python repository, and the software package needs to be compiled on the board. PyAudio depends on PortAudio, and PortAudio has not been transplanted on the board, so PyAudio cannot be used for the time being. This problem will be solved later. The temporary method I used was to modify the shell script for the test audio mentioned above, record 1 second of speech, and then call the Python program for keyword recognition. If it is YES, turn on the LED light on the development board, and if it is NO, turn off the LED light on the development board. After turning on or off the light, the corresponding prompt tone will be played. For the convenience of debugging, the recording result will be automatically played after recording to determine whether the recording is correct. INIT_FLAG="/home/root/shell/audio/.initialized_audio_device" PLAY_FILE="/home/root/shell/audio/short.mp3" RC_LOCAL_FILE="/etc/rc.local" DELETE_COMMAND="rm -f $INIT_FLAG" # 将开机自动删除音频初始化标志文件命令加入到开机自启中 if ! grep -qFx "$DELETE_COMMAND" "$RC_LOCAL_FILE"; then echo "$DELETE_COMMAND" >> "$RC_LOCAL_FILE" command -v "$1" > /dev/null 2>&1 amixer cset name='PCM Volume' 192 amixer cset name='Mono Mux' 'Stereo' amixer cset name='Playback De-emphasis' 2 amixer cset name='Capture Digital Volume' 192 amixer cset name='Capture Mute' 'on' amixer cset name='Capture Polarity' 'Normal' amixer cset name='3D Mode' 'No 3D' amixer cset name='ALC Capture Attack Time' 5 amixer cset name='ALC Capture Decay Time' 2 amixer cset name='ALC Capture Function' 'Stereo' amixer cset name='ALC Capture Hold Time' 2 amixer cset name='ALC Capture Max PGA' 3 amixer cset name='ALC Capture Min PGA' 6 amixer cset name='ALC Capture NG Switch' 'on' amixer cset name='ALC Capture NG Threshold' 9 amixer cset name='ALC Capture NG Type' 'Mute ADC Output' amixer cset name='ALC Capture Target Volume' 15 amixer cset name='ALC Capture ZC Switch' 'on' amixer cset name='Left Channel Capture Volume' 100% amixer cset name='Right Channel Capture Volume' 100% amixer cset name='Left Mixer Left Bypass Volume' 100% amixer cset name='Right Mixer Right Bypass Volume' 100% amixer cset name='Output 1 Playback Volume' 100% amixer cset name='Output 2 Playback Volume' 100% amixer cset name='ZC Timeout Switch' 'on' amixer cset name='Left PGA Mux' 'DifferentialL' amixer cset name='Right PGA Mux' 'DifferentialR' function init_board_mic() { check_command amixer && { amixer -q cset name='Differential Mux' 'Line 2' amixer -q cset name='Left Line Mux' 'Line 2L' amixer -q cset name='Right Line Mux' 'Line 2R' function init_headphone_mic() { check_command amixer && { amixer cset name='Differential Mux' 'Line 1' amixer cset name='Left Line Mux' 'Line 1L' amixer cset name='Right Line Mux' 'NC' check_command amixer && { amixer -q cset name='Left Mixer Left Bypass Switch' 'on' amixer -q cset name='Right Mixer Right Bypass Switch' 'on' amixer -q cset name='Left Mixer Left Playback Switch' 'off' amixer -q cset name='Right Mixer Right Playback Switch' 'off' check_command amixer && { amixer -q cset name='Left Mixer Left Bypass Switch' 'off' amixer -q cset name='Right Mixer Right Bypass Switch' 'off' amixer -q cset name='Left Mixer Left Playback Switch' 'on' amixer -q cset name='Right Mixer Right Playback Switch' 'on' check_command amixer && { amixer -q cset name='Left Mixer Left Bypass Switch' 'off' amixer -q cset name='Right Mixer Right Bypass Switch' 'off' amixer -q cset name='Left Mixer Left Playback Switch' 'off' amixer -q cset name='Right Mixer Right Playback Switch' 'off' amixer -q cset name='Left Line Mux' 'NC' amixer -q cset name='Right Line Mux' 'NC' function apply_config() { # read -r -p "请输入您的选择: " choice # if [[ "$choice" == "1" || "$choice" == "2" ]]; then printf "n应用麦克风配置项 %sn" "$choice" # 捕获Ctrl+C信号,并调用cleanup函数 # if ! check_initialized; then # printf "第一次运行,执行音频设备初始化...n" check_command arecord && arecord -f cd -d 1 -r 16000 "$RECORD_FILE" check_command aplay && aplay "$RECORD_FILE" output=$(python3 simple_audio.py --input=test.wav) if echo "$output" | grep -q ">>> YES"; then echo "Python程序输出YES,执行相应代码..." echo 1 > /sys/class/leds/sys-led/brightness echo heartbeat > /sys/class/leds/sys-led/trigger #gst-play-1.0 haodeyiweinindakai.mp3 aplay haodeyiweinindakai.wav elif echo "$output" | grep -q ">>> NO"; then echo "Python程序输出NO,执行其他代码..." echo none > /sys/class/leds/sys-led/trigger echo 0 > /sys/class/leds/sys-led/brightness #gst-play-1.0 haodeyiweininguanbi.mp3 aplay haodeyiweininguanbi.wav echo "Python程序输出未知结果,或者没有输出结果。" printf "n开始播音,按 Ctrl+C 可退出播音n" gst-play-1.0 --audiosink="alsasink" "$PLAY_FILE"
 See the compressed package for the complete program*Attachment: yes-no-test.zipThe core script code is as follows: From the video below, we can see that the desired effect is basically achieved. I was worried that the microphone recording effect of the board would affect the recognition, but it seems that this is not a big problem. Since the method of recording into a file first is adopted, and the time is only 1 second, it is still quite troublesome to use. Sometimes if you speak a little slowly, it will not be recorded completely. This requires the subsequent optimization of Python's voice processing.
[Trial of the Zhengdian Atom i.MX93 development board] Use voice to say YES or NO to control the LED light
In addition, the model currently used is pre-trained, and we plan to train Chinese prompt words in the future for easier use. |