Skip to content

Instantly share code, notes, and snippets.

@johann8384
Created January 1, 2019 17:37
Show Gist options
  • Save johann8384/900b64e8b9d4f7d3aac92edc91066566 to your computer and use it in GitHub Desktop.
Save johann8384/900b64e8b9d4f7d3aac92edc91066566 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import logging
import sys
import os
from twotonedecoder import DetectTones
logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s] %(levelname)-11s %(message)s')
logger = logging.getLogger('tone_detect')
if len(sys.argv) > 1:
FILE_TO_ENCODE=sys.argv[1]
else:
logger.error("no wave file provided")
sys.exit(1)
logger.debug("file to encode: %s", FILE_TO_ENCODE)
def touch(fname, times=None):
with open(fname, 'a'):
os.utime(fname, times)
WAV_FILE=os.path.basename(FILE_TO_ENCODE)
logger.debug("WAV_FILE: %s", WAV_FILE)
toneDetector = DetectTones()
## Return Nagios style status codes:
## 0 - No Tone Detected
## 1 - Possible Unidentified Tone Detected
## 2 - Identified Tone Detected
## 3 - Unknown/Something Weird Happened
exit(toneDetector.detectWaveFile(FILE_TO_ENCODE))
@johann8384
Copy link
Author

Works with Trunk Recorder to detect tones on the tranmissions.

Jan 1 11:46:24 medrc-recorder-1 recorder[2199]: [2019-01-01 11:46:24.007254] (info) [stclairco]#011TG: 7236#011Freq: 8.520875e+08#011Ending Recorded Call - Last Update: 6s#011Call Elapsed: 33
Jan 1 11:46:24 medrc-recorder-1 recorder[2199]: [2019-01-01 11:46:24.007521] (info) Running upload script: ./encode_upload.py /tmp/capture/stclairco/2019/1/1/7236-1546364751_8.527e+08.wav &
Jan 1 11:46:24 medrc-recorder-1 recorder[2199]: [2019-01-01 11:46:24,418] WARNING possible unidentified dispatch [369.0, 362.0]
Jan 1 11:46:24 medrc-recorder-1 recorder[2199]: [2019-01-01 11:46:24,418] WARNING Tone Detector Returned: 1
Jan 1 11:46:24 medrc-recorder-1 recorder[2199]: [2019-01-01 11:46:24,470] INFO Sending [7236] Belleville Police Dispatch to /var/run/liquidsoap/belleville.sock
Jan 1 11:46:24 medrc-recorder-1 recorder[2199]: [2019-01-01 11:46:24,475] INFO Sending [7236] Belleville Police Dispatch to /var/run/liquidsoap/scclaw.sock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment