def load_backgrounds(data): backgrounds = [] background_paths = data['backgroundSlices'] logger.info("input: %s", background_paths) for background_path in background_paths: backgrounds.append(open_audio(background_path)) return backgrounds
def load_all_waves(root): audios = [] for path, dirs, filenames in os.walk(root): for filename in filenames: if filename.endswith("mp3"): full_path = path + "/" + filename audio = open_audio(full_path) audios.append((full_path, audio)) return audios
def slice_sound(path, duration_sec=MIN_BACK_DURATION_SEC): res = [] try: sound = open_audio(path).split_to_mono()[0] total_duration = len(sound) duration_millis = duration_sec * 1000 for i in range(0, total_duration, duration_millis): target = "1-" + str(i) + ".wav" end = i+duration_millis-1 if i+duration_millis-1 < total_duration else total_duration buf = sound[i:end] buf.export(out_f=target, format="wav").close() res.append(target) except FileNotFoundError as e: logger.error("file:{path} not found".format(path=path)) except Exception as e: logger.error("exception occurs : {e}".format(e=e)) return res
def setUp(self): self.background: AudioSegment = open_audio( 'test-asset/raw-data/backgrounds/1.mp3') self.activate: AudioSegment = open_audio( 'test-asset/raw-data/activates/1_2.wav')
def process(data): segment = open_audio(data['filePath']) x = fit_audio(segment) predictions = predict(x) return make_output(segment, predictions)