generated from MBI-Div-B/pytango-TemplateDeviceServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundbox.py
47 lines (35 loc) · 1.2 KB
/
Soundbox.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
#!/home/labuser/micromamba/envs/sardana/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2020 MBI-Division-B
# MIT License, refer to LICENSE file
# Author: Martin Hennecke / Email: [email protected]
from tango.server import run, Device
from tango.server import attribute, command
from tango import DevState, AttrWriteType
from pydub import AudioSegment
from pydub.playback import play
from multiprocessing import Process
import time
class Soundbox(Device):
sound = attribute(
label="Sound",
dtype="str",
access=AttrWriteType.READ_WRITE,
)
def init_device(self):
Device.init_device(self)
self.__sound = ''
self.set_state(DevState.ON)
def delete_device(self):
pass
def read_sound(self):
return self.__sound
def write_sound(self, value):
self.__sound = value
sound = AudioSegment.silent(duration=500)+AudioSegment.from_file(value)+AudioSegment.silent(duration=500)
process = Process(target=play, args=(sound,))
process.start()
#play(AudioSegment.silent(duration=500)+sound+AudioSegment.silent(duration=500))
# start the server
if __name__ == "__main__":
Soundbox.run_server()