So this is a follow up to my post a while ago, talking about how to use the Google Speech Recognition API built in to Google Chrome.
Since my last post, Chrome has had some significant upgrades to this feature- specifically around the length of audio you can pass to the API. The old version would only let you pass very short clips (only a few seconds), but the new API is a full-duplex streaming API. What this means, is that it actually uses two HTTP connections- one POST request to upload the content as a “live” chunked stream, and a second GET request to access the results, which makes much more sense for longer audio samples, or for streaming audio.
I created a simple PHP class to access this API; while this likely won’t make sense for anybody that wants to do a real-time stream, it should satisfy most cases where people just want to send “longer” audio clips.
Before you can use this PHP class, you must get a developer API key from Google. The class does not include one, and I cannot give you one- they’re free, and easy to get just go to the Google APIs site, and sign up for one.
Then download the class below, and start with a simple example:
<? require 'google_speech.php'; $s = new cgoogle_speech('put your API key here'); $output = $s->process('@test.flac', 'en-US', 8000); print_r($output); ?>
Audio can be passed as a filename (by prefixing the ‘@’ sign in front of the file name), or by passing in raw FLAC content. The second argument is an IETF language tag. I’ve only been able to test with both English and French, but I assume others work. It defaults to ‘en-US’. The third argument is sample rate, it defaults to 8000.
** Your sample rate must match your file- if it doesn’t, you’ll either get nothing returned, or you’ll get a really bad transcription. **
The output will return as an array, and should look something like this:
Array (  => Array ( [alternative] => Array (  => Array ( [transcript] => my CPU is a neural net processor a learning computer [confidence] => 0.74177068 )  => Array ( [transcript] => my CPU is the neuron that process of learning )  => Array ( [transcript] => my CPU is the neural net processor a learning )  => Array ( [transcript] => my CPU is the neuron that process a balloon )  => Array ( [transcript] => my CPU is the neural net processor a living ) ) [final] => 1 ) )
Get the PHP class here: http://mikepultz.com/uploads/google_speech.php.zip
Something does seem to have changed. I enabled the API, created a key and ran a few queries with a file that is under 5 minutes in length. I never did get a positive response from the API, but my project is now marked abusive in the google console with over 18,000 hits. The appeal screen has no submit on it, only a cancel.
where did you can found the speech api to enable? I can’t found the speech api service to enabled in my account. please help
I was able to use your solution but could only get the output out of the first 10 seconds only !! wherein, my audio flac file is of 31 seconds. Any idea, why this wont be working ??
Any help is appreciated!
i tested this one out using curl on a flac input and it looks interesting.
IMO — relevant due to IBM making increasing efforts to roll-out a dev stack and dev console that may work for people having issues with the rate-cap over at Google-speech.
Any suggestion for doing the same trick on Android?
I am trying to use google api to translate speech to text but with a wav/mp3 file but it does not seem to work. Can you please tell me if google support this types of audio instead of flac files
No, it just seems to support FLAC and some form of Speex.
Hi, i am unable to find speech-to-text api on google developer console, is there still a Google streaming speech recognition webservice there?
hi, so i got through the api key for speech api. now i want to upload a wav file
can i simply change your code to .
curl_setopt($this->m_up_handle, CURLOPT_HTTPHEADER, array(‘Transfer-Encoding: chunked’,
‘Content-Type: audio/l16; rate=16000’ ));
and wav file work? does google accept a wav file. because i am getting empty array
It does accept wav file here. https://github.com/gillesdemey/google-speech-v2 do i need to change the URl to https://www.google.com/speech-api/v2/recognize ?
i am also unable to find speech-to-text api on google developer console,could you tell me ?
I tried to run the script as it is. But I was not getting the output at all. Probably there is something wrong with my flac file. Can you share the flac file you have tested with. It would be very much helpful. Thanks.
It’s working good on my hosting. But It’s not work on my Localhost. I used Xampp. it just return “Array ( )”. I don’t what is the problem. please help me.
I have followed all your above instructions but, still i am not getting output.
1. Enable Speech API.
2. Properly setup API key in application.
How i can check that google is providing proper response?
Pingback: Continuous Speech Recognition Android - Without Gaps - android
The google API url is outdated. This demo and other 100 along with it are obsolete. Google screw all of them..
I’m extremely pleased to uncover this page. I wanted to thank you forr ones time just for this fantastic read!!
I definitely appreciated every little bit of it and I have you book marked tto check out new stuff in your web site.