-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeDomainRep.pyw
47 lines (36 loc) · 868 Bytes
/
timeDomainRep.pyw
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
#!/usr/bin/env python
# coding: utf-8
import numpy as np
import pyaudio as pa
import struct
import matplotlib.pyplot as plt
import tkinter as tk
from IPython.terminal.pt_inputhooks import tk
_chunk = 1024 * 4
_format = pa.paInt16
_channels = 1
_rate = 44100 #in Hz
p = pa.PyAudio()
stream = p.open(
format = _format,
channels = _channels,
rate = _rate,
input = 1,
output = 1,
frames_per_buffer = _chunk,
)
fig, ax = plt.subplots()
x = np.arange(0, 2*_chunk, 2)
line, = ax.plot(x, np.random.rand(_chunk))
ax.set_ylim(-130,130)
ax.set_xlim(0,_chunk)
fig.show()
try:
while True:
data = stream.read(_chunk)
dataInt = np.array(struct.unpack(str(2*_chunk) + 'B', data)[::2], dtype = 'b')
line.set_ydata(dataInt)
fig.canvas.draw()
fig.canvas.flush_events()
except:
print("Restart Kernel")