mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
use full path to packaged audio commands
ensures we use the packaged version over the system version
This commit is contained in:
parent
f465dbd8ad
commit
04c13d1348
2 changed files with 32 additions and 21 deletions
|
@ -5,7 +5,7 @@
|
||||||
import re, sys, threading, time, subprocess, os, atexit
|
import re, sys, threading, time, subprocess, os, atexit
|
||||||
import random
|
import random
|
||||||
from anki.hooks import addHook
|
from anki.hooks import addHook
|
||||||
from anki.utils import tmpdir, isWin, isMac
|
from anki.utils import tmpdir, isWin, isMac, isLin
|
||||||
|
|
||||||
# Shared utils
|
# Shared utils
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -22,6 +22,30 @@ def stripSounds(text):
|
||||||
def hasSound(text):
|
def hasSound(text):
|
||||||
return re.search(_soundReg, text) is not None
|
return re.search(_soundReg, text) is not None
|
||||||
|
|
||||||
|
# Packaged commands
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# return modified command array that points to bundled command, and return
|
||||||
|
# required environment
|
||||||
|
def _packagedCmd(cmd):
|
||||||
|
cmd = cmd[:]
|
||||||
|
env = os.environ.copy()
|
||||||
|
if isMac:
|
||||||
|
dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
exeDir = os.path.abspath(dir + "/../../../../Resources/audio")
|
||||||
|
else:
|
||||||
|
exeDir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||||
|
if isWin and not cmd[0].endswith(".exe"):
|
||||||
|
cmd[0] += ".exe"
|
||||||
|
path = os.path.join(exeDir, cmd[0])
|
||||||
|
if not os.path.exists(path):
|
||||||
|
return cmd, env
|
||||||
|
cmd[0] = path
|
||||||
|
# need to set lib path for linux
|
||||||
|
if isLin:
|
||||||
|
env["LD_LIBRARY_PATH"] = exeDir
|
||||||
|
return cmd, env
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
processingSrc = "rec.wav"
|
processingSrc = "rec.wav"
|
||||||
|
@ -44,13 +68,6 @@ if isWin:
|
||||||
else:
|
else:
|
||||||
si = None
|
si = None
|
||||||
|
|
||||||
if isMac:
|
|
||||||
# make sure lame, which is installed in /usr/local/bin, is in the path
|
|
||||||
os.environ['PATH'] += ":" + "/usr/local/bin"
|
|
||||||
dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
dir = os.path.abspath(dir + "/../../../..")
|
|
||||||
os.environ['PATH'] += ":" + dir + "/Resources/audio"
|
|
||||||
|
|
||||||
def retryWait(proc):
|
def retryWait(proc):
|
||||||
# osx throws interrupted system call errors frequently
|
# osx throws interrupted system call errors frequently
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -62,15 +79,9 @@ def retryWait(proc):
|
||||||
# Mplayer settings
|
# Mplayer settings
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
exeDir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
mplayerCmd = ["mplayer", "-really-quiet", "-noautosub"]
|
||||||
if isWin:
|
if isWin:
|
||||||
os.environ['PATH'] += ";" + exeDir
|
mplayerCmd += ["-ao", "win32"]
|
||||||
mplayerCmd = ["mplayer.exe", "-ao", "win32"]
|
|
||||||
else:
|
|
||||||
os.environ['PATH'] += ":" + exeDir
|
|
||||||
mplayerCmd = ["mplayer"]
|
|
||||||
|
|
||||||
mplayerCmd += ["-really-quiet", "-noautosub"]
|
|
||||||
|
|
||||||
# Mplayer in slave mode
|
# Mplayer in slave mode
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -152,9 +163,7 @@ class MplayerMonitor(threading.Thread):
|
||||||
def startProcess(self):
|
def startProcess(self):
|
||||||
try:
|
try:
|
||||||
cmd = mplayerCmd + ["-slave", "-idle"]
|
cmd = mplayerCmd + ["-slave", "-idle"]
|
||||||
env = os.environ.copy()
|
cmd, env = _packagedCmd(cmd)
|
||||||
if not isWin and not isMac:
|
|
||||||
env["LD_LIBRARY_PATH"]=exeDir
|
|
||||||
self.mplayer = subprocess.Popen(
|
self.mplayer = subprocess.Popen(
|
||||||
cmd, startupinfo=si, stdin=subprocess.PIPE,
|
cmd, startupinfo=si, stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||||
|
@ -224,13 +233,14 @@ class _Recorder(object):
|
||||||
if not self.encode and c[0] == 'lame':
|
if not self.encode and c[0] == 'lame':
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
ret = retryWait(subprocess.Popen(c, startupinfo=si))
|
cmd, env = _packagedCmd(c)
|
||||||
|
ret = retryWait(subprocess.Popen(cmd, startupinfo=si, env=env))
|
||||||
except:
|
except:
|
||||||
ret = True
|
ret = True
|
||||||
if ret:
|
if ret:
|
||||||
raise Exception(_(
|
raise Exception(_(
|
||||||
"Error running %s") %
|
"Error running %s") %
|
||||||
" ".join(c))
|
" ".join(cmd))
|
||||||
|
|
||||||
class PyAudioThreadedRecorder(threading.Thread):
|
class PyAudioThreadedRecorder(threading.Thread):
|
||||||
|
|
||||||
|
|
|
@ -330,6 +330,7 @@ def call(argv, wait=True, **kwargs):
|
||||||
|
|
||||||
isMac = sys.platform.startswith("darwin")
|
isMac = sys.platform.startswith("darwin")
|
||||||
isWin = sys.platform.startswith("win32")
|
isWin = sys.platform.startswith("win32")
|
||||||
|
isLin = not isMac and not isWin
|
||||||
|
|
||||||
invalidFilenameChars = ":*?\"<>|"
|
invalidFilenameChars = ":*?\"<>|"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue