Encapsulate an image into an audio file.
It uses the image as the spectrogram of the audio and recover the spectral phases through Griffin-Lim algorithm, using librosa package.
Code written by Laurent Benaroya under GNU GPL v3 license.
$ sudo apt install pipenv
OR if you don't have root priviledges (see https://pipenv.pypa.io/en/latest/install/) => prerefered!!!
$ pip install --user pipx
$ pip install --upgrade pip
$ pipx install pipenv
$ pip install --user pipenv
$ export PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
$ export PATH="$PATH:$PYTHON_BIN_PATH"
You can add the export PATH in your ~/.bashrc
Note : pipenv problem : pypa/pipenv#5052
$ pipenv --python 3.9
$ pipenv install
$ pipenv shell
You may need to install tkinter
with the command sudo apt-get install python3-tk
for matplotlib
display in compare_image_and_spectrogram.py
(not compulsory).
$ python image2sound.py -h
usage: image2sound.py [-h] --img IMG --wav WAV [--inv] [--custom] generate audio from image taken as the spectrogram, inversion using Griffin-Lim algorithm (see https://librosa.org/doc/latest/generated/librosa.griffinlim.html for references to this algorithm) optional arguments: -h, --help show this help message and exit --img IMG filename of the input image --wav WAV filename of the output audio (wav) --inv swap gray image scale --custom custom settings for GL
$ python image2sound.py --img demo/signature_basique.jpg --wav demo/signature_basique.wav
try the options --inv (usefull when the image is mostly black) and --custom (try it for fun)
play the audio using mplayer or audacity etc !!!
visualize the original image and the spectrogram from the output audio :
$ python compare_image_and_spectrogram.py --img demo/signature_basique.jpg --wav demo/signature_basique.wav
$ exit