SyntaxError: позиционный аргумент следует за ключевым аргументом |Python клиент для речи в текст - PullRequest
2 голосов
/ 10 апреля 2019

Я пытаюсь преобразовать звук в текст с помощью облачного API Google. Я следую их официальному документу, но он заставляет меня выдавать ошибку

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

Ссылка на документацию: https://googleapis.github.io/google-cloud-python/latest/speech/index.html#streaming-recognition

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 голосов
/ 10 апреля 2019

Некоторые версии Python могут быть более строгими в отношении синтаксиса, чем другие.Просто измените его следующим образом:

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

, и оно будет работать.

...