SyntaxError:位置参数紧跟关键字参数|用于语音转文字的Python客户端

时间:2019-04-10 12:58:09

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

我正在尝试使用Google Cloud API将音频转换为文本。我正在关注他们的官方文件,但它使我一直出错

File "heyfinal.py", line 15
    ,requests,
    ^
SyntaxError: positional argument follows keyword argument

文档链接为:https://www.ruyadaruya.com/hareketler

import io
from google.cloud import speech
client = speech.SpeechClient()
config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    language_code='en-US',
    sample_rate_hertz=44100,
)
with io.open('./rehan.wav', 'rb') as stream:
    requests = [speech.types.StreamingRecognizeRequest(
        audio_content=stream.read(),
    )]
results = sample.streaming_recognize(
    config=speech.types.StreamingRecognitionConfig(config=config)
    ,requests,
    )
for result in results:
    for alternative in result.alternatives:
        print('=' * 20)
        print('transcript: ' + alternative.transcript)
        print('confidence: ' + str(alternative.confidence))

1 个答案:

答案 0 :(得分:0)

某些python版本在语法上可能比其他版本更严格。只需这样更改即可:

results = sample.streaming_recognize(
    config=speech.types.StreamingRecognitionConfig(config=config),
    requests=requests)

它将起作用。