Google Cloud Speech in Node.JS: config speech_context

I am using the Node.JS Google Speech API option.

Everything works well and dandy until I dare to pass an array of parameters speech_context. When I try to use each of the following methods, the stream is interrupted, but there is no error . So I have nothing to diagnose.

I am passing an array of strings ["one", "two", "three"], following the documentation , so I count. My initial configuration is as follows:

const cf = {
    config: {
        encoding: 'LINEAR16',
        sampleRate: 48000
    }
}

I tried to cf.config.speech_context = ARRAY, cf.config.speech_context.phrases = ARRAY, cf.speech_context = ARRAYand cf.speech_context.phrases = ARRAY.

Again, I am not getting the error message and not getting the result. I get nothing. The original configuration by itself works .

This is with the base stream:

recognizeStream = speech.createRecognizeStream(cf)
    .on('error', console.error)
    .on('data', console.log)

? !

+4
1
    const request = {
    config: {
      encoding: encoding,
      sampleRate: sampleRate,
      languageCode:'en-IN-x-longform',
    }
  };

  // Stream the audio to the Google Cloud Speech API

  const recognizeStream = speech.createRecognizeStream(request)
    .on('error', (error) => {
         console.error;
     })
    .on('data', (data) => {
      console.log('Data received: %j', data);
      if('results' in data)
        console.log(chalk.bgYellow( data.results ));
      logger.log(JSON.stringify(data));
    });



  // Stream an audio file from disk to the Speech API, e.g.    "./resources/audio.raw"

   filename = "./resources/audio.raw";
   fs.createReadStream(filename).pipe(recognizeStream);



 //This is working for me
 //I think you are missing the pipe part in , so you can do

 recognizeStream = speech.createRecognizeStream(cf)
      .on('error', console.error)
      .on('data', console.log)

   filename = "./resources/audio.raw";
   fs.createReadStream(filename).pipe(recognizeStream);

`
0

Source: https://habr.com/ru/post/1669009/


All Articles