mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
fix py3 issues with audio code
This commit is contained in:
parent
63499fb7e9
commit
4d88b62fbf
1 changed files with 5 additions and 11 deletions
|
@ -147,10 +147,10 @@ class MplayerMonitor(threading.Thread):
|
||||||
def startProcess(self):
|
def startProcess(self):
|
||||||
try:
|
try:
|
||||||
cmd = mplayerCmd + ["-slave", "-idle"]
|
cmd = mplayerCmd + ["-slave", "-idle"]
|
||||||
devnull = file(os.devnull, "w")
|
|
||||||
self.mplayer = subprocess.Popen(
|
self.mplayer = subprocess.Popen(
|
||||||
cmd, startupinfo=si, stdin=subprocess.PIPE,
|
cmd, startupinfo=si, stdin=subprocess.PIPE,
|
||||||
stdout=devnull, stderr=devnull)
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||||
|
universal_newlines=True, bufsize=1)
|
||||||
except OSError:
|
except OSError:
|
||||||
mplayerEvt.clear()
|
mplayerEvt.clear()
|
||||||
raise Exception("Did you install mplayer?")
|
raise Exception("Did you install mplayer?")
|
||||||
|
@ -169,9 +169,6 @@ def queueMplayer(path):
|
||||||
f.close()
|
f.close()
|
||||||
# it wants unix paths, too!
|
# it wants unix paths, too!
|
||||||
path = name.replace("\\", "/")
|
path = name.replace("\\", "/")
|
||||||
path = path.encode(sys.getfilesystemencoding())
|
|
||||||
else:
|
|
||||||
path = path.encode("utf-8")
|
|
||||||
mplayerQueue.append(path)
|
mplayerQueue.append(path)
|
||||||
mplayerEvt.set()
|
mplayerEvt.set()
|
||||||
|
|
||||||
|
@ -254,20 +251,17 @@ class PyAudioThreadedRecorder(threading.Thread):
|
||||||
input_device_index=PYAU_INPUT_INDEX,
|
input_device_index=PYAU_INPUT_INDEX,
|
||||||
frames_per_buffer=chunk)
|
frames_per_buffer=chunk)
|
||||||
|
|
||||||
all = []
|
data = b""
|
||||||
while not self.finish:
|
while not self.finish:
|
||||||
try:
|
try:
|
||||||
data = stream.read(chunk)
|
data += stream.read(chunk)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e[1] == pyaudio.paInputOverflowed:
|
if e[1] == pyaudio.paInputOverflowed:
|
||||||
data = None
|
pass
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
if data:
|
|
||||||
all.append(data)
|
|
||||||
stream.close()
|
stream.close()
|
||||||
p.terminate()
|
p.terminate()
|
||||||
data = ''.join(all)
|
|
||||||
wf = wave.open(processingSrc, 'wb')
|
wf = wave.open(processingSrc, 'wb')
|
||||||
wf.setnchannels(PYAU_CHANNELS)
|
wf.setnchannels(PYAU_CHANNELS)
|
||||||
wf.setsampwidth(p.get_sample_size(PYAU_FORMAT))
|
wf.setsampwidth(p.get_sample_size(PYAU_FORMAT))
|
||||||
|
|
Loading…
Reference in a new issue