def populate_calced_cols(db, col_dict, cur_wav_dir): #d1 is mother, d2 is baby rows = db.select( "%s d1 left join %s d2 on d1.%s = d2.%s AND d1.id = d2.id - 1 AND d1.%s = 'M' AND d2.%s = 'B' AND d1.%s <= ?" % (CSVDatabase.TABLE_NAME, CSVDatabase.TABLE_NAME, col_dict['Filename'], col_dict['Filename'], col_dict['Speaker'], col_dict['Speaker'], col_dict['Lag Time']), [ 'd1.id', 'd1.%s' % (col_dict['Marked']), 'd1.%s' % (col_dict['Sentence Type']), 'd1.%s' % (col_dict['Start Time']), 'd1.%s' % (col_dict['Stop Time']), 'd2.id', 'd2.%s' % (col_dict['Start Time']), 'd2.%s' % (col_dict['Stop Time']), 'd2.%s' % (col_dict['Speaker']), 'd1.%s' % (col_dict['Filename']) ], where_cond="d1.%s = 'M'" % (col_dict['Speaker']), params=[lag_cutoff]) PraatInterop.open_praat() prev_wav_filename = None for cur_row in rows: m_id, marked, m_sentence_type, m_start, m_end, b_id, b_start, b_end, b_speaker, filename = cur_row wav_filename = cur_wav_dir + '\\' + os.path.basename( filename)[:-5] + '.wav' if wav_filename != prev_wav_filename: PraatInterop.send_commands( ['Open long sound file... %s' % (wav_filename)]) prev_wav_filename = wav_filename m_min_pitch, m_max_pitch, m_mean_pitch = get_praat_vals( m_start, m_end, wav_filename) update_freq_val(db, m_min_pitch, 'm_min_pitch', m_id) update_freq_val(db, m_max_pitch, 'm_max_pitch', m_id) update_freq_val(db, m_mean_pitch, 'm_mean_pitch', m_id) update_pitch_delta(db, m_max_pitch, m_min_pitch, 'm_pitch_delta', m_id) if m_sentence_type == 'Q': q_type = 'Y/N' if bool(marked) else 'WH Question' update_question_type(db, q_type, col_dict['Question Type'], m_id) if b_speaker: b_min_pitch, b_max_pitch, b_mean_pitch = get_praat_vals( b_start, b_end, wav_filename) update_freq_val(db, b_min_pitch, 'b_min_pitch', m_id) update_freq_val(db, b_max_pitch, 'b_max_pitch', m_id) update_freq_val(db, b_mean_pitch, 'b_mean_pitch', m_id) update_pitch_delta(db, b_max_pitch, b_min_pitch, 'b_pitch_delta', m_id) #freq #update_responding_speaker(db, r_speaker, col_dict['Responding Speaker'], r_id) PraatInterop.close_praat()
def populate_calced_cols(db, col_dict): rows = db.select( '%s d1, %s d2' % (CSVDatabase.TABLE_NAME, CSVDatabase.TABLE_NAME), ['d1.id', 'd1.%s' % (col_dict['Start Time']), 'd1.%s' % (col_dict['Stop Time']), 'd2.id', 'd2.%s' % (col_dict['Start Time']), 'd2.%s' % (col_dict['Stop Time']), 'd1.%s' % (col_dict['Filename']) ], "d1.%s = d2.%s AND d1.id = d2.id - 1 AND d1.%s = 'M' AND d2.%s = 'B' AND d1.%s <= ?" % (col_dict['Filename'], col_dict['Filename'], col_dict['Speaker'], col_dict['Speaker'], col_dict['Lag Time']), [lag_cutoff] ) update_question_type(db, col_dict) PraatInterop.open_praat() prev_wav_filename = None for cur_row in rows: m_id, m_start, m_end, b_id, b_start, b_end, filename = cur_row wav_filename = wav_dir + '\\' + os.path.basename(filename)[:-5] + '.wav' if wav_filename != prev_wav_filename: PraatInterop.send_commands([ 'Open long sound file... %s' % (wav_filename) ]) prev_wav_filename = wav_filename m_pt1_time, m_pt1_pitch, m_pt2_time, m_pt2_pitch, m_min_pitch, m_max_pitch, m_mean_pitch = get_praat_vals(m_start, m_end, wav_filename) b_pt1_time, b_pt1_pitch, b_pt2_time, b_pt2_pitch, b_min_pitch, b_max_pitch, b_mean_pitch = get_praat_vals(b_start, b_end, wav_filename) #pitch update_pitch_val(db, m_pt1_pitch, m_id, 'pt1_pitch') update_pitch_val(db, m_pt2_pitch, m_id, 'pt2_pitch') update_pitch_val(db, b_pt1_pitch, b_id, 'pt1_pitch') update_pitch_val(db, b_pt2_pitch, b_id, 'pt2_pitch') m_slope_name = update_pitch_delta_name(db, m_pt1_pitch, m_pt2_pitch, m_id) b_slope_name = update_pitch_delta_name(db, b_pt1_pitch, b_pt2_pitch, b_id) update_pitch_slope_match(db, m_id, b_id, m_slope_name, b_slope_name) #freq update_freq_val(db, m_min_pitch, 'min_pitch', m_id) update_freq_val(db, m_max_pitch, 'max_pitch', m_id) update_freq_val(db, m_mean_pitch, 'mean_pitch', m_id) update_freq_val(db, b_min_pitch, 'min_pitch', b_id) update_freq_val(db, b_max_pitch, 'max_pitch', b_id) update_freq_val(db, b_mean_pitch, 'mean_pitch', b_id) PraatInterop.close_praat()
def _open_in_praat(self, headers, treeview): start, end = self._get_sel_row_clip_info(headers, treeview) if self.wav_filename and start != None and end != None: PraatInterop.open_praat() PraatInterop.send_commands(PraatInterop.get_open_clip_script(start, end, self.wav_filename))
def _open_praat(self): start_time, end_time = self._get_bounds(include_context=True) PraatInterop.open_praat() PraatInterop.send_commands( PraatInterop.get_open_clip_script(start_time, end_time, self.check.wav_filename))
def filter_batch(db, batch, batch_num): batch_dir = 'batch%d/' % (batch_num) if not os.path.exists(wav_out_dir + batch_dir): os.mkdir(wav_out_dir + batch_dir) placeholders = '(%s)' % (','.join(['?'] * len(batch))) rows = db.select('clips', ['id', 'Filename', 'Start_Time', 'Stop_Time'], where_cond='Filename in %s' % (placeholders), params=batch) filename_dict = OrderedDict() random.shuffle(rows) for i in range(len(rows)): id, filename, start_time, stop_time = rows[i] if not filename in filename_dict: filename_dict[filename] = [] filename_dict[filename].append( (id, i + 1, start_time, stop_time)) #order numbers start at 1 PraatInterop.open_praat() for i in range(len(filename_dict)): csv_filename = filename_dict.keys()[i] bounds_list = filename_dict[csv_filename] file_code = csv_filename[:-5] wav_filename = '%s.wav' % (file_code) age = get_file_age(db, csv_filename) age_dir = '%d mo/' % (age) print '\tFiltering file %s%s' % (age_dir, wav_filename) PraatInterop.send_commands([ 'Open long sound file... %s%s%s' % (wav_in_dir, age_dir, wav_filename) ]) for j in range(len(bounds_list)): id, order_num, start_time, stop_time = bounds_list[j] sys.stdout.write('\r\t\tProcessing clip %d of %d' % (j + 1, len(bounds_list))) sys.stdout.flush() #print '%s%s%s_%d-%d.wav' % (wav_out_dir, batch_dir, file_code, age, order_num), # PraatInterop.send_commands([ # 'Extract part... %f %f yes' % (start_time, stop_time), # 'Filter (pass Hann band)... %d %d %d' % (filter_from, filter_to, filter_smoothing), # 'Get maximum...', # 'Get minimum...', # 'Multiply... %f' % (amplitude_factor), # 'Save as WAV file... %s%s%s_%d-%d.wav' % (wav_out_dir, batch_dir, file_code, age, order_num), # 'select Sound %s' % (file_code + '_band'), # 'Remove', # 'select Sound %s' % (file_code), # 'Remove', # 'select LongSound %s' % (file_code), # ]) serversocket = PraatInterop.create_serversocket() PraatInterop.send_commands( PraatInterop.get_low_pass_filter_script( wav_filename, '%s%s%s_%d-%d.wav' % (wav_out_dir, batch_dir, file_code, age, order_num), file_code, start_time, stop_time, filter_from, filter_to, filter_smoothing)) db.update('clips', ['Batch_Num', 'Batch_Order'], where_cond='id = ?', params=[batch_num, order_num, id]) PraatInterop.send_commands([ 'Remove', ]) print '' PraatInterop.close_praat()