コード例 #1
0
 def get_recording(self, file_name):
     '''
     This reads the song's wave data into recording, which gets returned
     INPUT: file_name = string, name of wav file
     OUTPUT: recording = 2d numpy float array of song data in time domain;
     sample_rate = float, sampling rate of song
     '''
     song_name = Globals.getSongDir() + "\\" + file_name
     sample_rate, recording = wavfile.read(song_name)
     return sample_rate, recording
コード例 #2
0
 def get_recording(self, file_name):
     '''
     This reads the song's wave data into recording, which gets returned
     INPUT: file_name = string, name of wav file
     OUTPUT: recording = 2d numpy float array of song data in time domain;
     sample_rate = float, sampling rate of song
     '''
     song_name = Globals.getSongDir() + "\\" + file_name
     sample_rate, recording = wavfile.read(song_name)
     return sample_rate, recording
コード例 #3
0
 def write_pre_labels(self):
     '''
     This loads all of the song names in the song directory
     and creates a csv called pre_labels where each song will be 
     manually labeled. the resulting file should be saved as labels.csv 
     INPUT: NONE
     OUTPUT: NONE
     '''
     song_dir = Globals.getSongDir()
     file_list = [f for f in listdir(song_dir) if isfile(join(song_dir, f))]
     read_count = 0
     song_names = []
     for file_name in file_list:
         if ".wav" not in file_name:
             break
         read_count += 1
         song_names.append(file_name)
     self.write_pre_labels_to_csv(song_names, Globals.getLabelsDir())
コード例 #4
0
 def convert_all(self):
     '''
     This function can be thought of as the main, where all
     song wav data is converted. nothing is returned
     INPUT: NONE
     OUTPUT: NONE
     '''
     self.delete_files()
     song_dir = Globals.getSongDir()
     file_list = [f for f in listdir(song_dir) if isfile(join(song_dir, f))]
     read_count = 0
     incr = 1
     '''Begin conversion of all songs'''
     for file_name in file_list:
         if read_count > self.files_read_count:
             break
         if ".wav" not in file_name:
             break
         song_position = 1
         cycles = 0
         '''get the .wave recording using numpy functionality'''
         sample_rate, recording = self.get_recording(file_name)
         '''
         This while loop breaks only when the cycles condition 
         below is reached. the code allows for the song to be analyzed 
         in separate segments, but for now we just work with one segment
         as noted by the cycles > 0 termination condition.  
         the best way to solve this problem is to analyze the song as
         multiple segments, where each segment is individually listened 
         to by a human and classified manually.  This adds 
         a level of diversification to modeling songs.  I did not get 
         around to multiple song feature rows per song so here we
         just output one feature row per song for simplicity
         '''
         while 1 == 1:
             self.song_begin = float(song_position * 30)
             self.song_end = float(self.song_begin + 90)
             try:
                 '''split the song into .05 second segments'''
                 segments =\
                 self.get_segments_temporally(file_name, sample_rate, recording)
                 '''get all of the song's feature row data'''
                 song_data, column_labels = \
                 self.convert_one(file_name, self.segment_length, sample_rate, segments, recording)
                 print file_name
             except Exception, e:
                 print e
                 break
             '''
             write one feature row for this part of the 
             song using write_data_to_csv
             '''
             '''
             ZULU6FOX6TROT is nothing but a delimiter 
             to ease splitting later on
             '''
             self.write_data_to_csv(song_data,\
             file_name.split(".wav")[0]+"ZULU6FOX6TROT" +str(int(self.song_begin))\
             + str(int(self.song_end)), self.labels[file_name], column_labels)
             song_position += incr
             cycles += 1
             if cycles > 0:
                 break
         read_count += 1
コード例 #5
0
 def convert_all(self):
     '''
     This function can be thought of as the main, where all
     song wav data is converted. nothing is returned
     INPUT: NONE
     OUTPUT: NONE
     '''
     self.delete_files()
     song_dir = Globals.getSongDir()
     file_list = [f for f in listdir(song_dir) if isfile(join(song_dir, f))]
     read_count = 0
     incr = 1
     '''Begin conversion of all songs'''
     for file_name in file_list:
         if read_count > self.files_read_count:
             break
         if ".wav" not in file_name:
             break
         song_position = 1
         cycles = 0
         '''get the .wave recording using numpy functionality'''
         sample_rate, recording = self.get_recording(file_name)
         '''
         This while loop breaks only when the cycles condition 
         below is reached. the code allows for the song to be analyzed 
         in separate segments, but for now we just work with one segment
         as noted by the cycles > 0 termination condition.  
         the best way to solve this problem is to analyze the song as
         multiple segments, where each segment is individually listened 
         to by a human and classified manually.  This adds 
         a level of diversification to modeling songs.  I did not get 
         around to multiple song feature rows per song so here we
         just output one feature row per song for simplicity
         '''
         while 1==1:
             self.song_begin = float(song_position * 30)
             self.song_end = float(self.song_begin + 90)
             try:
                 '''split the song into .05 second segments'''
                 segments =\
                 self.get_segments_temporally(file_name, sample_rate, recording)
                 '''get all of the song's feature row data'''
                 song_data, column_labels = \
                 self.convert_one(file_name, self.segment_length, sample_rate, segments, recording)  
                 print file_name
             except Exception, e:
                 print e
                 break
             '''
             write one feature row for this part of the 
             song using write_data_to_csv
             '''
             '''
             ZULU6FOX6TROT is nothing but a delimiter 
             to ease splitting later on
             '''
             self.write_data_to_csv(song_data,\
             file_name.split(".wav")[0]+"ZULU6FOX6TROT" +str(int(self.song_begin))\
             + str(int(self.song_end)), self.labels[file_name], column_labels)
             song_position += incr
             cycles += 1
             if cycles > 0:
                 break 
         read_count += 1