-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_stream.py
More file actions
31 lines (22 loc) · 827 Bytes
/
audio_stream.py
File metadata and controls
31 lines (22 loc) · 827 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
def stream_audio(p, chunk, job):
wf = wave.open(job, 'rb')
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
data = wf.readframes(chunk)
while data != b'':
print(calculate_position_percent(wf.tell(), wf.getnframes()))
stream.write(data)
data = wf.readframes(chunk)
# Check queue and load next element
# stop stream (6)
stream.stop_stream()
stream.close()
wf.close()
return True
def check_audio_device(p):
p.get_default_output_device_info()
device_count = p.get_device_count()
for i in range(0, device_count):
yield p.get_device_info_by_index(i)["name"],p.get_device_info_by_index(i)["index"]