actondev / wavelet-denoiser

A wavelet audio denoiser done in python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TL;DR

python3 src/denoiser-argument.py -i <input file path> -o <output file path>

For an extensive list of what arguments you can pass

python3 src/denoiser-argument.py --help
 usage: denoiser-argument.py [-h] -i INPUT [-a A] [-b B] [-c C] [-d D]
							  [-type {1,2,3}] [-akg AKG] [-ako AKO]
							  [-aks {asc,desc}] [-l L] [-wavelet WAVELET]
							  [-method {wpa,dwt}] [-t TIME] [-v] -o OUTPUT

 optional arguments:
	-h, --help            show this help message and exit
	-i INPUT, --input INPUT
						  the relative or absolute path of the sound file you
						  wish to denoise
	-a A                  denoiser param 'a' (default: 2)
	-b B                  denoiser param 'b' (default: 1)
	-c C                  denoiser param 'c' (default: 1)
	-d D                  denoiser param 'd' (default: 0.1)
	-type {1,2,3}         filter type (default: 1)
	-akg AKG              grad of the Ak filter (default: 4)
	-ako AKO              offset of the Ak filter (default: 2)
	-aks {asc,desc}       the slope of the Ak filter - 'asc' or 'desc' (default:
						  asc)
	-l L                  wavelet packed decomposition levels (default: 8)
	-wavelet WAVELET      the wavelet to be used (default: db8)
	-method {wpa,dwt}     The wavelet transform method - 'wpa' or 'dwt'
						  (default: wpa)
	-t TIME, --time TIME  the period of silence present in the audio file (in
						  seconds) eg: '0-0.5'. If none provided, the noise
						  period will be autoimatically found
	-v, --verbose         verbose (plays the result audio)
	-o OUTPUT, --output OUTPUT
						  The output filename

comment: org-mode in emacs is awesome for writing this kind of documents :)

Docker way

First run docker-compose build, and then

docker-compose run denoiser python3 src/denoiser-argument.py -i test/resources/sp01_airport_sn5_44100.wav -o denoised.wav

You should see something like

trying to open test/resources/sp01_airport_sn5_44100.wav
Number of samples read: 124192
Denoiser options: 
a: 2
b: 1
c: 1
d: 0.1
akGrad: 4
akOffset: 2
filterType: 1
method: wpa
wavelet: db8
Noise profiler finished
0%
1%
...
99%
100%
will write denoised file to denoised.wav
OK

To denoise your own file (let’s say noised.wav)

  • put this file in the root directory
  • run docker-compose run denoiser python3 src/denoiser-argument.py -i noised.wav -o denoised.wav
  • profit :)

If you don’t want to use docker-compose and only docker

  • docker build . -t actondev/denoiser
  • and then
    docker run -v $(pwd):/code actondev/denoiser python3 src/denoiser-argument.py -i test/resources/sp01_airport_sn5_44100.wav -o denoised.wav
        

Wavelet denoiser

This is the product of my thesis for my Electrical & Computer Engineering diploma at Aristotle University of Thessaloniki. Good times (nah not really. i’m lazy, and doing this while having a day-job.. mierda)

Open sourced for 2 reasons

  • other people can use it
  • other people can improve it/comment on how to improve it ..aka tell me how much shitty the code -or the math- is :)

It’s my first attempt to try to do something in the open source world.

echo "Hello open source world"
Hello open source world

Installation

  • sudo apt-get install python3 python3-setuptools python3-pip
  • pip3 install -r requirements.txt

or instad of pip3 you can run python3 -m pip

Windows

with the above, python3 is available with the python command. Change this to python3 like that, by using git bash

python3 vs python fix

If you are on windows, and your executable to run python is.. python (even though it’s version 3) then using git bash:

  • which python

will tell you the path of the executable for the python

  • make sure python -V shows version 3
  • ln -s /path/of/python/from/which/python/command ~/bin
  • edit the environment variables for your current user, and add the C:\users\USERNAME\bin there

