-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_shared.py
35 lines (33 loc) · 950 Bytes
/
a_shared.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
import queue
import struct
from dataclasses import dataclass
###########Queue###########
to_GUI = queue.Queue()
to_server = queue.Queue()
to_volume = queue.Queue()
to_mapping = queue.Queue()
###########Arg#############
clients = {}
Config = {}
AllDevS = {}
VolChanger = ''
###########Flag############
isloopback = True
SliderOn = True
callbackOn = True
###########Class############
@dataclass
class AudioHeader:
sample_rate: int
block_size: int
channels: int
volume: float
# 格式
FORMAT = '!IIIf' #4*4 Bytes
SIZE = struct.calcsize(FORMAT)
def serialize(self) -> bytes: # 將 header 序列化為固定格式的二進制數據。
return struct.pack(self.FORMAT, self.sample_rate, self.block_size,
self.channels ,self.volume)
Header = AudioHeader(sample_rate=48000, block_size=320, channels=2, volume=0)
HEADER_SIZE = AudioHeader.SIZE
header_prefix = struct.pack('!I', HEADER_SIZE)