-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stream.py
45 lines (39 loc) · 1.45 KB
/
Stream.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
from threading import Thread
from time import time
from wave import open
class Stream:
def __init__(self, sb, device_index, s_format, channels, rate):
self.soundboard = sb
self.format = s_format
self.channels = channels
self.rate = rate
self.stream = sb.pyAudio.open(
output_device_index=device_index,
format=self.format,
channels=self.channels,
rate=self.rate,
output=True
)
self.timeAtLastPlay = time()
self.isPlaying = False
self.playSoundThread = None
self.wav = None
def play(self):
options = self.soundboard.options
def stop(): return self.soundboard.stopAllSounds
new_sound_stop = options['Stop All Sounds With New Sound'].state
chunk = options['Chunk Size'].state
data = self.wav.readframes(chunk)
self.isPlaying = True
while data and not stop() and (not new_sound_stop or self.wav is self.soundboard.currentSoundPlaying):
data = self.wav.readframes(chunk)
self.stream.write(data)
self.isPlaying = False
def get_play_thread(self):
return Thread(target=self.play, args=())
def set_wav(self, file_path):
self.wav = open(file_path, 'rb')
def matches_info(self, s_format, channels, rate):
return (self.format == s_format and
self.channels == channels and
self.rate == rate)