diff --git a/aqt/editor.py b/aqt/editor.py
index fb0042f7d..c38fcb4d8 100644
--- a/aqt/editor.py
+++ b/aqt/editor.py
@@ -5,7 +5,7 @@
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import QWebView
-import re, os, sys, tempfile, urllib2, ctypes, simplejson
+import re, os, sys, tempfile, urllib2, ctypes, simplejson, traceback
from anki.utils import stripHTML
from anki.sound import play
from anki.hooks import addHook, removeHook, runHook, runFilter
@@ -645,7 +645,10 @@ class Editor(object):
file = getFile(self.widget, _("Add Media"), "media", key)
if not file:
return
- html = self._addMedia(file)
+ self.addMedia(file, canDelete=True)
+
+ def addMedia(self, path, canDelete=False):
+ html = self._addMedia(path, canDelete)
self.web.eval("setFormat('inserthtml', %s);" % simplejson.dumps(html))
def _addMedia(self, path, canDelete=False):
@@ -668,19 +671,14 @@ class Editor(object):
return '[sound:%s]' % name
def onRecSound(self):
- self.initMedia()
- w = self.focusedEdit()
try:
file = getAudio(self.widget)
- except:
- if sys.platform.startswith("darwin"):
- ui.utils.showInfo(_('''\
-Please install lame
-to enable recording.'''), parent=self.widget)
- return
- raise
- if file:
- self._addSound(file, w, copy=False)
+ except Exception, e:
+ showWarning(_(
+ "Couldn't record audio. Have you installed lame and sox?") +
+ "\n\n" + unicode(e))
+ return
+ self.addMedia(file)
# LaTeX
######################################################################
diff --git a/aqt/sound.py b/aqt/sound.py
index cef0dd4a3..b4727f81e 100644
--- a/aqt/sound.py
+++ b/aqt/sound.py
@@ -5,7 +5,7 @@ from PyQt4.QtGui import *
from PyQt4.QtCore import *
import time
-from anki.sound import Recorder, play, generateNoiseProfile
+from anki.sound import Recorder, play
from aqt.utils import saveGeom, restoreGeom
def getAudio(parent, string="", encode=True):
@@ -36,22 +36,3 @@ def getAudio(parent, string="", encode=True):
# process
r.postprocess(encode)
return r.file()
-
-def recordNoiseProfile(parent):
- r = Recorder()
- mb = QMessageBox(parent)
- mb.setStandardButtons(QMessageBox.NoButton)
- mb.setIconPixmap(QPixmap(":/icons/media-record.png"))
- mb.show()
- mb.setWindowTitle("Anki")
- QApplication.instance().processEvents()
- f = time.time() + 10
- r.start()
- while f > time.time():
- txt =_("Sampling silence...
Time: %0.1f")
- mb.setText(txt % (f - time.time()))
- QApplication.instance().processEvents()
- time.sleep(0.1)
- r.stop()
- generateNoiseProfile()
- mb.deleteLater()