Unsolved Speech Recognition always listen and execute commands
-
I want the program always listen till it hear the word "sofia" and again hear for command and return the text so other class processes it and again hear for the word "sofia" and another command.
#SpeechCls import speech_recognition as sr import time from PyQt5.QtWidgets import QMessageBox import playsound import voiceAssistant counter = 0; lang_name = "fa-IR" class Speech: def SpeechFunc(self) : sample_rate = 48000 chunk_size = 2048 r = sr.Recognizer() mic_list = sr.Microphone.list_microphone_names() global text try: micro_name except NameError: self.SetMicName( mic_list[0]) for i, microphone_name in enumerate(mic_list): if microphone_name == self.getMic(): device_id = i try: with sr.Microphone(device_index = device_id, sample_rate = sample_rate, chunk_size = chunk_size) as source: while 1 : r.adjust_for_ambient_noise(source) audio = r.listen(source) try: text = r.recognize_google(audio,language=lang_name) except sr.UnknownValueError: text = "error : Not recognize the voice" except sr.RequestError as e: text = "error :can't connect to google" # playsound.playsound('noInternet.mp3', True) break if "sofia" in text: playsound.playsound('here.mp3', True) text = "" print("say your command") audio = r.listen(source) try: text = r.recognize_google(audio,language=lang_name) break except sr.UnknownValueError: text = "error : Not recognize the voice" except sr.RequestError as e: text = "error :can't connect to google" except: text = "error : Change the microphone" def textReturn(self): self.SpeechFunc() return text def mic_lists(self): mic_list= sr.Microphone.list_microphone_names() return mic_list def SetMicName(self,name): global micro_name micro_name = name; def setLang(self,lang): global lang_name if not lang_name : lang_name = "fa-IR" if (lang == 0): lang_name = "fa-IR" elif (lang == 1): lang_name = "en-US" elif (lang == 2): lang_name = "es" elif (lang == 3): lang_name = "ar-IQ" elif (lang == 4): lang_name = "tr" def getMic(self): return micro_name
I call the above class via this command :
self.speechText = SpeechCls.Speech().textReturn()
The problem is it works on my laptop but on other computer doesn't get to command portion after saying "sofia"
-
Hi,
Sounds like it would rather be a question for the authors the speech_recognition/voiceAssistant packages you are using, isn't it ?
-
@SGaist So what's is your suggestion where can i ask and get answer ?
-
Where are these speech related classes coming from ?
-
@Denni-0 As you suggested me i end up installing python and other library and hard code for that machine. Now it works your hint about print statement and debugging was very useful. I really appreciate your help .
-
@SGaist In the main class which is the form i i call it in a different thread.
-
This post is deleted!