Skip to content

Commit

Permalink
add audio duration and load metadata from file
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed Feb 10, 2025
1 parent 6e88569 commit a2b0259
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions processing/audio_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,22 @@ def process(recording, jwtKey, conf):
input_filename = temp_path / ("recording" + input_extension)
logger.debug("downloading recording to %s", input_filename)
api.download_file(jwtKey, str(input_filename))
analysis = analyse(input_filename, conf)
metadata = analyse(input_filename, conf)
new_metadata = {}

analysis = metadata.get("analysis_result")
duration = analysis.get("duration")
if duration is not None:
new_metadata["duration"] =duration
else:
duration = metadata.get("duration")
if analysis["species_identify"]:
species_identify = analysis.pop("species_identify")
for analysis_result in species_identify:
model_name = analysis_result.get("model", "Unnamed")
start_s = analysis_result["begin_s"]
end_s = analysis_result["end_s"]
x = start_s / recording["duration"]
width = end_s / recording["duration"] - x
x = start_s / duration
width = end_s / duration - x
y = 0
height = 1
position = {}
Expand Down Expand Up @@ -236,7 +241,9 @@ def analyse(filename, conf, analyse_tracks=False):
tag=conf.audio_analysis_tag,
analyse_tracks=analyse_tracks,
)
# Should change this to read from a file
with HandleCalledProcessError():
output = subprocess.check_output(command, shell=True, stderr=subprocess.PIPE)
return json.loads(output.decode("utf-8"))
subprocess.run(command, shell=True, stderr=subprocess.PIPE,timeout=conf.subprocess_timeout)
meta_f = Path(filename).with_suffix(".txt")
with meta_f.open("r") as f:
classify_info = json.load(f)
return classify_info

0 comments on commit a2b0259

Please sign in to comment.