似乎任何长音频(> 4分钟)以某种方式使API产生两个操作而不是一个。无论我一直在做什么(使用事件发射器模式或承诺),它总是那样。
结果我的数据库有两个转录而不是一个(我甚至不明白它是如何记住当第二个文本到达后端时猫鼬模型中断)
请帮助我解决这个问题,我现在大约两个月就遇到了这个问题。
Environment details@google-cloud/speech
版本:2.3.0运行代码:
async function transcribe(gcsuri, progressCB) {
const reducerforSingleAlternative = (obj, item, index, array) => {
item.alternatives[0].words.map(word => obj.words.push(word));
obj.confidence += item.alternatives[0].confidence;
obj.transcript += item.alternatives[0].transcript;
if (index === (array.length - 1)) {
obj.confidence /= array.length;
}
return obj;
};
process.env.GOOGLE_APPLICATION_CREDENTIALS = process.env.SPEECH_KEY;
const speech = require('@google-cloud/speech').v1p1beta1;
const client = new speech.SpeechClient();
const audio = {
uri: gcsuri,
};
const request = {
audio,
config: {
encoding: 'OGG_OPUS',
sampleRateHertz: 24000,
languageCode: 'ru',
enableSpeakerDiarization: true,
enableWordConfidence: true,
maxAlternatives: 1,
enableWordTimeOffsets: true,
},
};
const [operation] = await client.longRunningRecognize(request);
operation.on('progress', (metadata, apiResponse) => {
console.log('metadata', apiResponse);
progressCB(metadata.progressPercent);
});
const [results] = await operation.promise();
console.log('promise', typeof results, results);
return results.results.reduce(reducerforSingleAlternative, { words: [], confidence: 0, transcript: '' });
问题出在我的Apollo Server上。不知何故,它迫使API进行两次操作(可能是与超时相关的事情)。我尝试过纯粹的Node示例,一切都没问题。