For example, I had to run ln -s /c/Python36/python.exe ~/bin/python3.exe

This wall make python3 available in the cmd console of windows as well (useful in case you run the tests from Visual Studio Code in Windows)

A simpler way, to just make the python3 command available in git bash would be to

  • vim ~/.bashrc
alias python3="python"
  • source ~/.bashrc

Usage

Denoiser

run python3 denoiser-argument.py -i <input file path> -o <output file path>. For all the parameters you can pass to the denoiser, run python3 denoiser-argument --help

Denoised file metrics

If you have the clean audio file (that is then noisified)

  • denoise the file
  • calculate the denoiser metric
    =python3 src/metric-cci.py -a “the clean file .wav” -b “the denoised file.wav”=

Available wavelets

[‘bior1.1’, ‘bior1.3’, ‘bior1.5’, ‘bior2.2’, ‘bior2.4’, ‘bior2.6’, ‘bior2.8’, ‘bior3.1’, ‘bior3.3’, ‘bior3.5’, ‘bior3.7’, ‘bior3.9’, ‘bior4.4’, ‘bior5.5’, ‘bior6.8’, ‘cgau1’, ‘cgau2’, ‘cgau3’, ‘cgau4’, ‘cgau5’, ‘cgau6’, ‘cgau7’, ‘cgau8’, ‘cmor’, ‘coif1’, ‘coif2’, ‘coif3’, ‘coif4’, ‘coif5’, ‘coif6’, ‘coif7’, ‘coif8’, ‘coif9’, ‘coif10’, ‘coif11’, ‘coif12’, ‘coif13’, ‘coif14’, ‘coif15’, ‘coif16’, ‘coif17’, ‘db1’, ‘db2’, ‘db3’, ‘db4’, ‘db5’, ‘db6’, ‘db7’, ‘db8’, ‘db9’, ‘db10’, ‘db11’, ‘db12’, ‘db13’, ‘db14’, ‘db15’, ‘db16’, ‘db17’, ‘db18’, ‘db19’, ‘db20’, ‘db21’, ‘db22’, ‘db23’, ‘db24’, ‘db25’, ‘db26’, ‘db27’, ‘db28’, ‘db29’, ‘db30’, ‘db31’, ‘db32’, ‘db33’, ‘db34’, ‘db35’, ‘db36’, ‘db37’, ‘db38’, ‘dmey’, ‘fbsp’, ‘gaus1’, ‘gaus2’, ‘gaus3’, ‘gaus4’, ‘gaus5’, ‘gaus6’, ‘gaus7’, ‘gaus8’, ‘haar’, ‘mexh’, ‘morl’, ‘rbio1.1’, ‘rbio1.3’, ‘rbio1.5’, ‘rbio2.2’, ‘rbio2.4’, ‘rbio2.6’, ‘rbio2.8’, ‘rbio3.1’, ‘rbio3.3’, ‘rbio3.5’, ‘rbio3.7’, ‘rbio3.9’, ‘rbio4.4’, ‘rbio5.5’, ‘rbio6.8’, ‘shan’, ‘sym2’, ‘sym3’, ‘sym4’, ‘sym5’, ‘sym6’, ‘sym7’, ‘sym8’, ‘sym9’, ‘sym10’, ‘sym11’, ‘sym12’, ‘sym13’, ‘sym14’, ‘sym15’, ‘sym16’, ‘sym17’, ‘sym18’, ‘sym19’, ‘sym20’]

..though some give errors. See more here

Running the tests

python3 -m unittest discover -v -s ./test -p '*test*.py'

Continuous Integration

Had the project initially just on gitlab and started using gitlab-ci.. seems quite nice :) It can integrate with public github repos as well. Hooray

Known problems

  • [ ] the denoiser is optimized for input files of 44100 kHz samplerate.

About

A wavelet audio denoiser done in python


Languages

Language:Python 83.3%Language:Shell 16.2%Language:Dockerfile 0.5%