2011-09-01 2 views
0

사람들은 Google Speech API (Speech-To-Text) 사용법을 알고 있습니다. 나는 Flash Speex 코덱과 함께 작동 시키려고 노력하고 있으며, 단지 그것을 이해할 수 없다. 각 160 바이트 (일부 원본 말한 것처럼) 전에 프레임 크기 바이트 삽입 시도했지만이 작동하지 않습니다.Google Speech API 용 Flash SPEEX 코덱 변환 - 챌린지

Google Speech API가 이해할 수 있도록 Flash Speex 바이트를 어떻게 든 번역합니다. 여기

기본 플렉스 코드 :이 링크를 확인 더 많은 정보

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      creationComplete="init();"> 
<fx:Script> 
    <![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 & 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 < 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(); 
      } 
     }  
    ]]> 
</fx:Script> 

<s:HGroup> 
    <s:Button label="Record" 
       click="record(event)"/> 
    <s:Button label="Stop and Send" 
       click="stop(event)"/> 
</s:HGroup> 
</s:Application> 

: http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/Does Chrome have built-in speech recognition for "x-webkit-speech" input elements?

답변

0

당신이 찾고있는 코드 차례로 인클루드에서 라인 100-160 주위에 http://src.chromium.org/viewvc/chrome/trunk/src/content/browser/speech/speech_recognizer.cc?view=diff&r1=79556&r2=79557에있다 .../viewvc/chrome/trunk/deps/third_party/speex/

그러나 Chrome은 3 월 말에 Speex에서 FLAC으로 전환하여 변경 로그에 실제 설명이 없습니다. http://src.chromium.org/viewvc/chrome/trunk/src/content/browser/speech/speech_recognizer.cc?view=diff&r1=79556&r2=79557 - 그래서 나는 Speex를 사용하는 것을 권하지 않는다. 반면에, 누군가는 안드로이드 소스를보고 Speex를 여전히 사용하고 있다고 말했기 때문에 그것을 유지할 것입니다 (초당 5 바이트 미만입니다).