Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_audio(audio_file, sample_rate):
"""Reads the audio file using Essentia."""
audio = ES.MonoLoader(filename=audio_file,
sampleRate=sample_rate)()
return audio
"""
# Makes sure the output features folder exists
utils.ensure_dir(OUTPUT_FEATURES)
features_file = os.path.join(OUTPUT_FEATURES,
os.path.basename(audio_file) + ".json")
# If already precomputed, read and return
if os.path.exists(features_file):
with open(features_file, "r") as f:
features = json.load(f)
return list_to_array(features)
# Load Audio
logging.info("Loading audio file %s" % os.path.basename(audio_file))
audio = ES.MonoLoader(filename=audio_file, sampleRate=SAMPLE_RATE)()
duration = len(audio) / float(SAMPLE_RATE)
# Estimate Beats
features = {}
ticks, conf = compute_beats(audio)
ticks = np.concatenate(([0], ticks, [duration])) # Add first and last time
ticks = essentia.array(np.unique(ticks))
features["beats"] = ticks.tolist()
# Compute Beat-sync features
features["mfcc"], features["hpcp"], features["tonnetz"] = \
compute_beatsync_features(ticks, audio)
# Save output as audio file
if audio_beats:
logging.info("Saving Beats as an audio file")
def __init__(self, audio_file, mono=True, sample_rate=44100, normalize_gain=False):
""""""
self.fs = sample_rate
if normalize_gain:
self.audio_vector = estd.EasyLoader(filename=audio_file, sampleRate=self.fs, replayGain=-9)()
else:
self.audio_vector = estd.MonoLoader(filename=audio_file, sampleRate=self.fs)()
print "== Audio vector of %s loaded with shape %s and sample rate %s ==" % (audio_file, self.audio_vector.shape, self.fs)
return