我正在尝试使用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))
答案 0 :(得分:0)
某些python版本在语法上可能比其他版本更严格。只需这样更改即可:
results = sample.streaming_recognize(
config=speech.types.StreamingRecognitionConfig(config=config),
requests=requests)
它将起作用。