I am trying to create a python script that talks to itself. (example: https://vimeo.com/172440766) I have already been able to implement text-to-speech and speech-recognition one after another, but haven't found a way to do this at the same time.
Is there a way to do these two tasks in parallel? Appreciate any suggestions.
If you need something done concurrently, check out the threading library: https://docs.python.org/3/library/threading.html
An idea would be to create a thread for your speech recognition outside of the main control flow as I imagine this will be active most of the time. For a start you could do:
import threading
class SpeechRecognition(threading.Thread):
def __init__(self, parent=None):
super().__init__()
self.parent = parent
def run(self):
(your speech recognition function/code here)
and to start the speech recognition:
process = SpeechRecognition()
process.start()