From 929d650400ecaef4f705f4a9dfeb760aba398e7b Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 4 Jan 2019 17:07:58 -0800 Subject: [PATCH] Add filename arg to decoder dtmf-decoder.py can now be called dynamically by specifying the name of the dtmf wav file to decode. --- dtmf-decoder.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dtmf-decoder.py b/dtmf-decoder.py index 709d271..e85dcfa 100644 --- a/dtmf-decoder.py +++ b/dtmf-decoder.py @@ -3,10 +3,21 @@ The wave file is split into bins and each bin is analyzed for all the DTMF frequencies. The method run() will return a numeric representation of the DTMF tone. + +USAGE: +python dtmf-decoder.py filename + +Will decode and print the dtmf tones found in the wav file "filename" + +Example: +python dtmf-decoder.py dtmf.wav + ''' import wave import struct import math +import sys + class pygoertzel_dtmf: def __init__(self, samplerate): self.samplerate = samplerate @@ -93,7 +104,7 @@ def run(self, sample): return self.__get_number(freqs) if __name__ == '__main__': # load wav file - wav = wave.open('/home/michael/Downloads/dtmf.wav', 'r') + wav = wave.open(sys.argv[1], 'r') (nchannels, sampwidth, framerate, nframes, comptype, compname) = wav.getparams() frames = wav.readframes(nframes * nchannels) # convert wave file to array of integers