Google 云语音转文本长音频响应
Google cloud speech to text long audio response
我正在尝试将音频转换为文本,但得到的结果是,
LongRunningRecognizeResponse { results: [] }
这是我的函数,
const audio = {
uri: `gs://${BUCKET}/${fileName}`,
};
const request = {
config: {
encoding: 'LINEAR16',
sampleRateHertz: 16000,
languageCode: 'en-US',
},
audio: audio,
};
client.longRunningRecognize(request)
.then(responses => {
const [operation, initialApiResponse] = responses;
operation.on('complete', (result, metadata, finalApiResponse) => {
console.log('complete', result) // LongRunningRecognizeResponse { results: [] }
});
operation.on('progress', (metadata, apiResponse) => {
console.log('progress', apiResponse)
});
operation.on('error', err => {
throw (err);
});
})
const transcribeLong = async (url, channels) => {
const nameExtract = url.split('/');
const fileName = nameExtract[nameExtract.length - 1];
let localfile;
try {
localfile = await download(url);
fs.writeFileSync(fileName, localfile);
await storage.bucket(BUCKET).upload(fileName);
const audio = {
uri: `gs://${BUCKET}/${fileName}`,
};
const request = {
config: {
languageCode: `en-US`,
alternativeLanguageCodes: [`es-MX`, `en-US`],
encoding: 'LINEAR16',
sampleRateHertz: 8000,
audioChannelCount: channels || 2, //changed from 2
enableSeparateRecognitionPerChannel: true,
},
audio,
};
const [operation] = await client.longRunningRecognize(request);
const [response] = await operation.promise();
return response
} catch (error) {
console.error(error.toString());
}
};
问题是错误的渠道作为请求中的参数。
我正在尝试将音频转换为文本,但得到的结果是,
LongRunningRecognizeResponse { results: [] }
这是我的函数,
const audio = {
uri: `gs://${BUCKET}/${fileName}`,
};
const request = {
config: {
encoding: 'LINEAR16',
sampleRateHertz: 16000,
languageCode: 'en-US',
},
audio: audio,
};
client.longRunningRecognize(request)
.then(responses => {
const [operation, initialApiResponse] = responses;
operation.on('complete', (result, metadata, finalApiResponse) => {
console.log('complete', result) // LongRunningRecognizeResponse { results: [] }
});
operation.on('progress', (metadata, apiResponse) => {
console.log('progress', apiResponse)
});
operation.on('error', err => {
throw (err);
});
})
const transcribeLong = async (url, channels) => {
const nameExtract = url.split('/');
const fileName = nameExtract[nameExtract.length - 1];
let localfile;
try {
localfile = await download(url);
fs.writeFileSync(fileName, localfile);
await storage.bucket(BUCKET).upload(fileName);
const audio = {
uri: `gs://${BUCKET}/${fileName}`,
};
const request = {
config: {
languageCode: `en-US`,
alternativeLanguageCodes: [`es-MX`, `en-US`],
encoding: 'LINEAR16',
sampleRateHertz: 8000,
audioChannelCount: channels || 2, //changed from 2
enableSeparateRecognitionPerChannel: true,
},
audio,
};
const [operation] = await client.longRunningRecognize(request);
const [response] = await operation.promise();
return response
} catch (error) {
console.error(error.toString());
}
};
问题是错误的渠道作为请求中的参数。