Skip to content

James-P-D/ToneDecoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToneDecoder

Decoder for DTMF (and other MF signals) in Python

Screenshot

Introduction

Small Python script for decoding DTMF tones from .WAV files.

Requirements

pip install numpy
pip install scipy
pip install argparse
pip install csv

Usage

Running the program with the -h argument will produce the following:

C:\ToneDecoder\>python.exe main.py -h
usage: main.py [-h] [-f FRAME_MS] [-pf PEAK_FACTOR] [-st SILENCE_THRESHOLD] [-nts] filename csv_files [csv_files ...]

DTMF decoder

positional arguments:
  filename              Path to the input .WAV file
  csv_files             One or more CSV file(s)

options:
  -h, --help            show this help message and exit
  -f FRAME_MS, --frame_ms FRAME_MS
                        Frame rate in ms (integer, optional. Default=50)
  -pf PEAK_FACTOR, --peak_factor PEAK_FACTOR
                        Peak factor (float, optional. Default=0.1)
  -st SILENCE_THRESHOLD, --silence_threshold SILENCE_THRESHOLD
                        Silence threshold (float, optional. Default=0.02)
  -nts, --no_time_stamp
                        Flag to disable timestamps (default: False)

We can then check the file perfect-example.wav against the dtmf.csv file:

C:\ToneDecoder\>python.exe main.py perfect-example.wav dtmf.csv
00:00:00.000000000 -> 0
00:00:00.200000000 -> 1
00:00:00.400000000 -> 2
00:00:00.600000000 -> 3
00:00:00.800000000 -> 4
00:00:01.000000000 -> 5
00:00:01.200000000 -> 6
00:00:01.400000000 -> 7
00:00:01.600000000 -> 8
00:00:01.800000000 -> 9

Note however, that results may not be so perfect without clear audio. For example, attempting to decode not-perfect-example.wav we get:

C:\ToneDecoder\>python.exe main.py not-perfect-example.wav dtmf.csv
00:00:00.400000000 -> *
00:00:00.700000000 -> 7
00:00:00.750000000 -> 3
00:00:00.850000000 -> 7
00:00:00.900000000 -> D
00:00:00.950000000 -> 0
00:00:01.250000000 -> 6
00:00:01.500000000 -> B
00:00:01.550000000 -> 2
00:00:01.600000000 -> 1
00:00:01.650000000 -> 2
00:00:01.700000000 -> 7
00:00:01.750000000 -> #
00:00:01.800000000 -> 7
00:00:01.850000000 -> 4
00:00:02.050000000 -> 9
00:00:02.250000000 -> 2
00:00:02.400000000 -> 5
00:00:02.550000000 -> 8
00:00:02.600000000 -> *
00:00:02.650000000 -> C
00:00:02.700000000 -> D
00:00:02.750000000 -> 9
00:00:02.800000000 -> 7
00:00:02.850000000 -> 8
00:00:02.900000000 -> 1
00:00:02.950000000 -> A
00:00:03.000000000 -> 3
00:00:03.050000000 -> 6
00:00:03.100000000 -> #
00:00:03.150000000 -> 3
00:00:03.300000000 -> D
00:00:03.350000000 -> 8
00:00:03.400000000 -> 2
00:00:03.450000000 -> *
00:00:03.900000000 -> 8
00:00:03.950000000 -> 4
00:00:04.250000000 -> 7
00:00:04.300000000 -> 8
00:00:04.350000000 -> 5
00:00:04.450000000 -> 8
00:00:04.500000000 -> 5
00:00:04.700000000 -> #
00:00:04.800000000 -> 5
00:00:04.850000000 -> 8
00:00:04.900000000 -> C
00:00:05.000000000 -> 2
00:00:05.050000000 -> 6
00:00:05.250000000 -> 9
00:00:05.300000000 -> 6
00:00:05.350000000 -> 9
00:00:05.400000000 -> #
00:00:05.550000000 -> D
00:00:05.800000000 -> *
00:00:05.850000000 -> 7
00:00:05.900000000 -> 8
00:00:05.950000000 -> 7
00:00:06.050000000 -> C
00:00:06.100000000 -> *
00:00:06.150000000 -> 7
00:00:06.600000000 -> #
00:00:06.800000000 -> 8
00:00:06.950000000 -> C
00:00:07.050000000 -> D
00:00:07.100000000 -> 9
00:00:07.350000000 -> 8
00:00:07.450000000 -> *
00:00:07.500000000 -> 9
00:00:07.700000000 -> #
00:00:07.750000000 -> 9
00:00:07.800000000 -> D
00:00:07.850000000 -> 7
00:00:07.950000000 -> 0
00:00:08.000000000 -> 8
00:00:08.050000000 -> 7
00:00:08.200000000 -> 0
00:00:08.250000000 -> 9
00:00:08.300000000 -> 0
00:00:08.350000000 -> #
00:00:08.450000000 -> *
00:00:08.500000000 -> #
00:00:08.600000000 -> 3
00:00:08.650000000 -> 9
00:00:08.750000000 -> 0

If we try adjusting the frame-rate and peak-factor we get:

C:\ToneDecoder\>python.exe main.py not-perfect-example.wav dtmf.csv -f 100 -pf 0.4
00:00:00.900000000 -> 0
00:00:01.500000000 -> 1
00:00:02.200000000 -> 2
00:00:02.900000000 -> 3
00:00:03.900000000 -> 4
00:00:04.300000000 -> 5
00:00:05.000000000 -> 6
00:00:05.900000000 -> 7
00:00:06.800000000 -> 8
00:00:07.600000000 -> 9

If we do not wish to see the timestamp, we can use the -nts flag. So for example we decoding audiocheck.net_dtmf_123A456B789C_0#D.wav we get:

C:\ToneDecoder\>python.exe main.py audiocheck.net_dtmf_123A456B789C_0#D.wav dtmf.csv
123A456B789C*0#D

Finally, in addition to the dtmf.csv file there a ccitt5.csv file for CCITT-5 tones, and us_red_box.csv for US Red Box tones.

About

Decoder for DTMF (and other MF signals) in Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages