Skip to content

Commit

Permalink
bumped to version 1.4
Browse files Browse the repository at this point in the history
added arguments to detect_test.py so arguments can be passed directly
  • Loading branch information
TheGreatCodeholio committed May 23, 2024
1 parent 66368a5 commit e1bef1d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
44 changes: 35 additions & 9 deletions examples/detect_test.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "icad_tone_detection"
version = "1.3"
version = "1.4"
authors = [
{name = "TheGreatCodeholio", email = "[email protected]"},
]
Expand Down
13 changes: 12 additions & 1 deletion src/icad_tone_detection/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e1bef1d

Please sign in to comment.