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: [] } ]