use*_*317 8 python speech-recognition google-api
我有一个项目,我在客户端和主机之间创建了一个聊天程序,我必须在其中嵌入Speech to Text.我有什么办法可以在我的程序中嵌入Google Speech to Text API吗?
PyPI中有一个名为语音识别的软件包看起来会像这样做.实时(即通过麦克风)API看起来非常简单.
# NOTE: this requires PyAudio because it uses the Microphone class
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source: # use the default microphone as the audio source
audio = r.listen(source) # listen for the first phrase and extract it into audio data
try:
print("You said " + r.recognize(audio)) # recognize speech using Google Speech Recognition
except LookupError: # speech is unintelligible
print("Could not understand audio")
Run Code Online (Sandbox Code Playgroud)
它还具有转录WAV文件的功能,作为后台进程运行,为转录提供置信度等.