Google Cloud语音到文本API的问题

时间:2020-11-04 09:44:57

标签: python api google-cloud-platform speech-recognition speech-to-text

我正在尝试转录自己的PC和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必须有所更改。我不确定该怎么修改。

2 个答案:

答案 0 :(得分:2)

好像您使用的是旧库版本。

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-他们总是有最新的例子。

答案 1 :(得分:1)

您尝试过吗:

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