Skip to content

Encode an image to sound (WAV file) and view it as a spectrogram. Optimized Python 3 version.

License

Notifications You must be signed in to change notification settings

unreal79/pic2wav

Repository files navigation

pic2wav - Spectrogram from picture

Encode an image to sound (WAV file) and view it as a spectrogram in audio player.

Example

python3 pic2wav.py picture.png -d8 -r200

Source picture:

drawing

Spectrogram of created WAV file:

drawing

Options

pic2wav.py [[-p] <picture>] [-w <output.wav>] [-d <seconds>] [-r <resolution>] [-e] [-i]
Options:
  -p - input picture file name (PNG, JPEG, etc.) (default is 'picture.png')
  -w - output WAV file name (default is 'input picture file' + '.wav')
  -d - output sound file duration in seconds (float) (default is 2)
  -r - spectrogram resolution (height) in pixels; affects work time (default is 256)
  -e - equalize image (enhances contrast)
  -i - invert image colors

Optimisation

The code is optimized for pefromance in Python 3 with math and Pillow (PIL) libraries.

I recommend running it under PyPy -- this gives about 30% speedup.

Thanks

About

Encode an image to sound (WAV file) and view it as a spectrogram. Optimized Python 3 version.

Topics

Resources

License

Stars

Watchers

Forks

Languages