Google语音转文本:协议消息RecognitionConfig没有“ uri”字段

时间:2019-02-05 12:35:07

标签: url google-api speech-recognition speech-to-text

我一直试图将一个60m的音频文件转录为文本,但是在使用gs url时遇到了麻烦。 错误消息显示协议消息RecognitionConfig没有“ uri”字段 我尝试了几种将gs uri放在此处的方法,但似乎没有用。

from google.cloud import speech_v1p1beta1 as speech
import os
import io

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./SpeechToText-32140aeda073.json"

client = speech.SpeechClient()

encoding = speech.enums.RecognitionConfig.AudioEncoding.AMR

audio_source = speech.types.RecAognitionConfig(uri=gsc_uri)
gsc_uri = 'gs://interview_uio/Han.wav'

with io.open(audio_source, 'rb') as audio_file:
    content = audio_file.read()

config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.AMR,
    sample_rate_hertz=8000,
    language_code='en-US',
    audio_channel_count=1,
    enable_automatic_punctuation=True)
uri = 'gs://interview_uio/Han.wav'
audio = {'uri': uri}

operation = client.long_running_recognize(config, audio)

print('Waiting for operation to complete...')
response = operation.result(timeout=90)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print('-' * 20)
    print('First alternative of result {}'.format(i))
    print('Transcript: {}'.format(alternative.transcript))

0 个答案:

没有答案