def upload_files(): if request.method == 'POST': f = request.files['file'] fname = secure_filename(f.filename) path = os.path.join(app.config['UPLOAD_DIR'], fname) f.save(path) timbre = timbral_models.timbral_extractor(os.path.join(path)) print(timbre) return 'File upload complete (%s)' % path
def ac_timbral_models(audiofile, ac_descriptors): logger.debug('{0}: computing timbral models'.format(audiofile)) converted_filename = convert_to_wav(audiofile) try: timbre = timbral_models.timbral_extractor(converted_filename, clip_output=True, verbose=False) timbre['reverb'] = timbre['reverb'] == 1 ac_descriptors.update(timbre) except Exception as e: logger.debug('{0}: timbral models computation failed ("{1}")'.format( audiofile, e))
def process_sounds(directory): """Processes sounds using AudioCommons Timbral Models.""" result = [] paths = Path(directory).rglob("*") for path in paths: try: path_str = str(path) sound = timbral_extractor(path_str, clip_output=True) del sound["reverb"] sound["id"] = uuid1().hex sound["name"] = Path(path_str).resolve().stem sound["pack_name"] = "" sound["path"] = path_str sound["tag"] = "" sound["type"] = Path(path_str).suffix.replace(".", "") sound["verified"] = False result.append(sound) except: continue return result
import json import os from pathlib import Path import timbral_models script_directory_path = Path(__file__).resolve().parent input_directory_path = os.path.join(script_directory_path, 'mock_sounds') file_names = os.listdir(input_directory_path) for file_name in file_names: print(f"Analyzing {file_name}") result = timbral_models.timbral_extractor(os.path.join( input_directory_path, file_name), clip_output=True) output_directory_path = os.path.join(script_directory_path, './timbral_characteristics') if not os.path.exists(output_directory_path): os.makedirs(output_directory_path) file_path = os.path.join(output_directory_path, f"{Path(file_name).resolve().stem}.json") with open(file_path, "w") as file: json.dump(result, file) print(f"Result written to {file_path}")
def analysis_function(loop, sampleRate=16000): lp_filter = es.LowPass(cutoffFrequency=90, sampleRate=sampleRate) bp_filter = es.BandPass(bandwidth=20, cutoffFrequency=280, sampleRate=sampleRate) hp_filter = es.HighPass(cutoffFrequency=9000, sampleRate=sampleRate) [_, pattern] = ADT([loop], output_act='yes', tab='no', save_dir="analysis/") pattern = np.array(pattern)[0] time_audio = np.linspace(0, float(29538) / 16000, 29538) time_act = np.linspace(0, float(29538) / 16000, 160) final_pattern = np.clip( np.array([ interp1d(time_act, pattern[0, :, 0])(time_audio), interp1d(time_act, pattern[1, :, 0])(time_audio), interp1d(time_act, pattern[2, :, 0])(time_audio) ]).T, 0.0, 1.0) final_pattern = final_pattern / final_pattern.max(axis=0) final_pattern = np.expand_dims(final_pattern, 0) audio_file = es.MonoLoader(filename=loop, sampleRate=sampleRate) loop_basename = ntpath.basename(loop) lpf_audio = lp_filter(audio_file()) bpf_audio = bp_filter(audio_file()) hpf_audio = hp_filter(audio_file()) sf.write("analysis/lpf_" + loop_basename, lpf_audio, sampleRate) sf.write("analysis/bpf_" + loop_basename, bpf_audio, sampleRate) sf.write("analysis/hpf_" + loop_basename, hpf_audio, sampleRate) unordered_kick_features = timbral_models.timbral_extractor( "analysis/lpf_" + loop_basename, clip_output=True) unordered_snare_features = timbral_models.timbral_extractor( "analysis/bpf_" + loop_basename, clip_output=True) unordered_hh_features = timbral_models.timbral_extractor("analysis/hpf_" + loop_basename, clip_output=True) features_kick = [ unordered_kick_features['warmth'] / 69.738235, unordered_kick_features['roughness'] / 71.95989, unordered_kick_features['brightness'] / 82.336105, unordered_kick_features['hardness'] / 75.53646, unordered_kick_features['boominess'] / 71.00043, unordered_kick_features['depth'] / 100.0, unordered_kick_features['sharpness'] / 81.7323, ] features_snare = [ unordered_snare_features['warmth'] / 69.57681, unordered_snare_features['roughness'] / 67.66642, unordered_snare_features['brightness'] / 80.19115, unordered_snare_features['hardness'] / 71.689445, unordered_snare_features['boominess'] / 61.422714, unordered_snare_features['depth'] / 100.0, unordered_snare_features['sharpness'] / 71.406494 ] features_hh = [ unordered_hh_features['warmth'] / 32.789112, unordered_hh_features['roughness'] / 1.0, unordered_hh_features['brightness'] / 85.24432, unordered_hh_features['hardness'] / 67.71172, unordered_hh_features['boominess'] / 2.491137, unordered_hh_features['depth'] / 0.5797179, unordered_hh_features['sharpness'] / 87.83693 ] hpcp = file_to_hpcp(audio_file()) #[69.57681, 67.66642, 80.19115, 71.689445, 61.422714, 100.0, 71.406494] #[32.789112, 1.0, 85.24432, 67.71172, 2.491137, 0.5797179, 87.83693] #[69.738235, 71.95989, 82.336105, 75.53646, 71.00043, 100.0, 81.7323] return final_pattern, hpcp, features_kick, features_snare, np.clip( features_hh, 0, 1)
import timbral_models sample = '2248.wav' timbre = timbral_models.timbral_extractor(sample) print(timbre)