import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
print("Recognizing...")
text = r.recognize_google(audio)
print("You said:", text)
except sr.UnknownValueError:
print("Sorry, I could not understand your speech.")
except sr.RequestError as e:
print("Sorry, an error occurred. {0}".format(e))
1条答案
按热度按时间dgsult0t1#
如果您尝试做的只是语音到文本,那么这个简单的代码应该可以工作,首先运行
pip install SpeechRecognition
,然后这个代码应该可以工作