Google Cloud Speech-to-Text API 的问题

Problems with Google Cloud Speech-to-Text API

我正在尝试转录德语播客,我的电脑和 Google 存储桶上都有。我使用 this tutorial 作为参考。

这是我的代码:

frame_rate, channels = frame_rate_channel('pod.wav')
gcs_uri = 'gs://callsaudiofiles21/pod.wav'

client = speech.SpeechClient()
audio = types.RecognitionAudio(uri=gcs_uri)

config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=frame_rate,
language_code='de-DE')

transcript = ''

operation = client.long_running_recognize(config, audio)
response = operation.result(timeout=10000)

for result in response.results:
    transcript += result.alternatives[0].transcript

但是它停在了operation行,输出了TypeError: long_running_recognize() takes from 1 to 2 positional arguments but 3 were given。该教程是一年前的,因此 API 之后一定发生了一些变化。不过我不确定要修改什么。

你试过这个吗:

operation = client.long_running_recognize(
        request={"config": config, "audio": audio}
    )

看起来您使用的是旧版本的库。

来自Google async recognizion example,这两个选项似乎是等价的:

    operation = client.long_running_recognize(
        request={"config": config, "audio": audio}
    )

    operation = client.long_running_recognize(config=config, audio=audio)

顺便说一句 - 也看看官方 Google Codelab for Speech to text - 他们总是有 up-to-date 个例子。