def get_desired_features(): print("With which features do you want to train the model? (e.g. MFCC, FBANK, MFCC and pitch, FBANK and deltas)") features = input() if "exit" in features.lower(): raise ExitApp() print("\nYou entered: \n\n{}\n\nIs this correct? (Y/N)".format(features)) correct = input() if "exit" in correct.lower(): raise ExitApp() elif "y" not in correct.lower(): features = get_desired_features() return features
def get_label_column(): print("What is the column name for the label? (e.g. word, gender, class)") label_column = input() if "exit" in label_column.lower(): raise ExitApp() print("You entered ' {} '. Is that correct? (Y/N)".format(label_column)) correct = input() if "y" in correct.lower(): pass elif "exit" in correct.lower(): raise ExitApp() else: label_column = get_label_column() return label_column
def get_feature_type(): print("What kind of features will you extract? (e.g. mfcc, fbank, fbank with deltas, mfcc with pitch values)") features = input() if "exit" in features.lower(): raise ExitApp() print("You entered {}".format(features)) return features
def go(): print("Press ENTER to continue.") cont = input() if "exit" in cont.lower(): raise ExitApp("Have a good day!") elif cont != "": print("Type 'exit' to end the program.") cont = go() return True
def login(self,username): print("\nEnter your password to access your lists.\n") password = self.get_password() if 'exit' == password.lower(): raise ExitApp("Aw man. You're leaving already? Come back soon!") if password: match = self.check_password(username, password) return match return None
def get_label_data_type(): print("What type of data will the label be saved in the table? (i.e. 'INT', or 'TEXT')") data_type = input() type_options = ["INT","INTEGER","TEXT"] if data_type.upper() not in type_options: print("Please enter one of the following: {}".format(", ").join(type_options)) data_type = label_data_type() elif "exit" in data_type.lower(): raise ExitApp() return data_type
def add_noise(): print("Will you add noise? (Y/N)") noise = input() if "y" in noise.lower(): noise = True elif "n" in noise.lower(): noise = False elif "exit" in noise.lower(): raise ExitApp() return noise
def set_limit(): print("Is there a limit for the data? If YES: enter an INTEGER.") limit = input() if "exit" in limit.lower(): raise ExitApp() elif limit.isdigit(): limit = int(limit) else: limit = None return limit
def get_num_features(): print("How many feature columns do you need? (If you want the derivatives, DON'T INCLUDE THE COLUMNS FOR THOSE VALUSE HERE)") num_features = input() if num_features.isdigit(): pass elif "exit" in num_features.lower(): raise ExitApp() else: print("Please enter an integer") num_features = get_num_features() return int(num_features)
def get_username(self): print("\nUsername: "******"Spaces and special characters will be removed: ") username = rem_space_specialchar(username) if 'exit' == username.lower(): raise ExitApp("Aw man. I didn't even catch your name. Come back soon!") if username: return username else: print("Not enough alphanumeric characters used. Try again.") self.get_username() return None
def load_data(database,table,columns=None): if columns is None: columns = "all" print("Loading data from {} columns from {} in database: {}".format(columns,table,database)) limit = set_limit() print("Press ENTER to continue") cont = input() if "exit" in cont.lower(): raise ExitApp() elif cont.lower() == "": pass else: cont = load_data(database,table) data = select_data(database,table,limit) return data
from errors import ExitApp from user_account import LoginUser from user_data_babyname import UserData if __name__ == "__main__": database = "babynames_USA.db" num_clusters = 30 num_features = 5 #selected features to define clusters try: login = None ud = None login = LoginUser(database) login.sign_in() if login.is_user != True: print("Login failed.") raise ExitApp("UserId not found.") user_id = login.get_userid(login.username) if user_id is None: print("User ID Error") raise SystemExit ud = UserData(database, user_id, num_clusters, num_features=num_features) ud.main_menu() except ExitApp: print("Have a good day!") except SystemExit as e: print("Problem occurred: {}. Had to close app.".format(e)) except Exception as e: print(e)
def main(script_purpose, split=False): current_filename = os.path.basename(__file__) session_name = get_date( ) #make sure this session has a unique identifier - link to model name and logging information path_to_data = "./data_3word" start = time.time() try: start_logging(script_purpose) logging.info("Running script: {}".format(current_filename)) logging.info("Session: {}".format(session_name)) tablename, feature_type, num_features, num_feature_columns, noise = user_input.set_variables( ) paths, labels = featfun.collect_audio_and_labels(path_to_data) noise_path = "./_background_noise_/doing_the_dishes.wav" label_list = [i[1] for i in labels] class_labels = list(set(label_list)) print("The labels found: {}".format(class_labels)) #find out number of recordings from each class #ask user if they want to balance out the data? dict_class_distribution = featfun.get_class_distribution( class_labels, label_list) min_val = (1000000, None) for key, value in dict_class_distribution.items(): if value < min_val[0]: min_val = (value, key) print("Number of wave files for each class:\n\n{}\n\n".format( dict_class_distribution)) print("Chosen max number of files from each class = {}".format( min_val[0])) print("\n\nDo you approve this? (Y/N)") approve = input() if 'exit' in approve.lower(): raise ExitApp() elif 'y' in approve.lower(): pass elif 'n' in approve.lower(): print("Okay... woring on that functionality") raise ExitApp() else: raise ExitApp() max_num_per_class = min_val[0] #create dictionary w indices to labels and paths for each class dict_class_index_list = {} for label in class_labels: dict_class_index_list[label] = [] for i, label_item in enumerate(label_list): if label == label_item: dict_class_index_list[label].append(i) #get num per training/validation/test datasets max_nums_train_val_test = get_max_nums_train_val_test( max_num_per_class) #randomly assign indices to train, val, test datasets: dict_class_dataset_index_list = {} for label in class_labels: tot_indices = dict_class_index_list[label] tot_indices_copy = tot_indices.copy() random.shuffle(tot_indices_copy) train_indices = tot_indices_copy[:max_nums_train_val_test[0]] val_indices = tot_indices_copy[ max_nums_train_val_test[0]:max_nums_train_val_test[0] + max_nums_train_val_test[1]] test_indices = tot_indices_copy[ max_nums_train_val_test[0] + max_nums_train_val_test[1]:max_nums_train_val_test[0] + max_nums_train_val_test[1] + max_nums_train_val_test[2]] dict_class_dataset_index_list[label] = [ train_indices, val_indices, test_indices ] print() print("Name for directory to save feature images:") new_directory = input() if 'exit' in new_directory.lower(): raise ExitApp() train_val_test_dirs = [] for i in ["train", "val", "test"]: train_val_test_dirs.append(new_directory + "_{}".format(i)) start_feature_extraction = time.time() for label in class_labels: for i, directory in enumerate(train_val_test_dirs): if i == 0: train = True else: train = False try: os.makedirs(directory) except OSError as e: if e.errno != errno.EEXIST: raise dict_new_paths = {} new_path = './{}/{}/'.format(directory, label) try: os.makedirs(new_path) dict_new_paths[label] = new_path except OSError as e: if e.errno != errno.EEXIST: raise #limit = int(max_nums_train_val_test[i]*.3) limit = None num_pics = max_nums_train_val_test[i] msg = "\nExtracting features from {} samples. \nImages will be saved in the directory {}".format( num_pics, new_path) print(msg) logging.info(msg) frame_width = 11 time_step = 6 logging.info( "extracting features from wavefiles. Limit = {}".format( limit)) paths_list_dataset = [] labels_list_dataset = [] train_val_test_index_list = dict_class_dataset_index_list[ label] for k in train_val_test_index_list[i]: paths_list_dataset.append(paths[k]) labels_list_dataset.append(label_list[k]) print("Extracting features from class: {}".format(label)) for j, wav in enumerate(paths_list_dataset): if limit: if j <= limit: featfun.save_chroma( wav, split, frame_width, time_step, feature_type, num_features, num_feature_columns, noise, dict_new_paths[labels_list_dataset[j]], train, noise_path, vad=True, add_noise=True) else: featfun.save_chroma( wav, split, frame_width, time_step, feature_type, num_features, num_feature_columns, noise, dict_new_paths[labels_list_dataset[j]], train, noise_path, vad=True, add_noise=True) end_feature_extraction = time.time() logging.info("Duration setup: {} minutes".format( round((start_feature_extraction - start) / 60, 2))) print("Duration of feature extraction: {} minutes".format( round((end_feature_extraction - start_feature_extraction) / 60, 2))) except ExitApp: print("Have a good day!") logging.info("User exited app.") except FeatureExtractionError as e: logging.exception("Error occurred in feature extraction: {}".format(e)) except Exception as e: logging.exception("Error occurred: {}".format(e)) finally: end = time.time() duration = round((end - start) / 60, 2) logging.info("Duration: {} minutes".format(duration))
color_scale = 1 sampling_rate = 16000 noise_filename = "background_noise.wav" if sex == "female": speech_filename = "speaker_aislyn_satz.wav" speech_nr_filename = "speech_modelready_aislyn11.wav" else: speech_filename = "speaker_thomas_satz.wav" speech_nr_filename = "speech_modelready_thomas9.wav" print("Testing classifier with {} speech:".format(sex)) print("Press ENTER to start") ready = input() if ready != "": raise ExitApp() #background_noise = speech_collection.record(5,sampling_rate) #speech_collection.save_recording("noise_trash.wav",background_noise,sampling_rate) #print("Please press Enter and then say loudly and clearly: \n\n'Hallo, wie geht es Ihnen?'\n") #start = input() #if start != "": # raise ExitApp() #speech = speech_collection.record(5,sampling_rate) #print("\nNow saving..") #speech_collection.save_recording("speech_trash.wav",speech,sampling_rate) print("\nNow extracting features..\n") y_speech, sr = librosa.load(speech_filename, sr=sampling_rate) #y_noise, sr = librosa.load("background_noise.wav",sr=sampling_rate)