I'd like to recognize an audio file in a NodeJS server.
I'm using the command line on Windows 10, and the Node's version is 10.6.0, I've installed @google-cloud/speech regulary with npm. Morest I've declared the environment variable for credentials (explained here https://cloud.google.com/docs/authentication/getting-started?hl=en), and I've copyed the json file in the "credential" folder :
set GOOGLE_APPLICATION_CREDENTIALS="C:\Users\Me\Documents\NodeJs\Project1\credentials\RDCommandeVocale-b521de3b57d9.json"
The file was encoded via ffmpeg with this command :
ffmpeg -i newRecording.aac -vol 512 -c flac -ar 16000 newRecording.flac
My source code is :
const folderName = "uploaded";
const fileName = "newRecording";
const client = new speech.SpeechClient();
const config = {
encoding:"FLAC",
sampleRateHertz: 16000,
languageCode: "fr-FR"
};
const audioBytes = fs.readFileSync(`${__dirname}\\` + folderName + "\\" + fileName + ".flac").toString('base64');
//This doesn't work else with this :
//const audioBytes = fs.readFileSync(".\\uploaded" + fileName + ".flac").toString('base64');
// ... nor this one
//const audioBytes = fs.readFileSync("./uploaded" + fileName + ".flac").toString('base64');
const request = {
config: config,
audio: audioBytes,
};
client.recognize(request).then( response=>{
const transcription = response.results
.map(result => result.alternatives[0].transcript)// récupérer uniquement la première alternative
.join('\n');
console.log("Textual transcription: ", transcription );
res.status(200)
.json({ status: "success", message: transcription });
},
(err)=>{
console.log("Transcription ERROR : ", JSON.stringify(err));
res.status(500)
.json({ status: "error", message: JSON.stringify(err) });
});
I get this error :
Textual transcription : {"errno":-4058,"syscall":"lstat","code":"ENOENT","path":"c:\Users\Me\Documents\Me\NodeJs\Project1\\"C:"}
Does this error type is referenced anywhere in Google Cloud API docs ?