Google云语音API:如何获取1分钟以上音频的全文转录?

Google Cloud Speech API: how to get the full text transcription of audios longer than 1 minute?

我使用 Google Cloud Speech API (longrunningrecognize) 成功获得了一段 5 分钟长的音频的抄本和备选方案,但我没有得到这 5 分钟的全文,只是一个小成绩单,如下所示:

{
  "name": "2340863807845687922",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeMetadata",
    "progressPercent": 100,
    "startTime": "2018-09-20T13:25:57.948053Z",
    "lastUpdateTime": "2018-09-20T13:28:18.406147Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeResponse",
    "results": [
      {
        "alternatives": [
          {
            "transcript": "I am recording it. I think",
            "confidence": 0.9223639
          }
        ]
      },
      {
        "alternatives": [
          {
            "transcript": "these techniques properly stated",
            "confidence": 0.9190353
          }
        ]
      }
    ]
  }
}

如何获取转录生成的全文?

Google 语音 API 是一件非常痛苦的事情。除了无法翻译长文件外,他们还会随机跳过转录中的大段音频。可能的解决方案是:

  1. 使用语音 activity 检测和 分别转录每个块
  2. 使用更合理的服务,如 Speechmatics,他们将毫无问题地处理大文件,而且准确性更高
  3. 使用像 Kaldi 这样的开源语音识别器。

我成功解决了这个问题。我必须使用 ffmpeg:

正确转换文件
$ ffmpeg -i /home/user/audio_test.wav -ac 1 -ab 8k audio_test2.wav

*** 移除静音:

sox audio_test2.wav audio_no_silence4.wav silence -l 1 0.1 1% -1 2.0 1%

并修复我的同步-request.json:

{"config": {
      "encoding":"MULAW",
      "sampleRateHertz": 8000,
      "languageCode": "pt-BR",
      "enableWordTimeOffsets": false,
    "enableAutomaticPunctuation": false,
 "enableSpeakerDiarization": true,
    "useEnhanced": true,
`enter code here`"diarizationSpeakerCount":2,
 "audioChannelCount": 1},
  "audio": {
      "uri":"gs://storage/audio_no_silence4.wav"
  }
}

然后是 运行 curl。它现在运行良好。

Google Cloud Speech-to-Text 提供了非常准确的结果。对于一些长音频,它会提供分成块的转录本作为您观察到的一系列替代方案。我所做的是在我的识别配置中设置 MaxAlternatives = 1,然后连接备选方案数组以获得完整的成绩单。我在 c# 中使用 Google.Cloud.Speech.V1 的识别配置如下

var config = new RecognitionConfig()


{
    Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
    //SampleRateHertz = 16000,
    LanguageCode = "en",
    EnableWordTimeOffsets = true,
    MaxAlternatives = 1
 };