2
votes

I am trying to convert audio into text using google cloud API. I am following their official documentaion but it keeps me giving an error

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

The link to documentation is: 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

1 Answers

0
votes

Some python versions might be more strict about syntax than others. Simply change it like this:

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

and it will work.