From 936fa82974547c7b77f278b846e3a3b1db3a3474 Mon Sep 17 00:00:00 2001 From: Josef Haupt Date: Fri, 20 Oct 2023 13:05:10 +0200 Subject: [PATCH 1/2] raven table output now uses file specific frequencies --- analyze.py | 5 ++++- audio.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/analyze.py b/analyze.py index cdd2f45d..2a62f24e 100644 --- a/analyze.py +++ b/analyze.py @@ -52,6 +52,9 @@ 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 + # Extract valid predictions for every timestamp for timestamp in getSortedTimestamps(r): rstring = "" @@ -66,7 +69,7 @@ def saveResultFile(r: dict[str, list], path: str, afile_path: str): start, end, 150, - 15000, + 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. From 76aba8aa43be24be83a41d969f6887cb4c4ff34e Mon Sep 17 00:00:00 2001 From: Josef Haupt Date: Fri, 20 Oct 2023 13:28:43 +0200 Subject: [PATCH 2/2] cutoff at SIG_FMIN and SIG_FMAX --- analyze.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/analyze.py b/analyze.py index 2a62f24e..7a5a7919 100644 --- a/analyze.py +++ b/analyze.py @@ -55,6 +55,9 @@ def saveResultFile(r: dict[str, list], path: str, afile_path: str): # 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 = "" @@ -68,7 +71,7 @@ def saveResultFile(r: dict[str, list], path: str, afile_path: str): selection_id, start, end, - 150, + cfg.SIG_FMIN, high_freq, cfg.CODES[c[0]] if c[0] in cfg.CODES else c[0], label.split("_", 1)[-1],