File size: 1,639 Bytes
b03e08e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
## 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**
```bash
python ./wav2png.py folder --rootdir [rootdir]
```
**For single files**
```bash
 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](http://ieeexplore.ieee.org/abstract/document/7251907/). SPSI code originally from [here](https://github.com/lonce/SPSI_Python).

Example use:  

**For single png spectrogram**
```bash
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](http://www.ee.columbia.edu/ln/rosa/matlab/sgram/).

Example use:  

**For linear to cqt**
```bash
python ./cqtconv.py --rootdir [rootdir] --outdir [outdir] --conversion spec2cqt
```
**For cqt to linear**
```bash
python ./cqtconv.py --rootdir [rootdir] --outdir [outdir] --conversion cqt2spec 
```