diff --git a/analyze.py b/analyze.py index cdd2f45d..7a5a7919 100644 --- a/analyze.py +++ b/analyze.py @@ -52,6 +52,12 @@ def saveResultFile(r: dict[str, list], path: str, afile_path: str): # Write header out_string += header + # Read native sample rate + high_freq = audio.get_sample_rate(afile_path) / 2 + + if high_freq > cfg.SIG_FMAX: + high_freq = cfg.SIG_FMAX + # Extract valid predictions for every timestamp for timestamp in getSortedTimestamps(r): rstring = "" @@ -65,8 +71,8 @@ def saveResultFile(r: dict[str, list], path: str, afile_path: str): selection_id, start, end, - 150, - 15000, + cfg.SIG_FMIN, + high_freq, cfg.CODES[c[0]] if c[0] in cfg.CODES else c[0], label.split("_", 1)[-1], c[1], diff --git a/audio.py b/audio.py index 853df91f..d2e0b273 100644 --- a/audio.py +++ b/audio.py @@ -29,6 +29,11 @@ def openAudioFile(path: str, sample_rate=48000, offset=0.0, duration=None): return sig, rate +def get_sample_rate(path: str): + import librosa + return librosa.get_samplerate(path) + + def saveSignal(sig, fname: str): """Saves a signal to file.