Exemple #1
0
    def uploadFile(self, bucket, folder, local_path, chunk_size=52428800):
        """
        Upload local_filename to bucket/folder/local_filename in bucket
        Same filename gets overwritten
        """

        source_size = os.stat(local_path).st_size
        chunk_count = int(math.ceil(source_size / float(chunk_size)))
        # local_filename = local_path.split('/')[-1]

        try:
            bucket = self.connection.get_bucket(bucket)  # select bucket
        except Exception as e:
            print('Problem getting bucket %s' % e)
            return

        if bucket:
            # create a multipart upload request
            mp = bucket.initiate_multipart_upload(os.path.basename(local_path))
            """
            try:
                key = bucket.new_key(os.path.join(folder, local_filename))
            except Exception as e:
                print('Folder %s not accessible %s'%(folder,e))

            key.set_contents_from_filename(local_path)
            """
            done = 0
            for i in range(chunk_count):
                offset = chunk_size * i
                bytes = min(chunk_size, source_size - offset)
                with FileChunkIO(local_path, 'r', offset=offset,
                                 bytes=bytes) as fp:
                    mp.upload_part_from_file(fp, part_num=i + 1)
                    done += chunk_size
                    if source_size > done:
                        ut.printStuff('Uploading file %s %%',
                                      (int(100. * done / source_size - 1)))

            mp.complete_upload()
            print('File uploaded correctly')
            print
        else:
            print('%s does not exist' % bucket)
import utils as ut

# Load sound files
path = 'data/'
sound_file_paths = [os.path.join(path, "helpme.wav"),
                    os.path.join(path, "podcast_17_sample.wav"),
                   ]

sound_names = ["helpme", "podcast_17_sample"]
raw_sounds = ut.load_sound_files(sound_file_paths)

windowsize = 6000  # size of sliding window (22050 samples == 0.5 sec)  
step       = 3000
maxfiles   = 10000
numfiles = 0

dimx = 6
dimy = 5

# create positive samples
audiosamples = raw_sounds[0]
numsamples = audiosamples.shape[0]
for x in range(0, numsamples-windowsize, step):
    numfiles +=1
    b = x               # begin 
    e = b+windowsize    # end 
    ut.printStuff('Creating spectrum image class_1 samples [%d-%d] of %d file %d',(b,e, numsamples, numfiles))
    filename = os.path.join(path, 'class_1/partial_spectrum_%d.png'%x)
    ut.specgram_frombuffer(audiosamples[b:e], dimx, dimy, fname=filename, dpi=180)
        
print('\nbye!\n')        
Exemple #3
0
image_path = path.join(config.data_dir, "images")
if not path.isdir(image_path):
	mkdir(image_path)

windowsize = 6000  # size of sliding window (22050 samples == 0.5 sec)
step = 3000
numfiles = 0

dimx = 6
dimy = 5

for i in range(len(raw_sounds)):
	# create samples
	numsamples = raw_sounds[i].shape[0]
	file_path = path.basename(sound_files[i])
	file_path = path.splitext(file_path)[0]
	for x in range(0, numsamples - windowsize, step):
		b = x               # begin
		e = x + windowsize  # end

		fmt_string = "(%d/%d) %s [%d-%d] of %d file %d"
		ut.printStuff(fmt_string, (i, len(raw_sounds) - 1, file_path, x, e, numsamples, numfiles))

		filename = path.join(image_path, "{}_{}.png".format(file_path, x))
		ut.specgram_frombuffer(raw_sounds[i][x:e], dimx, dimy, fname=filename, dpi=180)

		numfiles += 1

print('\nbye!\n')
# Load sound files
path = '/archive/ahem_data/'
sound_file_paths = [os.path.join(path, "ahem_sounds.wav"),
                    os.path.join(path, "podcast_17_sample.wav"),
                   ]

sound_names = ["ahem_sounds", "podcast_17_sample"]
raw_sounds = ut.load_sound_files(sound_file_paths)

windowsize = 6000  # size of sliding window (22050 samples == 0.5 sec)  
step       = 3000
maxfiles   = 10000
numfiles   = 0

dimx = 6
dimy = 5

# create negative samples
audiosamples = raw_sounds[1]
numsamples = audiosamples.shape[0]

for x in xrange(0, numsamples-windowsize, step):
    numfiles += 1 
    b = x               # begin 
    e = b+windowsize    # end 
    ut.printStuff('Creating spectrum image class_0 samples [%d-%d] of %d file %d',(b,e, numsamples, numfiles))
    filename = os.path.join(path, 'class_0/partial_spectrum_%d.png'%x)
    ut.specgram_frombuffer(audiosamples[b:e], dimx, dimy, fname=filename, dpi=180)
        
print('\nbye!\n')