mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
win32/mac fixes for audio
This commit is contained in:
parent
f3368d3c1e
commit
2792d22bf5
1 changed files with 19 additions and 18 deletions
|
@ -74,6 +74,14 @@ if sys.platform == "win32":
|
||||||
else:
|
else:
|
||||||
si = None
|
si = None
|
||||||
|
|
||||||
|
def retryWait(proc):
|
||||||
|
# osx throws interrupted system call errors frequently
|
||||||
|
while 1:
|
||||||
|
try:
|
||||||
|
return proc.wait()
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
|
||||||
# Noise profiles
|
# Noise profiles
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -89,14 +97,17 @@ def checkForNoiseProfile():
|
||||||
cmd = cmd + ["noisered", noiseProfile, NOISE_AMOUNT]
|
cmd = cmd + ["noisered", noiseProfile, NOISE_AMOUNT]
|
||||||
processingChain[0] = cmd
|
processingChain[0] = cmd
|
||||||
|
|
||||||
def generateNoiseProfile(file):
|
def generateNoiseProfile():
|
||||||
try:
|
try:
|
||||||
os.unlink(noiseProfile)
|
os.unlink(noiseProfile)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
subprocess.Popen(["sox", processingSrc, tmpFiles[0], "trim", "1.5", "1.5"])
|
retryWait(subprocess.Popen(
|
||||||
subprocess.Popen(["sox", tmpFiles[0], tmpFiles[1],
|
["sox", processingSrc, tmpFiles[0], "trim", "1.5", "1.5"],
|
||||||
"noiseprof", noiseProfile]).wait()
|
startupinfo=si))
|
||||||
|
retryWait(subprocess.Popen(["sox", tmpFiles[0], tmpFiles[1],
|
||||||
|
"noiseprof", noiseProfile],
|
||||||
|
startupinfo=si))
|
||||||
processingChain[0] = ["sox", processingSrc, "tmp2.wav",
|
processingChain[0] = ["sox", processingSrc, "tmp2.wav",
|
||||||
"noisered", noiseProfile, NOISE_AMOUNT]
|
"noisered", noiseProfile, NOISE_AMOUNT]
|
||||||
|
|
||||||
|
@ -110,9 +121,8 @@ class QueueMonitor(threading.Thread):
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if queue:
|
if queue:
|
||||||
path = queue.pop(0)
|
path = queue.pop(0)
|
||||||
p = subprocess.Popen(externalPlayer + [path],
|
retryWait(subprocess.Popen(
|
||||||
startupinfo=si)
|
externalPlayer + [path], startupinfo=si))
|
||||||
p.wait()
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -148,15 +158,9 @@ class _Recorder(object):
|
||||||
def postprocess(self):
|
def postprocess(self):
|
||||||
for c in processingChain:
|
for c in processingChain:
|
||||||
#print c
|
#print c
|
||||||
p = subprocess.Popen(c, startupinfo=si)
|
ret = retryWait(subprocess.Popen(c, startupinfo=si))
|
||||||
while 1:
|
|
||||||
try:
|
|
||||||
ret = p.wait()
|
|
||||||
break
|
|
||||||
except OSError:
|
|
||||||
continue
|
|
||||||
if ret:
|
if ret:
|
||||||
raise Exception("problem with" + str(c))
|
raise Exception("Problem with" + str(c))
|
||||||
|
|
||||||
class PyAudioThreadedRecorder(threading.Thread):
|
class PyAudioThreadedRecorder(threading.Thread):
|
||||||
|
|
||||||
|
@ -207,9 +211,6 @@ class PyAudioRecorder(_Recorder):
|
||||||
def file(self):
|
def file(self):
|
||||||
return processingDst
|
return processingDst
|
||||||
|
|
||||||
def wavFile(self):
|
|
||||||
return processingSrc
|
|
||||||
|
|
||||||
# Mac audio support
|
# Mac audio support
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue