From e1bef1d9cccee16ee331d02bf41e59eaa1910242 Mon Sep 17 00:00:00 2001 From: thegreatcodeholio Date: Thu, 23 May 2024 17:05:57 -0400 Subject: [PATCH] bumped to version 1.4 added arguments to detect_test.py so arguments can be passed directly --- examples/detect_test.py | 44 ++++++++++++++++++++++++++------- pyproject.toml | 2 +- src/icad_tone_detection/main.py | 13 +++++++++- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/examples/detect_test.py b/examples/detect_test.py index 7ba5e6d..d67a76a 100644 --- a/examples/detect_test.py +++ b/examples/detect_test.py @@ -1,16 +1,42 @@ #!/usr/bin/env python3 +import argparse import json -import sys from icad_tone_detection import tone_detect -if len(sys.argv) > 1: - audio_path = sys.argv[1] -else: - print("Requires a audio path provided. Either file path, or URL.") - exit(0) -detect_result = tone_detect(audio_path, matching_threshold=1.5, time_resolution_ms=50, debug=True) +def main(): + parser = argparse.ArgumentParser(description='Run tone detection on an audio file.') + parser.add_argument('audio_path', type=str, help='Path to the audio file') + parser.add_argument('-t', '--matching_threshold', type=float, default=2.5, help='Matching threshold percentage') + parser.add_argument('-r', '--time_resolution_ms', type=int, default=25, help='Time resolution in ms') + parser.add_argument('-a', '--tone_a_min_length', type=float, default=0.7, help='Min length of tone A in seconds') + parser.add_argument('-b', '--tone_b_min_length', type=float, default=2.7, help='Min length of tone B in seconds') + parser.add_argument('-i', '--hi_low_interval', type=float, default=0.2, + help='Max interval between hi-low tones in seconds') + parser.add_argument('-n', '--hi_low_min_alternations', type=int, default=6, + help='Min number of hi-low alternations') + parser.add_argument('-l', '--long_tone_min_length', type=float, default=3.8, + help='Min length of a long tone in seconds') + parser.add_argument('-d', '--debug', action='store_true', help='Enable debug mode') -data_dict = {"two_tone": detect_result.two_tone_result, "long_tone": detect_result.long_result, "hl_tone": detect_result.hi_low_result} + args = parser.parse_args() -print(json.dumps(data_dict)) + detect_result = tone_detect( + audio_path=args.audio_path, + matching_threshold=args.matching_threshold, + time_resolution_ms=args.time_resolution_ms, + tone_a_min_length=args.tone_a_min_length, + tone_b_min_length=args.tone_b_min_length, + hi_low_interval=args.hi_low_interval, + hi_low_min_alternations=args.hi_low_min_alternations, + long_tone_min_length=args.long_tone_min_length, + debug=args.debug + ) + + data_dict = {"two_tone": detect_result.two_tone_result, "long_tone": detect_result.long_result, + "hl_tone": detect_result.hi_low_result} + + print(json.dumps(data_dict)) + + +main() diff --git a/pyproject.toml b/pyproject.toml index 2edf69f..5de3348 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "icad_tone_detection" -version = "1.3" +version = "1.4" authors = [ {name = "TheGreatCodeholio", email = "ian@icarey.net"}, ] diff --git a/src/icad_tone_detection/main.py b/src/icad_tone_detection/main.py index 6db4057..b3c1bc6 100644 --- a/src/icad_tone_detection/main.py +++ b/src/icad_tone_detection/main.py @@ -40,7 +40,18 @@ def tone_detect(audio_path, matching_threshold=2.5, time_resolution_ms=25, tone_ matched_frequencies = FrequencyExtraction(samples, frame_rate, duration_seconds, matching_threshold, time_resolution_ms).get_audio_frequencies() if debug is True: - print("Matched frequencies: ", matched_frequencies) + debug_info = ( + f"Analyzing {audio_path} with the following settings:\n" + f"Matching Threshold: {matching_threshold}%\n" + f"Time Resolution: {time_resolution_ms}ms\n" + f"Tone A Min Length: {tone_a_min_length}s\n" + f"Tone B Min Length: {tone_b_min_length}s\n" + f"Long Tone Min Length: {long_tone_min_length}s\n" + f"Hi-Low Interval: {hi_low_interval}s\n" + f"Hi-Low Min Alternations: {hi_low_min_alternations}\n" + f"Matched frequencies: {matched_frequencies}" + ) + print(debug_info) two_tone_result = detect_two_tone(matched_frequencies, tone_a_min_length, tone_b_min_length) long_result = detect_long_tones(matched_frequencies, two_tone_result, long_tone_min_length)