【发布时间】:2017-04-18 03:27:29
【问题描述】:
我正在处理 Google Speech API found here 提供的代码 sn-ps。该代码应该足以将 .wav 文件转换为转录文本。
感兴趣的块在这里:
def transcribe_file(speech_file):
"""Transcribe the given audio file."""
from google.cloud import speech
speech_client = speech.Client()
with io.open(speech_file, 'rb') as audio_file:
content = audio_file.read()
audio_sample = speech_client.sample(
content=content,
source_uri=None,
encoding='LINEAR16',
sample_rate_hertz=16000)
alternatives = audio_sample.recognize('en-US')
for alternative in alternatives:
print('Transcript: {}'.format(alternative.transcript))
首先,我认为代码可能是旧的,sample_rate_hertz=16000 必须更改为 sample_rate=16000。
之后,我收到此行的错误:alternatives = audio_sample.recognize('en-US')
内容为AttributeError: 'Sample' object has no attribute 'recognize'
我很好奇如何纠正这个问题。我似乎找不到有关此方法的任何文档。也许它也需要更换。
【问题讨论】:
-
请看here,因为有类似的工作示例