Google Voice Recognition

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(Script Usage)
(Script Code)
Line 16: Line 16:
 
* Temporary files <tt>message.flac</tt> and <tt>message.ret</tt> will be deleted after the process.
 
* Temporary files <tt>message.flac</tt> and <tt>message.ret</tt> will be deleted after the process.
  
==Script Code==
+
==Basic Script Code==
The script code can be tested on any Linux machine with SoX, SED, WGET installed. Modifiy the script according to your demands and storage of your audio files
+
The script code <tt>googlevoice.sh</tt> can be tested on any Linux machine with SoX, SED, WGET installed. Modifiy the script according to your demands and storage of your audio files
  
 
   #!/bin/sh
 
   #!/bin/sh
Line 33: Line 33:
  
 
The parameter <tt>lang=de-de</tt> is indicating, that the Google Voice API is expecting a German language audio file. Replace <tt>lang=de-de</tt> by <tt>lang=en-us</tt> to submit an audio file in US-English.
 
The parameter <tt>lang=de-de</tt> is indicating, that the Google Voice API is expecting a German language audio file. Replace <tt>lang=de-de</tt> by <tt>lang=en-us</tt> to submit an audio file in US-English.
 +
 +
== Script with Language Setting and Command Line Parameter ==
 +
The script <tt>googlevoicepar.sh</tt> with a command line parameter can be used if you want to use multiple input files for batch file recognition. You will call this script with the basename e.g. <tt>message0, message1,...</tt> by
 +
* <tt>googlevoicepar.sh message0</tt> converts <tt>message0.wav</tt> into <tt>message0.txt</tt>
 +
* <tt>googlevoicepar.sh message1</tt> converts <tt>message1.wav</tt> into <tt>message1.txt</tt>
 +
* <tt>googlevoicepar.sh message2</tt> converts <tt>message2.wav</tt> into <tt>message2.txt</tt>
 +
* ....
 +
 +
  #!/bin/sh
 +
  LANGUAGE="de-de"
 +
  echo "1 SoX Sound Exchange - Convert $1.wav to $1.flacC with 16000"
 +
  sox $1.wav $1.flac rate 16k
 +
  echo "2 Submit to Google Voice Recognition $1.flac"
 +
  wget -q -U "Mozilla/5.0" --post-file message.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=${LANGUAGE}&client=chromium" > $1.ret
 +
  echo "3 SED Extract recognized text"
 +
  cat $1.ret | sed 's/.*utterance":"//' | sed 's/","confidence.*//' > $1.txt
 +
  echo "4 Remove Temporary Files"
 +
  rm $1.flac
 +
  rm $1.ret
 +
  echo "5 Show Text "
 +
  cat $1.txt
  
 
==Links==
 
==Links==

Revision as of 17:08, 3 October 2011

Because the performance of your Freerunner is too poor for voice recognition, the Google Voice API can be used to convert an recorded Audio file into a text string. Be aware that the audio file will be transmitted to Google, so need to have Internet access on your freerunner FR to submit the audio file.

NOTE: You must be aware of the fact, that the follow script is running on your freerunner but it is not a standalone voice recognition software and so you might not want to use this tool for private audio files.


Contents

Google Voice API

For using the Google Voice API and the script you need to have the following package installed on your freerunner:

Script Usage

  • The script googlevoice.sh uses a the audio file message.wav in the directory of the script. All files are stored in the same directory, so you need write permissions for that directory.
  • SoX converts message.wav into message.flac
  • wget submits the file message.flac to the Google Voice API and writes the return message to message.ret. The language variable in the script is set to German by lang=de-de. If you want to submit a recorded file in US-English use lang=en-us instead.
  • SED extracts the recognized text message.ret by regular expressions and writes the text into message.txt.
  • Temporary files message.flac and message.ret will be deleted after the process.

Basic Script Code

