1

I have this speech recognition script which records audio input and sends to Google's speech recognition servers and receives the results and shows them on Ubuntu terminal. But I am failing to make it work. My guess is that Google has made a change or something that is why it is not working anymore. I need this script for a voice based web browser project. Here is the script:

#!/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

Here is a sample incomplete output:

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...

After that it is not showing anything. To see how this script works go to this link: LINK

Please help me to find the error. Information:I am using Ubuntu12.04 in a VMware WS.

  • what is the value of $a that you are getting? – Mukund K Roy Jan 05 '13 at 14:22
  • The results.Have you been able to successfully run the script? –  Jan 05 '13 at 16:11
  • I am getting error 500 Internal Server error – Mukund K Roy Jan 05 '13 at 17:08
  • And I have run the script in rhel6. 'qalc' replaced with 'bc' – Mukund K Roy Jan 05 '13 at 17:11
  • So, what's the solution? I don't see any way of sending a personal message in stackoverflow. So, if you have a profile in any social networking site give the link in a comment.We won't get any solution in this speed.We need to discuss more.If we finally get a solution I will post that here. –  Jan 05 '13 at 18:27
  • ok first lets discuss what is the value google api is returning. I am getting error 500 Internal Server Error. echo $a and tell me. – Mukund K Roy Jan 06 '13 at 05:56

2 Answers2

0

The problem might be that your audio files are too long. I believe that the Google api is limited to files that are less than 3 seconds long.

Chuck Wooters
  • 1,224
  • 8
  • 7
  • 3 seconds might be too short. I tried uploading several 10 seconds long audio files. Some can be recognized. However, there has no any doc from Google talking about the audio duration limit. – Leo5188 May 16 '13 at 15:26
0

Please try to split your bash script into two pieces for debugging purpose. You'd better to prepare a valid FLAC audio file (sampled in 16K Hz) and send it to Google to verify that your core part works. If your plan is just using Google ASR, you may consider directly using this Python 3.0 solution

Leo5188
  • 1,967
  • 2
  • 17
  • 21