import pandas as pd import numpy as np import random from functools import reduce from speech_pitch import * # %matplotlib inline def fix_csv(collection_name = 'test'): seg_data = pd.read_csv('./outputs/'+collection_name+'.csv',names=['phrase','filename' ,'start_phoneme','end_phoneme','start_time','end_time']) seg_data.to_csv('./outputs/'+collection_name+'.fixed.csv') def pick_random_phrases(collection_name='test'): collection_name = 'test' seg_data = pd.read_csv('./outputs/'+collection_name+'.fixed.csv',index_col=0) phrase_groups = random.sample([i for i in seg_data.groupby(['phrase'])],10) result = [] for ph,g in phrase_groups: result.append(ph) pd.DataFrame(result,columns=['phrase']).to_csv('./outputs/'+collection_name+'.random.csv') # pick_random_phrases() def plot_random_phrases(collection_name = 'test'): collection_name = 'test' rand_words = pd.read_csv('./outputs/'+collection_name+'.random.csv',index_col=0) rand_w_list = rand_words['phrase'].tolist() seg_data = pd.read_csv('./outputs/'+collection_name+'.fixed.csv',index_col=0) result = (seg_data['phrase'] == rand_w_list[0]) for i in rand_w_list[1:]: result |= (seg_data['phrase'] == i) # seg_data[result] phrase_groups = [i for i in seg_data[result].groupby(['phrase'])] self_files = ['a_wrong_turn-low1.aiff','great_pin-low1.aiff' ,'he_set_off_at_once_to_find_the_beast-low1.aiff' ,'hound-low1.aiff','noises-low1.aiff','po_burped-low1.aiff' ,'she_loves_the_roses-low1.aiff','the_busy_spider-low1.aiff' ,'the_rain_helped-low1.aiff','to_go_to_the_doctor-low1.aiff'] co_files = map(lambda x: './inputs/self/'+x,self_files) for ((ph,g),s_f) in zip(phrase_groups,co_files): # ph,g = phrase_groups[0] file_path = './outputs/test/'+g.iloc[0]['filename'] phrase_sample = pm_snd(file_path) self_sample = pm_snd(s_f) player,closer = play_sound() # rows = [i for i in g.iterrows()] # random.shuffle(rows) print(ph) phon_stops = [] for (i,phon) in g.iterrows(): end_t = phon['end_time']/1000 phon_ch = phon['start_phoneme'] phon_stops.append((end_t,phon_ch)) plot_sample_pitch(phrase_sample,phons = phon_stops) plot_sample_pitch(self_sample) # player(phrase_sample) # input() # for (i,phon) in g.iterrows(): # # phon = g.iloc[1] # start_t = phon['start_time']/1000 # end_t = phon['end_time']/1000 # phon_ch = phon['start_phoneme'] # phon_sample = phrase_sample.extract_part(from_time=start_t,to_time=end_t) # if phon_sample.n_samples*phon_sample.sampling_period < 6.4/100: # continue # # if phon_ch[0] not in 'AEIOU': # # continue # # phon_sample # # player(phon_sample) # # plot_sample_intensity(phon_sample) # print(phon_ch) # plot_sample_pitch(phon_sample) closer() # print(phg)#['start_phoneme'],g['start_time']) plot_random_phrases()