Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinError 10054 #733

Closed
MohamedSamer1 opened this issue Feb 2, 2024 · 3 comments · Fixed by #754
Closed

WinError 10054 #733

MohamedSamer1 opened this issue Feb 2, 2024 · 3 comments · Fixed by #754
Assignees

Comments

@MohamedSamer1
Copy link

MohamedSamer1 commented Feb 2, 2024

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

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 . (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 . (For example, from the Debian repositories, from Homebrew, or from the source code.)

@Hexer-7
Copy link

Hexer-7 commented Mar 24, 2024

Hi Mohammed,

I faced the same problem as you, and unfortunately, the reason was trivial. You need to modify the link in library "speech_recognition\recognizers\google.py"
from "http://www.google.com/speech-api/v2/recognize" to "https://www.google.com/speech-api/v2/recognize",
meaning changing "http" to "https".

I hope I was able to help you.

@ftnext ftnext assigned ftnext and MohamedSamer1 and unassigned ftnext May 1, 2024
@ftnext
Copy link
Collaborator

ftnext commented May 1, 2024

@MohamedSamer1 Thanks to report this.
Please try Hexer-7's workaround and tell us whether it works or not.

@ftnext
Copy link
Collaborator

ftnext commented May 5, 2024

@MohamedSamer1 SpeechRecognition 3.10.4 was out!
Try this by pip install --upgrade SpeechRecognition
You can write Hexer-7's workaround like

-query = r.recognize_google(audio, language='en-us')
+query = r.recognize_google(audio, language='en-us', endpoint='https://www.google.com/speech-api/v2/recognize')

If WinError 10054 is not resolved in your environment, please feel free to reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants