我正在尝试做SpeechRecognition 3.8.1 https://pypi.org/project/SpeechRecognition/听我的声音四天了。我已经在互联网上看到过以下内容:
- https://github.com/Uberi/speech_recognition/issues/20 https://github.com/Uberi/speech_recognition/issues/20
- https://www.geeksforgeeks.org/voice-assistant-using-python/ https://www.geeksforgeeks.org/voice-assistant-using-python/
-
https://pythonrepo.com/repo/Uberi-speech_recognition-python-audio https://pythonrepo.com/repo/Uberi-speech_recognition-python-audio
-
sudo apt-get install python-pyaudio python3-pyaudio
对我不起作用。
- 语音识别Python代码不起作用 https://stackoverflow.com/questions/32005310/speech-recognition-python-code-not-working
- Visual Studio 代码 Python 上的 PyAudio 出现错误 https://stackoverflow.com/questions/61256699/errors-on-pyaudio-on-visual-studio-code-python
- 我无法在 Windows 上安装 pyaudio?如何解决“错误:需要 Microsoft Visual C++ 14.0”? https://stackoverflow.com/questions/52283840/i-cant-install-pyaudio-on-windows-how-to-solve-error-microsoft-visual-c-14
- https://newbedev.com/speech-recognition-python-code-not-working-code-example https://newbedev.com/speech-recognition-python-code-not-working-code-example
- https://www.py4u.net/discuss/22062 https://www.py4u.net/discuss/22062
我经历了更多的讨论,一切都是徒劳.
到目前为止,没有任何解决方案对我有用。请帮忙!!
经过多次失败的尝试,我至少成功安装了pyaudio
用命令pipwin install pyaudio
我的Python代码:
import os
import pyttsx3, datetime, pyaudio
import speech_recognition as sr
# Initial Setup for pyttsx3 - speaking abilities
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[1].id) # 0-male voice , 1-female voice
sr.Microphone.list_microphone_names()
# Initial Setup for speech_recognition - listening abilities
# r.energy_threshold = 10
# print(pyaudio.get_device_count() - 1)
def speak(speakable):
"""speak() takes a string and reads it loud"""
engine.say(str(speakable))
engine.runAndWait()
def takeCommand():
pyaudio.PyAudio()
r = sr.Recognizer()
"""It takes microphone input from the user and returns string output"""
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source, duration=0.9)
print("Listening...")
r.pause_threshold = 45
audio = ""
try:
audio = r.listen(source)
print("Recognizing...")
except Exception as e:
print("Listen err: ", e)
try:
print("Recognizing...")
query = r.recognize_google(audio)
print(f"User said: {query}\n") # User query will be printed.
except sr.UnknownValueError as e:
print("Say that again please...")
return "None" # None string will be returned
except Exception as err:
print("Check your internet...")
return "None"
return query
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
speak("Good Morning!")
elif hour >= 12 and hour < 18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak(
"Hello Sir, I am Friday, your Artificial intelligence assistant. Please tell me how may I help you"
)
if __name__ == "__main__":
os.system("CLS")
while True:
command = takeCommand().lower()
print(f"Command: {command}")
if "wish" in command:
wishMe()
输出卡在Listening...
。之后什么也没有发生。
更多信息:
- 我在用
Windows 10 Home
- 代码编辑器-
vs code
- 我没有使用
virtual env
在这个这个节目中。
- 我也检查过Chrome 语音搜索工作没有任何问题。
-
result of the python3 -m speech_recognition
command
你尝试过使用python3 -m speech_recognition
?您应该看到类似以下内容:
...
A moment of silence, please...
Set minimum energy threshold to 51.208131879528096
Say something!
Got it! Now to recognize it...
You said hello
如果这不起作用,则您的音频系统可能有问题。确保您可以录制音频(https://onlinehardwaretest.com/microphone-test/ https://onlinehardwaretest.com/microphone-test/)并考虑重新启动系统。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)