Я хочу вводить текст речи с помощью Google Cloud Speech API, но не могу этого сделать, так как возникает ошибка. Что мне делать или есть ли другое решение для преобразования речи в текст в узле js. Поскольку я хочу взять текст из речи, а затем разбить его на несколько слов, чтобы они соответствовали им из моей библиотеки, хранящейся в iMongoDBdb.
Мой текущий код таков:
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');
const fs = require('fs');
// Your Google Cloud Platform project ID
const projectId = 'MY-PROJECT-ID';
// Creates a client
const client = new speech.SpeechClient({
projectId: projectId,
});
// The name of the audio file to transcribe
const fileName = 'C:/Projects/audio/public/1.mp3';
// Reads a local audio file and converts it to base64
const file = fs.readFileSync(fileName);
const audioBytes = file.toString('base64');
// The audio file's encoding, sample rate in hertz, and BCP-47 language code
const audio = {
content: audioBytes,
};
const config = {
encoding: 'LINEAR16',
sampleRateHertz: 16000,
languageCode: 'en-US',
};
const request = {
audio: audio,
config: config,
};
// Detects speech in the audio file
client
.recognize(request)
.then(data => {
const response = data[0];
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n');
console.log(`Transcription: ${transcription}`);
})
.catch(err => {
console.error('ERROR:', err);
});
и эта ошибка приходит:
$ node speech.js
ERROR: Error: Unexpected error while acquiring application default credentials:
Could not load the default credentials. Browse to https://developers.google.com/
accounts/docs/application-default-credentials for more information.
at GoogleAuth.<anonymous> (C:\Projects\audio\node_modules\google-auth-librar
y\build\src\auth\googleauth.js:249:31)
at step (C:\Projects\audio\node_modules\google-auth-library\build\src\auth\g
oogleauth.js:47:23)
at Object.next (C:\Projects\audio\node_modules\google-auth-library\build\src
\auth\googleauth.js:28:53)
at fulfilled (C:\Projects\audio\node_modules\google-auth-library\build\src\a
uth\googleauth.js:19:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:3112) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 3): Error: Unexpected error while acquiring application default credent
ials: Could not load the default credentials. Browse to https://developers.googl
e.com/accounts/docs/application-default-credentials for more information.
(node:3112) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.