Пример #1
0
def extract_examples(relative_path='..\\..\\PreppedUIowa v1.1\\'):
    """
    Opens all files from the given directory and subdirectories of the dataset.
    Maps the examples of instruments to the name of the instrument.
    Works only with PCM .wav files.

    :param relative_path: Relative path to the directory containing all example files.
    :return: An array of keys and an array of corresponding spectra. An array of all possible keys.
    """

    i_keys = []
    i_specs = []
    keys = []

    types = os.listdir(relative_path)
    print types
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    # For each type get instruments.
    for t in types:
        # Define filepath for reading data
        i_path = os.path.join(relative_path, t)
        instruments = os.listdir(i_path)
        print ('\n' + t)
        print '-------------------------------------------------------------------'

        # For each instrument get files.
        for i in instruments:
            # Add to the key array.
            keys.append(i)
            # Define filepath for reading data
            f_path = os.path.join(i_path, i)
            files = os.listdir(f_path)
            print('' + f_path)

            # For each file of this instrument.
            for f in files:
                # Define filepath for reading data
                s_path = os.path.join(f_path, f)
                sound_file = of.open_wav(s_path, 0)
                #print('\t> ' + f)

                # Array of FvPs to be mapped to this instrument.
                values = []
                # Sliding window, 200 samples wide.
                get_freqs(sound_file, values)
                # Pair each value with instrument.
                for v in values:
                    i_keys.append(i)
                    nv = np.array(v)
                    #nv = nv.reshape(nv.shape[0],1)
                    i_specs.append(nv)

    print '\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    print '\nExtraction finished successfully!'

    return i_keys, i_specs, keys
Пример #2
0
    def askopenfilename(self):

        """Returns an opened file in read mode.
        This time the dialog just returns a filename and the file is opened by your own code.
        """

        # get filename
        path = tkFileDialog.askopenfilename(**self.file_opt)

        # open file on your own
        if path:
            self.results_text.delete('1.0', Tkinter.END)
            results = ''
            wav = op.open_wav(path, 0)
            results = tst.test(wav, 1)
            output = tst.prepare_output(path, results)
            self.results_text.insert('1.0', output)
Пример #3
0
# For each type get instruments.
for t in types:
    i_path = os.path.join(read_path, t)
    instruments = os.listdir(i_path)
    print t
    #print instruments
    print '-------------------------------------------------------------------'

    #For each instrument get files.
    for i in instruments:
        f_path = os.path.join(i_path, i)
        files = os.listdir(f_path)

        m_path = os.path.join(f_path, 'mono')
        os.mkdir(m_path)

        print('\n' + f_path)
        print '...................................................................'

        #For each file
        for f in files:
            new_f = f.replace('stereo', 'mono')
            if('Piano' in f):
                new_f = f.replace('Piano', 'Piano.mono')

            print(f + '\t\t->\t\t' + new_f)

            s_path = os.path.join(f_path, f)
            sound_file = of.open_wav(s_path, 0)
            trim = ts.trim(sound_file)
            sv.new_wav(trim, f_path, new_f)