我正在玩谷歌云语音API。我想知道如果我使用python语音识别库并调用google cloud语音API,这仍然是使用API的有效方法吗?我只想抄写这篇课文
我对它们之间的区别感到困惑,如果我只想转录音频,是否有任何建议方法
使用Python语音识别:
import speech_recognition as sr
r = sr.Recognizer()
r.recognize_google_cloud()
harvard = sr.AudioFile('harvard.wav')
with harvard as source:
audio = r.record(source)
r.recognize_google(audio)
不使用Python语音识别:
from google.cloud import speech_v1 as speech
def speech_to_text(config, audio):
client = speech.SpeechClient()
response = client.recognize(config, audio)
print_sentences(response)
def print_sentences(response):
for result in response.results:
best_alternative = result.alternatives[0]
transcript = best_alternative.transcript
confidence = best_alternative.confidence
print('-' * 80)
print(f'Transcript: {transcript}')
print(f'Confidence: {confidence:.0%}')
config = {'language_code': 'en-US'}
audio = {'uri': 'gs://cloud-samples-data/speech/brooklyn_bridge.flac'}
Google Cloud Client Libraries是以编程方式访问云API的推荐选项:
另外,请注意best practices,以便从API获得更好的结果
若你们只打算使用谷歌云平台进行语音识别,那个么SpeechClient会更好,因为它是由谷歌维护的
如果你想尝试不同的语音识别服务,语音识别会有所帮助,因为它更通用
任何调用api的方法都可以。图书馆只是为了让你更容易
相关问题 更多 >
编程相关推荐