This blog post talks about how to decode DTMF from WAV files with Keypad Mapping.
Introduction
For context, this mini customization spawned because of this month’s CSIT Mini Challenge. There was WAV file with a flag embedded into the audio. It happens that the audio resembles DTMF.
A quick google search shows a few open-sourced projects and even web applications that takes in an audio file and helps you decode it. However, most of it is’nt very useful and give incorrect results.
Those that managed to correctly translate from WAV with DTMF into digits and symbols, were not able satisfy the condition to retrieve the flag. To solve this particular challenge, I forked ribt’s github project “dtmf-decoder” and added a decoder with the keypad mapping. Please free feel to use it at my github page here 🔗. Heres a quick snippet of the key logic that converts the DTMF results into what we need.
keypad = {
"2": "ABC",
"3": "DEF",
"4": "GHI",
"5": "JKL",
"6": "MNO",
"7": "PQRS",
"8": "TUV",
"9": "WXYZ"
}
def decode_sequence(sequence: str) -> str:
parts = sequence.split("#")
decoded = []
for part in parts:
if len(part) != 2: # must be 2 digits
continue
digit, index = part[0], int(part[1])
...