-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwavfile2waveform.py
More file actions
48 lines (31 loc) · 934 Bytes
/
wavfile2waveform.py
File metadata and controls
48 lines (31 loc) · 934 Bytes
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
# -*- coding:utf-8 -*-
import os
import os.path as osp
import glob
import sys
import numpy as np
import matplotlib.pyplot as plt
from wavReader import readWav
def ConvertFile2Waveform(audio, dir_out):
fname = osp.basename(audio)
rate, data = readWav(audio)
fname = fname.split('.')[0]
fname = osp.join(dir_out, fname)
print(fname)
plt.figure()
plt.plot(data)
plt.savefig(fname + '.png')
plt.close()
return True
def ConvertAudioToWaveform(dir_in, dir_out=osp.join('.', 'image', 'waveform')):
if not osp.exists(dir_in):
raise(ValueError(dir_in + ' does not exist'))
if not osp.exists(dir_out):
raise(ValueError(dir_out + ' does not exist'))
audios = glob.glob(osp.join(dir_in, '*.*'))
print(audios)
for audio in audios:
ConvertFile2Waveform(audio, dir_out)
return
if __name__ == '__main__':
ConvertAudioToWaveform(sys.argv[1])