def keyOne(cs_mic, pnl_mic, cs_speaker, pnl_speaker): track = randrange( 29) #generate a random number to select which audio file to test with # track = 3 # Run the micToText function with a flag so that we can import the speechrecognition module # before spinning up a thread. This allows us to prevent a race condition that would # periodically crash the program micToText(2, True) #Can the CS hear the panel? pnl_audio_thread = threading.Thread(target=playAudio, args=(pnl_speaker, hs[4][FILE])) pnl_audio_thread.start() transcription = micToText( cs_mic, False ) #transcription holds the string that was transcribed from the audio clip while pnl_audio_thread.isAlive( ): #make sure the thread has finished before moving on to avoid two audio clips playing at the same time time.sleep(0.1) if (str(transcription).lower() == ""): print("Pass! Nothing was detected") #Can the panel hear the CS? cs_audio_thread = threading.Thread(target=playAudio, args=(cs_speaker, hs[4][FILE])) cs_audio_thread.start() transcription = micToText( pnl_mic, False ) #transcription holds the string that was transcribed from the audio clip while cs_audio_thread.isAlive(): time.sleep(0.1) if (str(transcription).lower() == str(hs[track][TEXT]).lower()): print("Pass! Call was understood") return
r = sr.Recognizer() #Selecting Mics mic_list = sr.Microphone.list_microphone_names() print('\n'.join('{}: {}'.format(*k) for k in enumerate(mic_list))) print("Please select the number of the microphone you would like to use for the CS:") cs_mic=int(input()) print("Please select the number of the microphone you would like to use for the Panel:") pnl_mic=int(input()) print("Please select the number of the speaker you would like to use for the CS:") cs_speaker=int(input()) print("Please select the number of the speaker you would like to use for the Panel:") pnl_speaker=int(input()) micToText(2,True) audio_thread=threading.Thread(target=playAudio, args=(2,sys.argv[1])) audio_thread.start() micToText(2,False) while audio_thread.isAlive(): time.sleep(0.1) # #CS mic test # with cs_mic as source: # print("Speak into the CS mic") # audio = r.adjust_for_ambient_noise(source) # audio = r.listen(source) # try: # recog = r.recognize_wit(audio, key = "6Y4KLO4YTWDQSYQXGONPHAVB3IRSWFRN")
# # Selecting Mics # mic_list = sr.Microphone.list_microphone_names() # print('\n'.join('{}: {}'.format(*k) for k in enumerate(mic_list))) # print("Please select the number of the microphone you would like to use for the CS:") # cs_mic=int(input()) # print("Please select the number of the microphone you would like to use for the Panel:") # pnl_mic=int(input()) # print("Please select the number of the speaker you would like to use for the CS:") # cs_speaker=int(input()) # print("Please select the number of the speaker you would like to use for the Panel:") # pnl_speaker=int(input()) # Run the micToText function with a flag so that we can import the speechrecognition module # before spinning up a thread. This allows us to prevent a race condition that would # periodically crash the program micToText(2, True) out = open("results3.txt", "a") for track in range(22): success = 0 failedList = [] correctString = str(hs[track][TEXT]).lower() clipName = str(hs[track][FILE]) for i in range(15): #Can the CS hear the panel? pnl_audio_thread = threading.Thread(target=playAudio, args=(4, hs[track][FILE])) pnl_audio_thread.start() transcription = micToText( 2, False
def trackToText(cs_mic, pnl_mic, cs_speaker, pnl_speaker): track = randrange( 4) #generate a random number to select which audio file to test with # track = 3 # Run the micToText function with a flag so that we can import the speechrecognition module # before spinning up a thread. This allows us to prevent a race condition that would # periodically crash the program micToText(2, True) #Can the CS hear the panel? pnl_audio_thread = threading.Thread(target=playAudio, args=(pnl_speaker, hs[track][FILE])) pnl_audio_thread.start() transcription = micToText(cs_mic, False) while pnl_audio_thread.isAlive(): time.sleep(0.1) if (str(transcription).lower() == str(hs[track][TEXT]).lower()): print("Pass! Call was understood") track = randrange( 4) #generate a random number to select which audio file to test with pnl_audio_thread = threading.Thread(target=playAudio, args=(pnl_speaker, hs[track][FILE])) pnl_audio_thread.start() transcription = micToText(cs_mic, False) while pnl_audio_thread.isAlive(): time.sleep(0.1) if (str(transcription).lower() == str(hs[track][TEXT]).lower()): print("Pass! Call was understood") track = randrange( 4) #generate a random number to select which audio file to test with pnl_audio_thread = threading.Thread(target=playAudio, args=(pnl_speaker, hs[track][FILE])) pnl_audio_thread.start() transcription = micToText(cs_mic, False) while pnl_audio_thread.isAlive(): time.sleep(0.1) if (str(transcription).lower() == str(hs[track][TEXT]).lower()): print("Pass! Call was understood") track = randrange( 4) #generate a random number to select which audio file to test with pnl_audio_thread = threading.Thread(target=playAudio, args=(pnl_speaker, hs[track][FILE])) pnl_audio_thread.start() transcription = micToText(cs_mic, False) while pnl_audio_thread.isAlive(): time.sleep(0.1) if (str(transcription).lower() == str(hs[track][TEXT]).lower()): print("Pass! Call was understood") track = randrange( 4) #generate a random number to select which audio file to test with pnl_audio_thread = threading.Thread(target=playAudio, args=(pnl_speaker, hs[track][FILE])) pnl_audio_thread.start() transcription = micToText(cs_mic, False) while pnl_audio_thread.isAlive(): time.sleep(0.1) if (str(transcription).lower() == str(hs[track][TEXT]).lower()): print("Pass! Call was understood")