0

I want to generate text for .mp3 file and using google-cloud/speech module to do this in my nodejs application. My code is running fine and not producing any error, my mp3 file is also ok ( I have tested with multiple .mp3 files ). But is gives the response with empty array every times.

This is not a duplicate question of Google Speech Recognition API Result is Empty , The problem may looks like same but its different because google do changes in there API.

Can anyone please suggest me why is is happening ?

My code is:

// Imports the Google Cloud client library
const Speech = require('@google-cloud/speech');
process.env.GOOGLE_APPLICATION_CREDENTIALS = './speech-368abcdefghi.json'  

// Your Google Cloud Platform project ID
const projectId = 'engaged-talon-123456';

// Instantiates a client
const speechClient = Speech({
  projectId: projectId
});

// The name of the audio file to transcribe
const fileName = './5sec.mp3';

// The audio file's encoding, sample rate in hertz, and BCP-47 language code
const options = {
  encoding: 'LINEAR16',
  sampleRateHertz: 16000,
  languageCode: 'en-US'
};

// Detects speech in the audio file
speechClient.recognize(fileName, options)
  .then((results) => {
    console.log(results);
    // const transcription = results[0];
    // console.log(`Transcription: ${transcription}`);
  })
  .catch((err) => {
    console.error('ERROR:', err);
  });

Result:

[ '', { results: [] } ]

Shubham Verma
  • 8,783
  • 6
  • 58
  • 79
  • 1
    Mp3 is not LINEAR16 – Nikolay Shmyrev Jul 14 '17 at 06:39
  • Possible duplicate of [Google Speech Recognition API Result is Empty](https://stackoverflow.com/questions/38906527/google-speech-recognition-api-result-is-empty) – Nikolay Shmyrev Jul 14 '17 at 06:39
  • https://cloud.google.com/speech/docs/best-practices "Using mp3, m4a, mu-law, a-law or other lossy codecs during recording or transmission may reduce accuracy. If your audio is already in **an encoding not supported by the API**" – l2aelba Jul 14 '17 at 09:54

0 Answers0