-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathsound.py
34 lines (29 loc) · 1021 Bytes
/
sound.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from playsound import playsound
import time
import threading
import queue
class Sound:
def __init__(self, config):
self.config = config
self.sound_queue = queue.Queue()
def run(self):
if self.config.Debug: print("run, sound play thread...")
thread_sound = threading.Thread(target=self.sound_play)
thread_sound.start()
def put(self, obj):
self.sound_queue.put(obj)
#####################################
# !sound 音声再生スレッド -------------
def sound_play(self):
while True:
q = self.sound_queue.get()
if q is None:
time.sleep(1)
else:
try:
playsound('./sound/{}.mp3'.format(q), True)
except Exception as e:
print('sound error: [!sound] command can not play sound...')
if self.config.Debug: print(e.args)