Giter VIP home page Giter VIP logo

dtmf-decoder's Introduction

DTMF decoder

(Sorry for my English, I'm not dumb but French. Feel free to make a PR to correct this README.)

Have you always dreamt of finding the phone number dialled by someone in a video? It's possible now! All you have to do is record the audio of the beeps and this script will extract the phone number for you from the dial tones.

Installation

(If you are on Mac or Windows, go to hell.)

$ git clone https://github.com/ribt/dtmf-decoder.git
$ cd dtmf-decoder/
$ sudo python3 -m pip install -r requirements.txt --upgrade
$ chmod +x dtmf.py
$ sudo cp dtmf.py /usr/local/bin/dtmf

Usage

You have to give a wav file (you can try to convert it with ffmpeg -i audio.mp3 audio.wav for example).

Usage: dtmf [-h] [-v] [-l] [-r] [-d] [-t F] [-i T] file.wav

optional arguments:
  -h, --help     show this help message and exit
  -v, --verbose  show a complete timeline
  -l, --left     left channel only (if the sound is stereo)
  -r, --right    right channel only (if the sound is stereo)
  -d, --debug    show graphs to debug
  -t F           acceptable frequency error (in hertz, 20 by default)
  -i T           process by T seconds intervals (0.05 by default)

Examples

You can test this script with these examples :

The perfect case

$ dtmf perfect-example.wav
0123456789

As you can see it works perfectly, we have a classical French phone number.

The non-perfect case

$ dtmf not-perfect-example.wav
012374526789

We can guess there is a problem because we have more than ten numbers. So try the verbose output:

$ dtmf -v not-perfect-example.wav
0:00 ...................0
0:01 0..........1111.....
0:02 .....222............
0:03 33........7.......44
0:04 .......5..........2.
0:05 .66666............77
0:06 777.............888.
0:07 ..........99........
0:08 .................

We can guess there are false positives so try to decrease the tolerance:

$ dtmf -v -t 10 not-perfect-example.wav 
0:00 ...................0
0:01 0..........111......
0:02 .....222............
0:03 3..................4
0:04 .......5............
0:05 ..66.6..............
0:06 7...............88..
0:07 ...........9........
0:08 .................

The number 6 must have been split into two so the number is 0123456789.

How it works

This script is quite simple. We split the signal into frames and we analyse them one by one. We calculate a Fast Fourier Transorm to find its constituent frequencies. We find the frequencies with the bigger amplitude and we compare them with the DTMF's (dual-tone multi-frequency) frequencies.

DTMF keypad frequencies from Wikipedia:

array of dial tones' frequencies from Wikipedia

Graph explaining the functioning :

graphs

dtmf-decoder's People

Contributors

clemg avatar obitorasu avatar ribt avatar rishitsaiya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dtmf-decoder's Issues

[Question] why I got different outputs?

First of all, thank you for sharing your work. I gave it a try, but got different outputs, do you mind taking a look? Thank you!

python dtmf.py ./not-perfect-example.wav
012344556778899

python dtmf.py -t 10 ./not-perfect-example.wav
3699

python dtmf.py -v -t 10 ./not-perfect-example.wav
0:00 .........................
0:01 .........................
0:02 .........................
0:03 3........................
0:04 .........................
0:05 ..6666...................
0:06 .........................
0:07 .............9.9.........
0:08 .....................

SurDetector.pyIl y a des questions.

Bonjour, les documents suivants sont traduits en automatique。
debut = np.where(frequencies > 0)[0][0]
fin = np.where(frequencies > 1050)[0][0]
freq = frequencies[debut:fin]
amp = abs(fourier.real[debut:fin])
lf = freq[np.where(amp == max(amp))[0][0]]
delta = args.t
best = 0
for f in [695, 766, 846, 934]:
if abs(lf-f) < delta:
delta = abs(lf-f)
best = f
lf = best
En tant qu'autodidacte, il a fallu beaucoup de temps pour lire et comprendre les implications
Pouvez-vous expliquer la signification du code ci-dessus ? Merci beaucoup !

Use dtmf-decoder with the standard input instead of wav file ?

Hello @ribt , @clemg , @OBITORASU , @rishitsaiya ,

First of all, thanks for this great project!

Is there a way to read to use the dtmf-decoder with the standard input, instead of an offline wav file ?

I tried to use a named pipe (fifo) to simulate the standard input stored into a wav file, but I'm getting the following errors.

If the wav file is open while trying to read it:

 "Impossible to read:"
 "Please give a wav file."

Or that one when using the named pipe:

Traceback (most recent call last):
  File "/usr/local/bin/dtmf", line 26, in <module>
    fps, data = wavfile.read(file)
  File "/usr/local/lib/python3.9/dist-packages/scipy/io/wavfile.py", line 553, in read
    while fid.tell() < file_size:
OSError: [Errno 29] Illegal seek

I know we cannot seek in a PIPE, but is there a way to use maybe BytesIO or StringIO?

Failing installation (due to Apple Silicon?)

Trying to install on a mac with M1 ship I get the following error at the sudo python3 -m pip install -r requirements.txt --upgrade step

            compiling C sources
            C compiler: clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
      
            compile options: '-DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=3 -DHAVE_CBLAS -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/umath -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/npymath -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/common -Inumpy/core/include -Ibuild/src.macosx-12-arm64-3.9/numpy/core/include/numpy -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/include/python3.9 -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/common -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/npymath -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/common -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/npymath -c'
            extra options: '-faltivec -I/System/Library/Frameworks/vecLib.framework/Headers'
            clang: numpy/core/src/multiarray/alloc.c
            clang: numpy/core/src/multiarray/array_assign_scalar.c
            clang: numpy/core/src/multiarray/buffer.c
            clang: numpy/core/src/multiarray/common.c
            clang: numpy/core/src/multiarray/conversion_utils.c
            clang: numpy/core/src/multiarray/datetime_strings.c
            clang: numpy/core/src/multiarray/descriptor.c
            clang: build/src.macosx-12-arm64-3.9/numpy/core/src/multiarray/einsum.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/multiarray/hashdescr.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: build/src.macosx-12-arm64-3.9/numpy/core/src/multiarray/lowlevel_strided_loops.c
            clang: numpy/core/src/multiarray/multiarraymodule.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/multiarray/nditer_constr.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/multiarray/scalarapi.c
            clang: numpy/core/src/multiarray/refcount.c
            clang: numpy/core/src/multiarray/temp_elide.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/multiarray/vdot.c
            clang: build/src.macosx-12-arm64-3.9/numpy/core/src/umath/loops.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/umath/ufunc_object.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: build/src.macosx-12-arm64-3.9/numpy/core/src/umath/scalarmath.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/npymath/npy_math.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/common/npy_longdouble.c
            clang: numpy/core/src/npymath/halffloat.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: numpy/core/src/common/numpyos.c
            clang: /private/tmp/pip-install-u53577ol/numpy_febe829ebfa6486c9e24f8c8d9d84ae2/numpy/_build_utils/src/apple_sgemv_fix.c
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
            error: Command "clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=3 -DHAVE_CBLAS -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/umath -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/npymath -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/common -Inumpy/core/include -Ibuild/src.macosx-12-arm64-3.9/numpy/core/include/numpy -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/include/python3.9 -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/common -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/npymath -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/common -Ibuild/src.macosx-12-arm64-3.9/numpy/core/src/npymath -c numpy/core/src/multiarray/alloc.c -o build/temp.macosx-12-arm64-3.9/numpy/core/src/multiarray/alloc.o -MMD -MF build/temp.macosx-12-arm64-3.9/numpy/core/src/multiarray/alloc.o.d -faltivec -I/System/Library/Frameworks/vecLib.framework/Headers" failed with exit status 1
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: legacy-install-failure
      
      × Encountered error while trying to install package.
      ╰─> numpy
      
      note: This is an issue with the package mentioned above, not pip.
      hint: See above for output from the failure.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Following the installation steps i get this

Ran this command sudo python3 -m pip install -r requirements.txt --upgrade and I get a long list of ERRORS.
The final one being:
ERROR: Could not find a version that satisfies the requirement scipy~=1.5.4 ERROR: No matching distribution found for scipy~=1.5.4
Current python version = 3.10.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.