【问题标题】:AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW'AttributeError:“模块”对象没有属性“STARTF_USESHOWWINDOW”
【发布时间】:2018-01-06 14:12:59
【问题描述】:

说点什么!

Traceback (most recent call last):<br/>
  File "speechrecognition.py", line 17, in <module><br/>
    print("You said: " + r.recognize_google(audio))<br/>
  File "C:\python27\lib\site-packages\speech_recognition\__init__.py", line 828, in recognize_google<br/>
    convert_width=2  # audio samples must be 16-bit<br/>
  File "C:\python27\lib\site-packages\speech_recognition\__init__.py", line 448, in get_flac_data<br/>
    startup_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW  # specify that the wShowWindow field of `startup_info` contains a value<br/>
AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW'<br/>

【问题讨论】:

  • 你导入subprocess模块了吗?
  • 是的,我已经导入了子流程
  • 这是我的程序 import speech_recognition as sr r = sr.Recognizer() 以 sr.Microphone() 作为源: print("Say something!") audio = r.listen(source) 尝试: print("你说:" + r.recognize_google(audio)) except sr.UnknownValueError: print("Google Speech Recognition could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition服务;{0}".format(e))
  • 很抱歉,您的代码不可读,请相应格式化。但是,据我所见,您没有导入子流程模块,仅导入了 Speech_recognition。
  • 我导入了还是有错误

标签: python windows python-2.7 speech-recognition google-speech-api


【解决方案1】:

经过一点research 之后,似乎在Python 2.7 版本(您正在使用的版本)中,您必须使用use subprocess._subprocess.STARTF_USESHOWWINDOW 而不是subprocess.STARTF_USESHOWWINDOW。后者是在2.7版本之后添加的。

【讨论】:

  • 使用 bing api r.recognize_bing(audio, key=BING_KEY) 解决的问题比 google api 更好,并且在 windows 中运行良好,没有任何错误
猜你喜欢
  • 2010-11-18
  • 2018-08-28
相关资源
最近更新 更多