speech_recognition
speech_recognition copied to clipboard
WinError 10054
Steps to reproduce
1.The issue happen every time i run the code [WinError 10054] An existing connection was forcibly closed by the remote host 2. Every time i run the code the same error appear
import os
import pygame
import speech_recognition as sr
def speak(text):
voice = "en-US-ChristopherNeural"
command = f'edge-tts --voice "{voice}" --text "{text}" --write-media "MichealOutput.mp3"'
os.system(command)
pygame.init()
pygame.mixer.init()
try:
pygame.mixer.music.load("MichealOutput.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
except Exception as e:
print(e)
finally:
pygame.mixer.music.stop()
pygame.mixer.quit()
def take_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-us')
print("hi")
except Exception as e:
print(e)
return ""
return query
speak("hello, i am Micheal, your virtual assistant; How can i help you today")
query = take_command()
print(query)
here is the code
Expected behaviour
that it recognize my speech and print it
Actual behavior
nothing the code work well but after the r.recognize function the error appeared [WinError 10054] An existing connection was forcibly closed by the remote host
PS C:\Users\hammo> & C:/Users/hammo/AppData/Local/Programs/Python/Python311/python.exe c:/Users/hammo/Desktop/Micheal/main.py
pygame 2.5.2 (SDL 2.28.3, Python 3.11.7)
Hello from the pygame community. https://www.pygame.org/contribute.html
WEBVTT
00:00:00.100 --> 00:00:03.625
hello i am Micheal your virtual assistant How can i
00:00:03.638 --> 00:00:04.463
help you today
Listening...
Recognizing...
[WinError 10054] An existing connection was forcibly closed by the remote host
PS C:\Users\hammo> ```
System information
------------------
(Delete all the statements that don't apply.)
My **system** is <windows 11>. (For example, "Ubuntu 16.04 LTS x64", "Windows 10 x64", or "macOS Sierra".)
My **Python version** is <3.11.7>. (You can check this by running `python -V`.)
My **Pip version** is <INSERT VERSION HERE>. (You can check this by running `Fatal error in launcher: Unable to create process using '"C:\Users\hammo\AppData\Local\Programs\Python\Python312\python.exe" "C:\Users\hammo\AppData\Local\Programs\Python\Python312\Scripts\pip.exe" -V': The system cannot find the file specified.`.)
My **SpeechRecognition library version** is <3.10.1>. (You can check this by running `python -c "import speech_recognition as sr;print(sr.__version__)"`.)
My **PyAudio library version** is <0.2.14> / I don't have PyAudio installed. (You can check this by running `python -c "import pyaudio as p;print(p.__version__)"`.)
My **microphones** are: (You can check this by running `python -c "import speech_recognition as sr;print(sr.Microphone.list_microphone_names())"`.)
My **working microphones** are:( {} this is what he gave me ) (You can check this by running `python -c "import speech_recognition as sr;print(sr.Microphone.list_working_microphones())"`.)
I **installed PocketSphinx from** <no>. (For example, from the Debian repositories, from Homebrew, or from the source code.)