How to use StreamingRecognize for more than 1 minu

2019-07-28 06:09发布

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

2条回答
Melony?
2楼-- · 2019-07-28 06:53

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   
      }     
    }    
  }  
查看更多
不美不萌又怎样
3楼-- · 2019-07-28 07:09

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."
查看更多
登录 后发表回答