-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10-scan.py
41 lines (36 loc) · 1.01 KB
/
10-scan.py
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
from scipy.io import wavfile
import numpy as np
import pickle
wav = wavfile.read('waves/reworu-wave.wav')
#print(wav)
# sample rate:44100
# 片方の音源に限定
wav = np.array(wav[1])[:,0]
print('wave shape', wav.shape)
print('wave min', np.min(wav))
print('wave max', np.max(wav))
# 16bit表現なので、0 ~ 65535に収まるはずであり、np.minが-32768なので足し合わせる
nextwav = []
Ys = []
for index, w in enumerate(wav.tolist()):
#if w != 0 :
nextwav.append(w)
Ys.append( (w+32768)/32768 )
nextwav = np.array(nextwav,dtype=np.int16 )
print(nextwav.shape)
wavfile.write('origin.wav', 44100, nextwav)
#sys.exit()
nextwav = []
Xs = []
DOWN = 3
for index, w in enumerate(wav.tolist()):
if index%DOWN == 0:
wabs = w + 32768
wabs = f'{wabs:016b}'
for d in range(DOWN):
Xs.append( wabs )
nextwav.append(w)
nextwav = np.array(nextwav,dtype=np.int16 )
print(nextwav.shape)
wavfile.write('degradation.wav', 44100, nextwav)
open('xs_ys.pkl', 'wb').write( pickle.dumps( (Xs, Ys) ) )