I am trying to send a post-request to the stt v2 rest API with node js but I keep on getting Error: HTTP error! status: 404 I am using one of the service endpoints provided on the stt rest documentation. What am I doing wrong?
const fs = require('fs');
const fetch = require('node-fetch');
const apiKey = 'my_api_key';
const projectId = 'my_project_idr';
const location = 'us-central1';
const model = 'chirp';
const audioFilePath = 'audios/my_audio.mp3';
const audioContent = fs.readFileSync(audioFilePath).toString('base64');
const requestBody = {
config: {
language_codes: ["en-US"],
model: "chirp",
features: {
"enableWordTimeOffsets": true,
"enableWordConfidence": true
},
},
content: audioContent
};
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(requestBody),
};
fetch(`https://us-central1-speech.googleapis.com/v2/recognizer=projects/${projectId}/locations/${location}/recognizers/_`, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error.message);
});
Hi @piratebay,
Thank you for joining our community.
I understand you're frustrated by the 404 error you're encountering with the Speech-to-Text v2 API. It can be confusing when things aren't working as expected. The 404 error usually means the API can't find the specific web address (endpoint URL) you're trying to use. Make sure it matches exactly with what's listed in the Speech-to-Text v2 REST documentation for the type of recognition you're trying to do (batch or streaming).
Here's a couple of resources that you can use as reference
I hope I was able to provide you with useful insights.