【发布时间】:2025-01-12 15:35:02
【问题描述】:
我正在使用 Google Cloud Speech API。我想知道我是否使用 python 语音识别库并调用谷歌云语音 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 SpeechRecognition:
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/*lyn_bridge.flac'}
【问题讨论】:
标签: python google-cloud-platform speech-recognition google-cloud-speech