Google Cloud SpeechtoText API无限等待

2024-05-05 02:12:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Google云语音来编写API文本。在

我将mp3音频文件格式转换为.raw格式,并上传到bucket存储。在

这是我的代码:

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")

我做错什么了?在


Tags: thefromimportcloudfor格式googleuri
1条回答
网友
1楼 · 发布于 2024-05-05 02:12:18

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

我最近处理了一个56分钟的音频,花了17分钟,所以你应该知道它应该有多长。在

使用sox处理你的文件,我找到了使用命令-

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

相关问题 更多 >