![](/img/trans.png)
[英]Having trouble in installing and importing pyttsx3(text to speech conversion library) in Python VS code
[英]Having trouble with speech to text in Python
import speech_recognition as sr
rec = sr.Recognizer()
with sr.Microphone as source:
print('say something')
audio = rec.listen(source)
voice_data = rec.recognize_google(audio)
print(voice_data)
這是我在網上觀看的大量教程中顯示的代碼,我安裝了 SpeechRecognizer 和 pyAudio(使用 whl 文件,而不是 pip,我不知道它是否有區別)。
當我嘗試運行它時,它給了我關於 pydevd.py 中某些內容的錯誤,最后給了我:
以 sr.Microphone 作為來源:
屬性錯誤:輸入
我該如何解決這個問題?
我通過將與捕獲音頻無關的語句移出 with 語句來使其工作,這應該對您有用:
import speech_recognition as sr
rec = sr.Recognizer()
print('say something')
with sr.Microphone() as source:
audio = rec.listen(source)
voice_data = rec.recognize_google(audio)
print(voice_data)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.