i'm trying to write a hearing test that will play sounds at increasingly loud volumes until it has traversed its list of volumes or there is input from the user, indicating they heard the sound. To do this I'm trying to get the script to ask for input while still looping to increase the volumes, but normally input() will stop the script. And threads seem to stop working after the firs loop-over. This is what I came up with so far:
def tone_stopper():
"""This function will take as input a pressed key on the keyboard and give
True as output"""
test = input("Press enter when you hear a tone: ")
if test == " ":
return True
def call_play_file(frequency, vol_list):
"""This function will play a frequency and stop when the user presses
a button or stop when it reaches the loudest volume for a frequency,
it takes as an input a frequency and a list of volumes
and returns the loudness at which the sound was playing when a button was
pressed"""
for volume in vol_list: #plays a tone and then repeats it a different vol
tone_generator(frequency, volume)
play_file('hearingtest.wav')
if thread == True:
return frequency, volume
return frequency, "didn't hear" #in case no button is pressed
thread = threading.Thread(target = tone_stopper())
thread.setDaemon(True)
thread.start()
vol_list = [4, 8, 12];
freq_left_right = random_freq_list(200, 18000, 500)
startplaying = call_play_file(freq_left_right, vol_list)
To keep the script from being extremely long it refers to two functions that I didn't define here.