The script code googlevoice.sh can be tested on any Linux machine with SoX, SED, WGET installed. Modifiy the script according to your demands and storage of your audio files

 #!/bin/sh
 echo "1 SoX Sound Exchange - Convert WAV to FLAC with 16000" 
 sox message.wav message.flac rate 16k
 echo "2 Submit to Google Voice Recognition"
 wget -q -U "Mozilla/5.0" --post-file message.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=de-de&client=chromium" > message.ret
 echo "3 SED Extract recognized text" 
 cat message.ret | sed 's/.*utterance":"//' | sed 's/","confidence.*//' > message.txt
 echo "4 Remove Temporary Files"
 rm message.flac
 rm message.ret
 echo "5 Show Text "
 cat message.txt

The parameter lang=de-de is indicating, that the Google Voice API is expecting a German language audio file. Replace lang=de-de by lang=en-us to submit an audio file in US-English.

Script with Language Setting and Command Line Parameter

The script googlevoicepar.sh with a command line parameter can be used if you want to use multiple input files for batch file recognition. You will call this script with the basename e.g. message0, message1,... by

  • googlevoicepar.sh message0 converts message0.wav into message0.txt
  • googlevoicepar.sh message1 converts message1.wav into message1.txt
  • googlevoicepar.sh message2 converts message2.wav into message2.txt
  • ....
 #!/bin/sh
 LANGUAGE="de-de"
 echo "1 SoX Sound Exchange - Convert $1.wav to $1.flacC with 16000" 
 sox $1.wav $1.flac rate 16k
 echo "2 Submit to Google Voice Recognition $1.flac"
 wget -q -U "Mozilla/5.0" --post-file message.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=${LANGUAGE}&client=chromium" > $1.ret
 echo "3 SED Extract recognized text" 
 cat $1.ret | sed 's/.*utterance":"//' | sed 's/","confidence.*//' > $1.txt
 echo "4 Remove Temporary Files"
 rm $1.flac
 rm $1.ret
 echo "5 Show Text "
 cat $1.txt

Links

Personal tools

Because the performance of your Freerunner is too poor for voice recognition, the Google Voice API can be used to convert an recorded Audio file into a text string. Be aware that the audio file will be transmitted to Google, so need to have Internet access on your freerunner FR to submit the audio file.

NOTE: You must be aware of the fact, that the follow script is running on your freerunner but it is not a standalone voice recognition software and so you might not want to use this tool for private audio files.


Google Voice API

For using the Google Voice API and the script you need to have the following package installed on your freerunner:

Script Usage

  • The script googlevoice.sh uses a the audio file message.wav in the directory of the script. All files are stored in the same directory, so you need write permissions for that directory.
  • SoX converts message.wav into message.flac
  • wget submits the file message.flac to the Google Voice API and writes the return message to message.ret. The language variable in the script is set to German by lang=de-de. If you want to submit a recorded file in US-English use lang=en-us instead.
  • SED extracts the recognized text message.ret by regular expressions and writes the text into message.txt.
  • Temporary files message.flac and message.ret will be deleted after the process.

Script Code

The script code can be tested on any Linux machine with SoX, SED, WGET installed. Modifiy the script according to your demands and storage of your audio files

 #!/bin/sh
 echo "1 SoX Sound Exchange - Convert WAV to FLAC with 16000" 
 sox message.wav message.flac rate 16k
 echo "2 Submit to Google Voice Recognition"
 wget -q -U "Mozilla/5.0" --post-file message.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=de-de&client=chromium" > message.ret
 echo "3 SED Extract recognized text" 
 cat message.ret | sed 's/.*utterance":"//' | sed 's/","confidence.*//' > message.txt
 echo "4 Remove Temporary Files"
 rm message.flac
 rm message.ret
 echo "5 Show Text "
 cat message.txt

The parameter lang=de-de is indicating, that the Google Voice API is expecting a German language audio file. Replace lang=de-de by lang=en-us to submit an audio file in US-English.

Links