3

I am developing a virtual assistant. I am using google_speech_to_text converter i am unable to keep the audio input continues. I think if there is any way i can use two environments, one will be used for listening and converting text and other for rest of the processing.

I don't want to change my STT engine. i just want to know is it possible to simultaneously switch between environments. If yes, HOW?

Here is my input.py file : whereever I require to take audio input I call the function start_listening():

import speech_recognition as sr
import output
import winsound

def start_listening():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        # output.speak("Listening")
        r.adjust_for_ambient_noise(source)
        audio = r.record(source, duration=5)

        try:
            return r.recognize_google(audio)
        except:
            output.speak("Unable to Translate, speak again")
            start_listening()

Here is my processing.py file :

import input as listener
import output as speak
import clock
import query_processor as mind
import rideBooking

#First Greeting at the startup , according to the time select the greeting
speak.speak(clock.get_part_of_day())

def searching_for_word(word,sentence):
    if word in sentence:
        return True
    else:
        return False

def main_organ():
    input = listener.start_listening()
    inputType = mind.classify(input)
    if inputType == 'whatever':
        #run different functions on different commands
        main_organ()


#run the app with the below code
if __name__ == "__main__":
    main_organ()

While the processing is ON the app is unable to listen. It can only start_listening when the processing is fully completed.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TRQ
  • 33
  • 4

1 Answers1

0

You can create multiple processes.

To do that, import the multiprocessing.Process.run module and recover the return value.

You can use a queue to process the data as it comes from your subprocess.

You don't need multiple environments.

Benoît P
  • 3,179
  • 13
  • 31
  • i want the processing be done at the background without interrupting the input processing. – TRQ Mar 01 '19 at 00:35
  • like if the processing needs 2 minutes to process something during that period the input should work fine and watches for the commands – TRQ Mar 01 '19 at 00:36
  • multiprocessing does that. Put the data to process in a queue, and process it in another process. The processing process will process the data without interrupting other processes. – Benoît P Mar 01 '19 at 00:43
  • Can you please help me with a example – TRQ Mar 01 '19 at 01:11