How to use StreamingRecognize for more than 1 minute?

不羁岁月 提交于 2019-12-11 05:17:43

问题


I am quite new to using Google speech API. My application requiers me to contiouously stream audio requsts for speech recognition. the usage will be more than 1 minute continuously. However, the service halts after 60 seconds as per the Usage Limits. Is there a way around this issue?

Any help is greatly appreciated.

Thanks


回答1:


Buried deep in the Google cloud console is a link to a form where you can request increase in some of the limits. However, if possible, use the Async recognition which will give you up to 80 minutes of recognition.

To get to the limit increase form:

  1. Go to the API manager in the console
  2. Click on Google Cloud Speech API
  3. Click the "Quotas" tab
  4. Scroll down to any of the adjustable quotas, such as Discovery requests per 100 seconds
  5. Click on the "edit" icon to the right of that.
  6. In that pop-up there should be a link titled "apply for higher quota."



回答2:


I solved this problem in a Node.js app by creating a series of streaming recognition requests.

The code is here: https://github.com/marciovm/Speech-Forever.

The trick is to request new streams client side (from the user's browser or equivalent) on a suitable break in input speech.

Key section on app.js (Node server)

var gstreams = []; // keeep track of speech streams
  var activeStreamID = -1; // pointer to active speech stream
  ws.on('message', function (data) {         
    if ( typeof data == 'string' ) { 
      if (data.indexOf("info")>0) { // client sends an info string on connection that triggers server to start a speech stream             
        console.log('Start first stream');
        gstreams.push(startGoogleSpeechStream(ws));
        activeStreamID = activeStreamID + 1;           
      }
      else { // client requested a new speech stream (client-side logic allows for triggering on a lull in input volume)
        console.log('Start another stream');
        gstreams[activeStreamID].end();
        gstreams.push(startGoogleSpeechStream(ws));
        activeStreamID = activeStreamID + 1;                              
      }    
    }    
    else  { 
      gstreams[activeStreamID].write(data); // client sent audio, push it to active speech stream 
    }        
  });  

Key section on demo.js (client browser)

var handleSuccess = function(stream) {
    setRecordingTrue(1000); // give socket 1 sec to open
    audioInput = context.createMediaStreamSource(stream);   
    audioInput.connect(recorder);            
    recorder.onaudioprocess = function(stream){
      if(!recording) return;
      var buf = stream.inputBuffer.getChannelData(0);             
      volume = detectVolume(buf, this);               
      $(".volume_meter")[0].value=volume * 100;      
      if (volume < 0.01 && (Date.now() > (streamStartTime + breakTime))) {    
        ws.send("restarting Google Stream");  
        console.log("restarting Google Stream");
        streamStartTime = Date.now();
        writeToCaret(' ');
      }   
      else {
        ws.send(float32ToInt16(buf)); // send audio stream to Node server   
      }     
    }    
  }  


来源:https://stackoverflow.com/questions/40200220/how-to-use-streamingrecognize-for-more-than-1-minute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!