0

I am using below Node.js script snippet,

'use strict';
var google_speech = require('google-speech');
google_speech.ASR({
    debug: true,
    lang: 'en_US',
    developer_key: '<Google API Key>',
    file: '<voice file name with path>',
  }, function(err, httpResponse, xml){   
    if(err){
        console.log(err);
      }else{
        console.log(httpResponse.statusCode, xml)
      }
    }
);

The output I am getting from some audio files but not for all. Even for example one flac file is giving output but another flac file doesn't.

Is there any specific type of files are required for this API to give output. If yes, then let me know the specific type/format of the file.

1 Answers1

0

If you're using this google-speech Node library, it appears that it's hardcoded the content-type header to audio/l16; rate=16000 here in the source code.

It looks like this can be overridden as an option in your first param, so, for example, if you're using a 44.1khz flac file, the following might work

'use strict';
var google_speech = require('google-speech');
google_speech.ASR({
    debug: true,
    lang: 'en_US',
    developer_key: '<Google API Key>',
    file: '<voice file name with path>',
    'content-type': 'audio/x-flac; rate=44100' // ← override it here
  }, function(err, httpResponse, xml){   
    if(err){
        console.log(err);
      }else{
        console.log(httpResponse.statusCode, xml)
      }
    }
);

That being said (and this wasn't what you asked), it does appear that Google's recently updated their official Cloud Speech API, which you may also find useful. They've got a nodejs tutorial here, and more extensive details about the file formats supported here.

Sydin
  • 607
  • 5
  • 14