Ejemplo n.º 1
0
import matplotlib.pyplot as plt

from FishRecording import *
from Auxiliary import *

if __name__ == '__main__':

    if not 3 >= len(sys.argv) >= 2:  # only if len(sys.argv) == 2 or 3, the codes continues running.
        print("\nI need an audiofile as first argument. Please give me the path + filename as argument! "
              "Then you can tell me the folder name you wish me to save the figures in, as a second argument "
              "(don't use any '/'). Only of you like though.\n")
        sys.exit(2)
    # Load, convert and process the audiofile
    audio_file = sys.argv[1]
    modfile = conv_to_single_ch_audio(audio_file)
    fish = FishRecording(modfile)

    # detect best window
    w_start, w_width = fish.detect_best_window()

    # define save path and create the plots with the best window
    if len(sys.argv) == 3:
        folder_name = sys.argv[2]
        savepath = './control_figures/best_window_detection/' + folder_name + '/'
    else:
        savepath = './control_figures/best_window_detection/'

    if not os.path.exists(savepath):
        os.mkdir(savepath)

    recording_name = '_'.join(modfile.split('.')[0].split('_')[:2]) + '.pdf'
Ejemplo n.º 2
0
    ##-------------------------------------------------##
    ##-------------------------------------------------##

    curr_file = sys.argv[1]

    try:  # ACHTUNG!! This try-clause only serves to print the error message at the end!
        base, ext = os.path.splitext(curr_file)
        base = base.split('/')[-1]
        new_mod_filename = new_dir + base + '_mod.wav'
        os.system('avconv -i {0:s} -ac 1 -y -acodec pcm_s16le {1:s}'.format(curr_file, new_dir + '/' + new_mod_filename))

        # pcm_s16le means: pcm format, signed integer, 16-bit, "little endian"

        ##### Calculate spectogram #####

        fish = FishRecording(new_dir + '/' + new_mod_filename)
        fish_file_number = re.findall(r'\d+\_', new_mod_filename)[0][:-1]
        print 5 * '============'
        if fish._time[-1] > 5.:  # This if clause skips recordings of lesser length than 10 seconds.
            pass
        else:
            print '%%% File No. ' + fish_file_number\
                  + ' was not analyzed, because the length of the recording was less than 10 seconds. %%%'
            exit()

        print '\n'
        print 'Analyzing Fish No. ' + fish_file_number + ' ...'
        current_fish = "fish" + fish_file_number
        fund_freq = fish.fund_freq
        s.append(odml.Section(current_fish, "subject"))
        s[current_fish].append(odml.Property("Audio_file", new_mod_filename))