【问题标题】:Google Cloud Speech-to-Text API - Waiting infinitelyGoogle Cloud Speech-to-Text API - 无限等待
【发布时间】:2018-05-26 18:18:07
【问题描述】:

我正在尝试使用 Google Cloud Speech-to-Text API。

根据 API 文档的理解,我将 mp3 音频文件格式转换为 .raw,然后上传到存储桶。

这是我的代码:

def transcribe_gcs(gcs_uri):
    """Asynchronously transcribes the audio file specified by the gcs_uri."""
    from google.cloud import speech
    from google.cloud.speech import enums
    from google.cloud.speech import types
    client = speech.SpeechClient()

    audio = types.RecognitionAudio(uri=gcs_uri)
    config = types.RecognitionConfig(
        encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
        sample_rate_hertz=16000,
        language_code='en-US')

    operation = client.long_running_recognize(config, audio)

    print('Waiting for operation to complete...')
    response = operation.result()

    # Each result is for a consecutive portion of the audio. Iterate through
    # them to get the transcripts for the entire audio file.
    for result in response.results:
        # The first alternative is the most likely one for this portion.
        print(u'Transcript: {}'.format(result.alternatives[0].transcript))
        print('Confidence: {}'.format(result.alternatives[0].confidence))

transcribe_gcs("gs://cloudh3-200314.appspot.com/cs.raw")

我做错了什么?

【问题讨论】:

  • 那么错误信息是什么?
  • 只是等待永远不会结束的问题。
  • 您能否尝试直接使用API 对同一个文件执行相同的操作,然后检查操作如何运行here。绕过库将阐明实际问题所在。

标签: python google-app-engine google-cloud-platform google-speech-api


【解决方案1】:

我遇到了类似的问题,这与可接受的格式有关。即使您可能已经转换为 RAW,但格式仍然可能有问题,如果无法读取文件,它不会给您输出。

我最近处理了一个 56 分钟的音频,花了 17 分钟,因此您应该知道它应该多长时间。

使用 sox 处理你的文件,我找到了使用命令工作的转换参数 -

sox basefile.mp3 -r 16000 -c 1 newfile.flac

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多