1

オーディオ入力を記録してGoogleの音声認識サーバーに送信し、結果を受信して​​Ubuntuターミナルに表示するこの音声認識スクリプトがあります。しかし、私はそれを機能させることに失敗しています。私の推測では、Google が変更または何かを行ったため、それが機能しなくなったのです。音声ベースの 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 を使用しています。

4

2 に答える 2

0

オーディオ ファイルが長すぎることが問題である可能性があります。Google API は、長さが 3 秒未満のファイルに限定されていると思います。

于 2013-01-07T21:57:11.500 に答える