长文件转录两次(运行两个操作) - bug

问题描述 投票:0回答:1

似乎任何长音频(> 4分钟)以某种方式使API产生两个操作而不是一个。无论我一直在做什么(使用事件发射器模式或承诺),它总是那样。

结果我的数据库有两个转录而不是一个(我甚至不明白它是如何记住当第二个文本到达后端时猫鼬模型中断)

请帮助我解决这个问题,我现在大约两个月就遇到了这个问题。

Environment details
  • 操作系统:MacOS 10.14.4(18E226)
  • Node.js版本:11.2.0
  • npm版本:
  • @google-cloud/speech版本:2.3.0
Steps to reproduce

运行代码:

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: '' });
javascript google-speech-api apollo-server
1个回答
0
投票

问题出在我的Apollo Server上。不知何故,它迫使API进行两次操作(可能是与超时相关的事情)。我尝试过纯粹的Node示例,一切都没问题。

© www.soinside.com 2019 - 2024. All rights reserved.