def take_user_input(self, list_task, flag): #Speech_samples_required = ['One', 'Two','Three', 'Four', 'Zero'] Username = "******" #frames = [] #dict = { 'Four': 4, 'One': 1, 'Three': 3, 'Two': 2, 'Zero': 0} #for v, i in enumerate(Speech_samples_required): #print("When ready, please press esc and say {}".format(i)) #kb.wait('esc') #print(i) #audio_file_plath = Record_audio.record_voice(Username, "0", "1" , 'team_data/') self.prompt_menu(list_task, flag) #kb.wait('esc') audio_file_path = Record_audio.record_voice("userinput", "1", 1, 'team_data/') features = Record_audio.get_features("team_data/1_userinput_1.wav", sr=8000) #print(list(features)) features1 = [] features1.append(features) features2 = pd.DataFrame(features1) # Extract features from the user input #calling classify_input to get the prediction and confidence measure by giving features and model, you have to complete the classify_input method #model = 0 digit, confidence = self.classify_input(features2, model_KNN) print(digit[0], confidence) digit, choice = self.confirm_input(digit[0], confidence, flag) return digit, choice
def confirm_input(self, digit, confidence, flag): if (confidence > T) and (digit < len(list_task[flag])): return digit, list_task[flag][digit] else: print('Sorry we could not understand you, please reconfirm') #list_task = shuffled list_task Record_audio.play_audio("sorry_reconfirm.wav") return self.take_user_input(list_task, flag)
def rec(): Speech_samples_required = [ 'Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'yes', 'no', ] Username = input("What is your ID? ") #frames = [] dict = { 'Eight': 8, 'Four': 4, 'Nine': 9, 'One': 1, 'Seven': 7, 'Five': 5, 'Six': 6, 'Three': 3, 'Two': 2, 'Zero': 0, 'no': 11, 'yes': 10 } confidence_array = np.zeros(12) for v, i in enumerate(Speech_samples_required * 1): print("When ready, please press esc and say {}".format(i)) kb.wait('esc') print(i) audio_file_path = Record_audio.record_voice(Username, dict[i], v, "team_data/") Record_audio.play_audio(audio_file_path) #get_features in Record_audio.py should be completed features = Record_audio.get_features(audio_file_path, sr=8000) label = int(audio_file_path.split("/")[-1].split("_")[0]) #######use your classifier to return a confidence and predict for the input #######digit is the prediction and confidence should be confidence measure confidence, digit = 0, 0 #use the model you defined here to get the confidence and digit if digit == label: confidence_array[dict[i]] = confidence else: pass print("Confidence : {} Prediction : {} label : {} ".format( confidence, digit, label))
def take_user_input(self, list_task, flag): self.prompt_menu(list_task, flag) audio_file_path = Record_audio.record_voice("userinput", "1", 1, "./") features = Record_audio.get_features(audio_file_path, sr=8000, n_mfcc=30, n_mels=128, frames=15) digit, confidence = self.classify_input(features) digit, choice = self.confirm_input(digit, confidence, flag) return digit, choice
def completeTheClassification(): for filename in glob.iglob( "/Users/madhukaruturi/Desktop/Madhu/AI-ML/AIML-Labs/Hackathon I/speech-data/*.wav" ): featureDF.append( Record_audio.get_features(filename, sr=8000, n_mfcc=30, n_mels=128, frames=15)) labelDF.append(os.path.basename(filename).split('_')[0])
def test(fileName): deep_features = [] deep_features.append( Record_audio.get_features(fileName, sr=8000, n_mfcc=30, n_mels=128, frames=15)) loadedModel = pickle.load( open( "/Users/madhukaruturi/Desktop/Madhu/AI-ML/AIML-Labs/Hackathon I/model.sav", 'rb')) print(loadedModel.predict(deep_features))
#Will take arguments as user_name #hardcoding sampling rate to 8000 #--user <user_name> import Record_audio as rec import sys import keyboard as kb sounds_to_record = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Yes', 'No'] if len(sys.argv) < 2: print('Required syntax: python record_samples.py <user_name>') exit user = sys.argv[1] print("\n-----Start the process to record samples for User:"******"\n\n--------------Starting to record samples for ", sounds_to_record[label]) for sample_id in range(0,5): print('{}_{}_{}.wav'.format( label, user, sample_id)) print("\nPress 'n' when you are ready") kb.wait('n') rec.record_voice(user, label, sample_id, "group5_voice/" )
def record_tonic(): print("let's record a new sound\n") rec.record_to_file('menu_sleeping_demo_dj.wav') print("great, done!\n")
'Five': 5, 'Six': 6, 'Three': 3, 'Two': 2, 'Zero': 0, 'no': 11, 'yes': 10 } confidence_array = np.zeros(12) for v, i in enumerate(Speech_samples_required * 10): print("When ready, please press esc and say {}".format(i)) kb.wait('esc') print(i) audio_file_path = Record_audio.record_voice(Username, dict[i], v, "team_data/") Record_audio.play_audio(audio_file_path) #get_features in Record_audio.py should be completed features = Record_audio.get_features(audio_file_path, sr=8000) label = int(audio_file_path.split("/")[-1].split("_")[0]) #######use your classifier to return a confidence and predict for the input #######digit is the prediction and confidence should be confidence measure confidence, digit = 0, 0 #use the model you defined here to get the confidence and digit if digit == label: confidence_array[dict[i]] = confidence else: pass
def prompt_menu(self, list_task, flag): #flag = menu(0)/quantity(1) Record_audio.play_audio(menu_prompts[flag]) Record_audio.play_audio("beep.wav") for i in range(0, len(list_task[flag])): print('say ' + str(i) + ' for ' + str(list_task[flag][i]))
'Seven', 'Eight', 'Nine', 'Zero', 'yes', 'no', ] Username = input("What is your ID? ") #frames = [] dict = { 'Eight': 8, 'Four': 4, 'Nine': 9, 'One': 1, 'Seven': 7, 'Five': 5, 'Six': 6, 'Three': 3, 'Two': 2, 'Zero': 0, 'no': 11, 'yes': 10 } for v, i in enumerate(Speech_samples_required * 10): print("When ready, please press esc and say {}".format(i)) kb.wait('esc') print(i) audio_file_plath = Record_audio.record_voice(Username, dict[i], v, 'team_data/')