我不能使用speech_recognition

时间:2018-01-10 13:08:04

标签: python-3.x

您好我已经从网站上复制了关于python的代码,用于将我的语音转换为文本,但它有一个我无法理解或修复的错误。你能不能教我一些理由。

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:                
r.adjust_for_ambient_noise(source)
while True:
 print("said")
 audio = r.listen(source)
 try:
  print("You said " + r.recognize_google(audio))  
 except LookupError:                           
  print("i do not understand audio")

enter image description here

1 个答案:

答案 0 :(得分:0)

使用此代码。它在pycharm中对我有用

import speech_recognition as sr
r = sr.Recognizer()

with sr.Microphone() as source:
    print("speak into mic")
    audio = r.listen(source,timeout=2)


try:
    print("Transcription:" + r.recognize_google(audio))
except sr.UnknownValueError:
    print("Audio Unintelligible")

except sr.RequestError as e:
    print("cannot obtain results : {0}".format(e))

`