Bor*_*aev 3 python api speech-recognition speech-to-text google-cloud-platform
我正在尝试转录一个德语播客,我的电脑和 Google 存储桶上都有该播客。我使用本教程作为参考。
这是我的代码:
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
Run Code Online (Sandbox Code Playgroud)
但它停在该operation行,输出TypeError: long_running_recognize() takes from 1 to 2 positional arguments but 3 were given. 该教程是一年前的,所以自那以后 API 中一定发生了一些变化。我不确定要修改什么。
看起来您正在使用旧的库版本。
从Google 异步识别示例来看,这两个选项似乎是等效的:
operation = client.long_running_recognize(
request={"config": config, "audio": audio}
)
Run Code Online (Sandbox Code Playgroud)
或者
operation = client.long_running_recognize(config=config, audio=audio)
Run Code Online (Sandbox Code Playgroud)
顺便说一句 - 也可以看看官方的Google Codelab for Speech to text - 他们总是有最新的示例。