-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_loopback.py
More file actions
42 lines (38 loc) · 947 Bytes
/
audio_loopback.py
File metadata and controls
42 lines (38 loc) · 947 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
'''
Can be used as a loudspeaker.
Wait, doesn't VoiceMeeter already do this?
DUPLICATE: playback.py
'''
import pyaudio
SR = 44100
DTYPE = pyaudio.paFloat32
PAGE_LEN = 256
def main():
pa = pyaudio.PyAudio()
outStream = pa.open(
format = DTYPE, channels = 1, rate = SR,
frames_per_buffer = PAGE_LEN,
output = True,
)
outStream.start_stream()
inStream = pa.open(
format = DTYPE, channels = 1, rate = SR,
frames_per_buffer = PAGE_LEN,
input = True,
)
inStream.start_stream()
try:
while True:
print('.', end='', flush=True)
try:
data = inStream.read(PAGE_LEN)
except KeyboardInterrupt:
print('bye')
break
outStream.write(data)
finally:
inStream.close()
outStream.close()
pa.terminate()
if __name__ == '__main__':
main()