使用以下代码进行语音识别根本不起作用
with sr.Microphone() as source:
# read the audio data from the default microphone
audio = r.record(source, duration=4)
print("Recognizing...")
# convert speech to text
# recognize speech using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("Google Speech Recognition thinks you said in English: - " + r.recognize_google(audio, language = "en-US"))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio") …
Run Code Online (Sandbox Code Playgroud)