Skip to content

Scripts to convert audio files to spectrograms and back

Notifications You must be signed in to change notification settings

SwapnanilSinha/audio2spec

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wav2png

Run this script to convert wav files to spectrograms, which are saved as png files. Is able to run on a folder structure with class labels:

  root/dog/0001.wav
  root/dog/0002.wav

  root/cat/0001.wav
  root/cat/0002.wav   etc.

Or otherwise on single files.

Example use:

For class folder structure

python ./wav2png.py folder --rootdir [rootdir]

For single files

 python ./wav2png.py single --filename [filename.wav]

Scaling is done on the STFT output to be compatible with 8-bit png format. The script searches the dataset for the maximum and minimum values, rounds up and down to the nearest integer respectively then scales to [0,255].

png2wav

Run to convert individual png spectrograms back to wav. Script assumes (and inverts) similar scaling as in wav2png. Griffin-Lim algortihm is initialized with SPSI. SPSI code originally from here.

Example use:

For single png spectrogram

python ./png2wav.py [filename.png]

cqtconv

This script is to transform a linear frequency scaled spectrogram image (like the ones generated by wav2png) to a pseudo constant-Q (CQT) scaled spectrogram. Algorithm is adapted from Matlab code written by Dan Ellis.

Example use:

For linear to cqt

python ./cqtconv.py --rootdir [rootdir] --outdir [outdir] --conversion spec2cqt

For cqt to linear

python ./cqtconv.py --rootdir [rootdir] --outdir [outdir] --conversion cqt2spec 

About

Scripts to convert audio files to spectrograms and back

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%