Exemple #1
0
def get_praat_vals(start, end, wav_filename):
    socket = PraatInterop.create_serversocket()

    PraatInterop.send_commands([
        'Extract part... %f %f yes' % (start, end),
    ])

    #PraatInterop.send_commands( PraatInterop.get_octave_corrected_pitch_script() )
    PraatInterop.send_commands(
        PraatInterop.get_pitch_sample_vals_script(start, end, wav_filename))
    pt1_time, pt1_pitch, pt2_time, pt2_pitch, min_pitch, max_pitch, mean_pitch = PraatInterop.socket_receive(
        socket)

    wav_object_name = (os.path.basename(wav_filename)[:-4])
    PraatInterop.send_commands([
        #'Remove', #pitch
        'select Sound %s' % (wav_object_name),
        'Remove',
        'select LongSound %s' % (wav_object_name),
    ])

    return (
        float_or_none(pt1_time),
        float_or_none(pt1_pitch),
        float_or_none(pt2_time),
        float_or_none(pt2_pitch),
        float_or_none(min_pitch),
        float_or_none(max_pitch),
        float_or_none(mean_pitch),
    )
Exemple #2
0
    def _close_praat(self):
        socket = PraatInterop.create_serversocket()
        PraatInterop.send_commands(
            PraatInterop.get_sel_bounds_script(self.check.wav_filename))
        start_time, end_time = PraatInterop.socket_receive(socket)
        socket.close()
        PraatInterop.close_praat()

        if start_time != end_time:  #make sure something was selected
            #update the inputs in the UI
            start_time = str(round(float(start_time), 3))
            end_time = str(round(float(end_time), 3))

            self.w_form.user_start_entry.set_text(start_time)
            self.w_form.user_end_entry.set_text(end_time)
Exemple #3
0
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()