-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (50 loc) · 1.49 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pylab
import pyaudio
from scipy import signal, stats, integrate
import numpy as np
import matplotlib.pyplot as plt
import scipy.io.wavfile as w
p = pyaudio.PyAudio()
fs, audio = w.read('Track48.wav')
#cycles = 5
t = np.linspace(0, 1, 500)
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=fs,
output=True)
plt.plot(audio)
plt.show()
audio_stream = audio.astype(np.int16).tostring()
stream.write(audio_stream)
stream.close()
# Second Audio 5s ---------------------------------------------------
p = pyaudio.PyAudio()
fs, audio = w.read('5s.wav')
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=fs,
output=True)
plt.plot(audio)
plt.show()
audio_stream = audio.astype(np.int16).tostring()
stream.write(audio_stream)
stream.close()
# Uniform mid tread Quantizer ---------------------------------------
data = audio
step = (float(np.max(data)) - float(np.min(data)))/(2**4-1)
audioQuant = np.round(data/(step)) * step
de_quantization_tread = audioQuant*step
plt.plot(de_quantization_tread)
plt.title('Mid Tread uniform quantized audio with quantization nosie ')
plt.show()
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32,
channels=1,
rate=fs,
output=True,
frames_per_buffer=1024)
audio_play = de_quantization_tread.astype('float32').tostring()
stream.write(audio_play)
stream.stop_stream()
stream.close()
p.terminate()