Note that there are some explanatory texts on larger screens.

plurals
  1. POFlash SPEEX codec coversion for Google Speech API - a challenge
    text
    copied!<p>People have figured out how to use the Google Speech API (Speech-To-Text). I'm trying to get it working with Flash Speex codec, and I just can't figure it out. I've tried inserting frame size byte before each 160 bytes (as some sources say), but this doesn't work.</p> <p>So I post a challenge to somehow translate the flash speex bytes for Google Speech API to understand.</p> <p>Here is basic flex code:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init();"&gt; &lt;fx:Script&gt; &lt;![CDATA[ // Speech API info // Reference: http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/, // Reference: https://stackoverflow.com/questions/4361826/does-chrome-have-buil-in-speech-recognition-for-input-type-text-x-webkit-speec private static const speechApiUrl:String = "http://www.google.com/speech-api/v1/recognize"; private static const speechLanguage:String = "en"; private static const mimeType:String = "audio/x-speex-with-header-byte"; private static const sampleRate:uint = 8; // Sound bytes &amp; mic private var soundBytes:ByteArray; private var microphone:Microphone; // Initial setup private function init():void { // Set up the microphone microphone = Microphone.getMicrophone(); // Speech API supports 8khz and 16khz rates microphone.rate = sampleRate; // Select the SPEEX codec microphone.codec = SoundCodec.SPEEX; // I don't know what effect this has... microphone.framesPerPacket = 1; } // THIS IS THE CHALLENGE // We have the flash speex bytes and we need to translate them so Google API understands private function process():void{ soundBytes.position = 0; var processed:ByteArray = new ByteArray(); processed.endian = Endian.BIG_ENDIAN; var frameSize:uint = 160; for(var n:uint = 0; n &lt; soundBytes.bytesAvailable / frameSize; n++){ processed.writeByte(frameSize); processed.writeBytes(soundBytes, frameSize * n, frameSize); } processed.position = 0; soundBytes = processed; } // Sending to Google Speech server private function send():void { var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest(speechApiUrl + "?lang=" + speechLanguage); request.method = URLRequestMethod.POST; request.data = soundBytes; request.contentType = mimeType + "; rate=" + (1000 * sampleRate); loader.addEventListener(Event.COMPLETE, onComplete); loader.addEventListener(IOErrorEvent.IO_ERROR, onError); loader.load(request); trace("Connecting to Speech API server"); } private function onError(event:IOErrorEvent):void{ trace("Error: " + event.toString()); } private function onComplete(event:Event):void{ trace("Done: " + event.target.data); } private function record(event:Event):void{ soundBytes = new ByteArray(); soundBytes.endian = Endian.BIG_ENDIAN; microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, sampleData); } private function sampleData(event:SampleDataEvent):void { soundBytes.writeBytes(event.data, 0, event.data.bytesAvailable); } private function stop(e:Event):void { microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, sampleData); if(soundBytes != null){ process(); send(); } } ]]&gt; &lt;/fx:Script&gt; &lt;s:HGroup&gt; &lt;s:Button label="Record" click="record(event)"/&gt; &lt;s:Button label="Stop and Send" click="stop(event)"/&gt; &lt;/s:HGroup&gt; &lt;/s:Application&gt; </code></pre> <p>For more info check this links: <a href="http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/" rel="nofollow noreferrer">http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/</a> and <a href="https://stackoverflow.com/questions/4361826/does-chrome-have-buil-in-speech-recognition-for-input-type-text-x-webkit-speec">Does Chrome have built-in speech recognition for &quot;x-webkit-speech&quot; input elements?</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload