-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.py
37 lines (29 loc) · 1.06 KB
/
Player.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
# -*- coding: utf-8
import sys
import time
import threading
import subprocess
from utils import which
lock = threading.Lock()
class Player(threading.Thread):
def __init__(self, queue):
super(Player, self).__init__()
self.queue = queue
def run(self):
while True:
lock.acquire()
if not self.queue.empty():
voiceStream = self.queue.get()
self.playStream(voiceStream)
lock.release()
time.sleep(1)
def playStream(self, stream):
with open("output.mp3", "wb") as fw:
fw.write(stream)
fname = "output.mp3" # temp.name
exe = "ffplay" if sys.platform.find('darwin')>=0 else "ffplay.exe"
if not which(exe):
print("ffplay: Executable not found on machine.")
raise Exception("Dependency not found: %s" % exe)
command = [which(exe), "-vn", "-nodisp", "-autoexit", "-loglevel", "error", "-i", fname, "-af", "volume=0.5"]
subprocess.check_output(command)