Skip to content

Commit

Permalink
fix py3 issues with audio code
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed May 31, 2016
1 parent 63499fb commit 4d88b62
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions anki/sound.py
Expand Up @@ -147,10 +147,10 @@ def kill(self):
def startProcess(self):
try:
cmd = mplayerCmd + ["-slave", "-idle"]
devnull = file(os.devnull, "w")
self.mplayer = subprocess.Popen(
cmd, startupinfo=si, stdin=subprocess.PIPE,
stdout=devnull, stderr=devnull)
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
universal_newlines=True, bufsize=1)
except OSError:
mplayerEvt.clear()
raise Exception("Did you install mplayer?")
Expand All @@ -169,9 +169,6 @@ def queueMplayer(path):
f.close()
# it wants unix paths, too!
path = name.replace("\\", "/")
path = path.encode(sys.getfilesystemencoding())
else:
path = path.encode("utf-8")
mplayerQueue.append(path)
mplayerEvt.set()

Expand Down Expand Up @@ -254,20 +251,17 @@ def run(self):
input_device_index=PYAU_INPUT_INDEX,
frames_per_buffer=chunk)

all = []
data = b""
while not self.finish:
try:
data = stream.read(chunk)
data += stream.read(chunk)
except IOError as e:
if e[1] == pyaudio.paInputOverflowed:
data = None
pass
else:
raise
if data:
all.append(data)
stream.close()
p.terminate()
data = ''.join(all)
wf = wave.open(processingSrc, 'wb')
wf.setnchannels(PYAU_CHANNELS)
wf.setsampwidth(p.get_sample_size(PYAU_FORMAT))
Expand Down

0 comments on commit 4d88b62

Please sign in to comment.