Hi,
I’m quite new to touchdesigner and have a question about using a python while loop.
I have two Text Dat’s: ‘listen’ and ‘prompt’.
Listen contains a python script that continuously listens to a microon and once the word ‘stop’ is said it has to send the spoken text to the text-dat ‘prompt’. Then the script has to continue and as soon as the word ‘stop’ is said again, the text-dat ‘prompt’ is emptied and the new spoken text is put in ‘prompt’, etc…
When ‘end’ is said, the script stops.
The script is below.
I am unable to get this working. The spoken-text is written to the text-dat prompt only when the script is finished, but not during the while loop. And during the while loop also the timeline paused, so other processes are waiting on the while loop.
This also applies if, for example, I want to send a trigger to another component within the while loop.
How can I solve this?
The script in the ‘Listen’ text-dat (in abbreviated form and without the right indentations):
import speech_recognition as sr
r = sr.Recognizer()
microphone = sr.Microphone()
phrase = ""
prompt = on('prompt')
prompt.clear()
whileTrue:
with microphone as source:
audio = r.listen(source, phrase_time_limit=60)
try:
speak = r.recognize_google(audio, language="en-US")
if "stop" in speak.lower():
sentence += speak.lower().replace("stop", "") + " "
prompt.clear()
prompt.write(sentence)
speak = ""
sentence = ""
continuous
elif "end" in speak.lower():
break
except sr.UnknownValueError:
#do some error handling and continue
continuous
except sr.RequestError as e:
#do some error handling and break
break
Sincerely, Pieter van Dijk