我有这个语音识别脚本,它记录音频输入并发送到谷歌的语音识别服务器并接收结果并在 Ubuntu 终端上显示它们。但我无法让它发挥作用。我的猜测是谷歌已经做出了改变,或者这就是它不再工作的原因。我需要此脚本用于基于语音的 Web 浏览器项目。这是脚本:
#!/bin/bash
results=6
if [ "$1" == "-r" ];then
results="$2"
fi
echo "Recording... Please press ^C a few seconds after finishing."
rec -r 16000 -b 16 -c 1 test.wav > /dev/null 2>&1
echo
echo "Recording finished!"
sox test.wav test.flac gain -n -5 silence 1 5 2% > /dev/null 2>&1
echo "Now uploading to google's speech recognition servers."
echo
echo "This may take a bit..."
a=$(curl \
--data-binary @test.flac \
--header 'Content-type: audio/x-flac; rate=16000' \
'https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&pfilter=2&lang=en-US&maxresults='$results'' 2>/dev/null)
#echo "Done! Parsing results..."
echo
b=$(echo "$a" |egrep -o "\"confidence\":[^}]*" |sed 's/"confidence"://')
c=$(qalc $b \* 100 | egrep -o "=.*" |sed 's/= //' |sed 's/\.\([0-9]\)*/\.\1/')
echo "Done, results below :)"
echo
echo "Confidence in results = ${c}%"
echo "$a" | egrep -o "\"utterance\":\"[^\"]*\"" |sed 's/"utterance":"//;s/"//'|nl
这是一个不完整的输出示例:
john@ubuntu:~/Desktop$ ./test.bash
Recording... Please press ^C a few seconds after finishing.
^C
Recording finished!
Now uploading to google's speech recognition servers.
This may take a bit...
之后它没有显示任何东西。要查看此脚本的工作原理,请访问此链接: LINK
请帮我找出错误。信息:我在 VMware WS 中使用 Ubuntu12.04。