def test_noise_and_cut(self): basename = os.path.basename(sample_noise).split('.')[0] editor = firstcut.Editor(sample_noise) editor.amplitude_clipping() editor.export('./tests/test_output/test_editor.{}'.format(basename)) editor = firstcut.Editor(sample_noise) editor.noise_reduction() editor.amplitude_clipping() editor.export( './tests/test_output/test_editor.{}.denoised'.format(basename))
def test_vis(self): basename = os.path.basename(sample_wav).split('.')[0] editor = firstcut.Editor(sample_wav) editor.plot( figure_type='signal', path_to_save='./tests/test_output/test_editor.{}.png'.format( basename))
def test_editor(self): basename = os.path.basename(sample_wav).split('.')[0] editor = firstcut.Editor(sample_wav) editor.amplitude_clipping(min_interval_sec=0.12, cutoff_ratio=0.99) editor.plot( figure_type='amplitude_clipping', path_to_save='./tests/test_output/test_cutoff.{}.png'.format( basename))
def test(self): for sample in [sample_mp3, sample_wav, sample_mov, sample_mp4]: basename = os.path.basename(sample).split('.')[0] logging.info('process {}'.format(sample)) editor = firstcut.Editor(sample) editor.amplitude_clipping(min_interval_sec=0.1, cutoff_ratio=0.75) editor.export( './tests/test_output/test_editor.{}'.format(basename))
def test(self): logging.info('process {}'.format(sample_wav)) basename = os.path.basename(sample_wav).split('.')[0] editor = firstcut.Editor(sample_wav) editor.noise_reduction(custom_noise_reference_interval=[0, 8000]) editor.plot( figure_type='noise_reduction', path_to_save='./tests/test_output/test_noise_reduction.{}.png'. format(basename)) editor.export('./tests/test_output/test_noise_reduction.{}.wav'.format( os.path.basename(basename)))
def test_iter(self): for sample in [sample_wav, sample_mp3]: logging.info('process {}'.format(sample)) basename = os.path.basename(sample).split('.')[0] editor = firstcut.Editor(sample) editor.noise_reduction() editor.plot( figure_type='noise_reduction', path_to_save= './tests/test_output/test_noise_reduction.iter.{}.png'.format( basename)) editor.export( './tests/test_output/test_noise_reduction.iter.{}.wav'.format( os.path.basename(basename)))
def _audio_clip(job_id, file_name, interval, ratio, crossfade, max_sample): """ Audio clipping function Parameter ------------ job_id: unique job id file_name: file name to process interval: min_interval_sec ratio: cutoff_ratio crossfade: crossfade_sec """ try: logging.info('validate file_name') job_status_instance.update(job_id=job_id, progress=0, status='validate file_name') basename = os.path.basename(file_name).split('.') raw_format = basename[-1] name = '.'.join(basename[:-1]) if firebase is None: # referring local file if not os.path.exists(file_name): raise ValueError('file not found: {}'.format(file_name)) path_file = file_name else: path_file = os.path.join(TMP_DIR, '{}_{}_raw.{}'.format(name, job_id, raw_format)) if not os.path.exists(path_file): msg = 'download {} from firebase to {}'.format(file_name, path_file) job_status_instance.update(job_id=job_id, status=msg) logging.info(msg) firebase.download(file_name=file_name, path=path_file) job_status_instance.update(status='start processing', job_id=job_id, progress=20) logging.info('start processing') editor = firstcut.Editor(path_file, max_sample_length=max_sample) editor.amplitude_clipping(min_interval_sec=interval, cutoff_ratio=ratio, crossfade_sec=crossfade) if editor.if_amplitude_clipping: msg = 'save tmp folder: {}'.format(TMP_DIR) job_status_instance.update(job_id=job_id, progress=70, status=msg) logging.info(msg) base_name = '{}_{}_processed'.format(name, job_id) if firebase is None: file_name = editor.export(os.path.join(TMP_DIR, base_name)) url = '' else: logging.info('upload to firebase') job_status_instance.update(job_id=job_id, progress=75, status='upload to firebase') file_name = editor.export(os.path.join(TMP_DIR, base_name)) url = firebase.upload(file_path=file_name) to_clean = os.path.join(TMP_DIR, '{}_{}_*'.format(name, job_id)) msg = 'clean local storage: {}'.format(to_clean) logging.info(msg) job_status_instance.update(job_id=job_id, progress=95, status=msg) # os.system('rm -rf {}'.format(to_clean)) else: url = '' if firebase is None else firebase.get_url(file_name) # update job status job_status_instance.complete(job_id=job_id, url=url, file_name=file_name) except Exception: job_status_instance.error(job_id=job_id, error_message=traceback.format_exc()) logging.exception('raise error')