-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
55 lines (39 loc) · 1.71 KB
/
client.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
46
47
48
49
50
51
52
53
54
55
import hydra
from multiprocessing import Process
from omegaconf.dictconfig import DictConfig
from swan.subscriber import Subscriber
from swan.publisher import Publisher
from swan.utils.audio import get_audio_devices
class Client:
"""This class abstracts the main functionality performed by a device.
A device can be a 'publisher', a 'subscriber' or both. A publisher sends their
recorded microphone signals to a Mosquitto (MQTT) server, which in turn sends it to
all 'subscriber' devices.
Besides receiving the microphone signals additional functionality
of subscribers consist of computing features based on the received signals and
plotting them.
"""
def __init__(self, config: DictConfig):
"""Create a new client.
Args:
config (DictConfig): dictionary-like structure containg the client configuration,
such as whether they are a publisher and/or subscriber, the address of the MQTT server, etc.
"""
try:
processes = []
if config["subscribe"]:
processes.append(Process(target=Subscriber, args=(config,)))
if config["publish"]:
processes.append(Process(target=Publisher, args=(config,)))
[p.start() for p in processes]
[p.join() for p in processes]
except KeyboardInterrupt:
print("Stopping client...")
@hydra.main(config_path="config", config_name="config")
def main(config: DictConfig):
print("###########################")
get_audio_devices()
config["audio"]["device_id"] = int(input("Enter Input Device id: "))
Client(config)
if __name__ == "__main__":
main()