mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
recording
This commit is contained in:
parent
3337b42565
commit
c08e810503
2 changed files with 12 additions and 33 deletions
|
@ -5,7 +5,7 @@
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtWebKit import QWebView
|
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.utils import stripHTML
|
||||||
from anki.sound import play
|
from anki.sound import play
|
||||||
from anki.hooks import addHook, removeHook, runHook, runFilter
|
from anki.hooks import addHook, removeHook, runHook, runFilter
|
||||||
|
@ -645,7 +645,10 @@ class Editor(object):
|
||||||
file = getFile(self.widget, _("Add Media"), "media", key)
|
file = getFile(self.widget, _("Add Media"), "media", key)
|
||||||
if not file:
|
if not file:
|
||||||
return
|
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))
|
self.web.eval("setFormat('inserthtml', %s);" % simplejson.dumps(html))
|
||||||
|
|
||||||
def _addMedia(self, path, canDelete=False):
|
def _addMedia(self, path, canDelete=False):
|
||||||
|
@ -668,19 +671,14 @@ class Editor(object):
|
||||||
return '[sound:%s]' % name
|
return '[sound:%s]' % name
|
||||||
|
|
||||||
def onRecSound(self):
|
def onRecSound(self):
|
||||||
self.initMedia()
|
|
||||||
w = self.focusedEdit()
|
|
||||||
try:
|
try:
|
||||||
file = getAudio(self.widget)
|
file = getAudio(self.widget)
|
||||||
except:
|
except Exception, e:
|
||||||
if sys.platform.startswith("darwin"):
|
showWarning(_(
|
||||||
ui.utils.showInfo(_('''\
|
"Couldn't record audio. Have you installed lame and sox?") +
|
||||||
Please install <a href="http://www.thalictrum.com/software/lame-3.97.dmg.gz">lame</a>
|
"\n\n" + unicode(e))
|
||||||
to enable recording.'''), parent=self.widget)
|
return
|
||||||
return
|
self.addMedia(file)
|
||||||
raise
|
|
||||||
if file:
|
|
||||||
self._addSound(file, w, copy=False)
|
|
||||||
|
|
||||||
# LaTeX
|
# LaTeX
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
21
aqt/sound.py
21
aqt/sound.py
|
@ -5,7 +5,7 @@ from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from anki.sound import Recorder, play, generateNoiseProfile
|
from anki.sound import Recorder, play
|
||||||
from aqt.utils import saveGeom, restoreGeom
|
from aqt.utils import saveGeom, restoreGeom
|
||||||
|
|
||||||
def getAudio(parent, string="", encode=True):
|
def getAudio(parent, string="", encode=True):
|
||||||
|
@ -36,22 +36,3 @@ def getAudio(parent, string="", encode=True):
|
||||||
# process
|
# process
|
||||||
r.postprocess(encode)
|
r.postprocess(encode)
|
||||||
return r.file()
|
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...<br>Time: %0.1f")
|
|
||||||
mb.setText(txt % (f - time.time()))
|
|
||||||
QApplication.instance().processEvents()
|
|
||||||
time.sleep(0.1)
|
|
||||||
r.stop()
|
|
||||||
generateNoiseProfile()
|
|
||||||
mb.deleteLater()
|
|
||||||
|
|
Loading…
Reference in a new issue