-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess_1.5.py
More file actions
59 lines (48 loc) · 2.77 KB
/
Copy pathpreprocess_1.5.py
File metadata and controls
59 lines (48 loc) · 2.77 KB
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
51
52
53
54
55
56
57
58
59
import numpy as np
from scipy.io import wavfile
from scipy import signal
import matplotlib.pyplot as plt
########################################################
# Preprocess needed to build spectogram (.jpg) data set
# in order to do the speech analysis.
# process of 3 separate speech command : no, yes, down
########################################################
######## convert no_datas to specgrams .jpg
for i in range(1,201):
audio_dir = r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\train_data\no\no ('+str(i)+').wav'
rate_data, audio_data = wavfile.read(audio_dir)
# remove borders
fig, ax = plt.subplots(1)
fig.subplots_adjust(left=0,right=1,bottom=0,top=1)
# plt the specgrams and save files
Pxx, freqs, bins, im = ax.specgram(audio_data, NFFT=1024, Fs=44100, noverlap=900)
ax.axis('off')
ax.axis('tight')
fig.savefig(r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\train_specgram\no\sg_no'+str(i)+'.jpg')
fig.savefig(r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\validation_specgram\no\sg_no'+str(i)+'.jpg')
######## convert yes_datas to specgrams .jpg
for i in range(1,201):
audio_dir = r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\train_data\yes\yes ('+str(i)+').wav'
rate_data, audio_data = wavfile.read(audio_dir)
# remove borders
fig, ax = plt.subplots(1)
fig.subplots_adjust(left=0,right=1,bottom=0,top=1)
# plt the specgrams and save files
Pxx, freqs, bins, im = ax.specgram(audio_data, NFFT=1024, Fs=44100, noverlap=900)
ax.axis('off')
ax.axis('tight')
fig.savefig(r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\train_specgram\yes\sg_yes'+str(i)+'.jpg')
fig.savefig(r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\validation_specgram\yes\sg_yes'+str(i)+'.jpg')
######## convert down_datas to specgrams .jpg
for i in range(1,201):
audio_dir = r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\train_data\down\down ('+str(i)+').wav'
rate_data, audio_data = wavfile.read(audio_dir)
# remove borders
fig, ax = plt.subplots(1)
fig.subplots_adjust(left=0,right=1,bottom=0,top=1)
# plt the specgrams and save files
Pxx, freqs, bins, im = ax.specgram(audio_data, NFFT=1024, Fs=44100, noverlap=900)
ax.axis('off')
ax.axis('tight')
fig.savefig(r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\train_specgram\down\sg_down'+str(i)+'.jpg')
fig.savefig(r'C:\Users\Of Corrupted Vision\Documents\Source Python\CNN speech recognition\validation_specgram\down\sg_down'+str(i)+'.jpg')