def play_offset(path, offset, duration): """ Play only part of the given mp3 file. Return True if the whole clip played. """ with audio.cropped(path, offset, duration) as clip: return audio.play_mp3(clip)
def _play(self): s = self.segment filename = sample_filename(s.sample) basename = path.basename(filename) print('{0} ({1} at {2} -> {3})'.format( self.language_names[s.sample['language']], basename, s.offset, s.offset + s.duration, )) with audio.cropped(filename, s.offset, s.duration) as clip: return audio.play_mp3(clip)
def make_clip(sample, annotation): source_file = 'samples/{language}/{language}-{checksum}.mp3'.format( language=sample['language'], checksum=sample['checksum'], ) dest_file = ('samples/_annotated/{language}/{language}-' '{checksum}-{offset}-{end}.mp3'.format( language=sample['language'], checksum=sample['checksum'], offset=annotation['offset'], end=annotation['offset'] + annotation['duration'], )) print(dest_file) if os.path.exists(dest_file): return parent_dir = os.path.dirname(dest_file) if not os.path.isdir(parent_dir): os.mkdir(parent_dir) with audio.cropped(source_file, annotation['offset'], annotation['duration']) as temp_file: shutil.copy(temp_file, dest_file)