basic pronunciation check

This commit is contained in:
Damien Elmes 2012-04-24 15:32:01 +09:00
parent f52073f2e9
commit c308141339
2 changed files with 29 additions and 6 deletions

View file

@ -8,8 +8,9 @@ import HTMLParser
from aqt.qt import *
from anki.utils import fmtTimeSpan, stripHTML, isMac
from anki.hooks import addHook, runHook, runFilter
from anki.sound import playFromText, clearAudioQueue, hasSound
from anki.sound import playFromText, clearAudioQueue, hasSound, play
from aqt.utils import mungeQA, getBase, shortcut, openLink, tooltip
from aqt.sound import getAudio
import aqt
class Reviewer(object):
@ -22,6 +23,7 @@ class Reviewer(object):
self.cardQueue = []
self.hadCardQueue = False
self._answeredIds = []
self._recordedAudio = None
self.typeCorrect = None # web init happens before this is set
self.state = None
self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb)
@ -243,10 +245,14 @@ function _typeAnsPress() {
self.onBuryNote()
elif key == "!":
self.onSuspend()
elif key == "V":
self.onRecordVoice()
elif key == "o":
self.onOptions()
elif key in ("1", "2", "3", "4"):
self._answerCard(int(key))
elif key == "v":
self.onReplayRecorded()
elif evt.key() == Qt.Key_Delete:
self.onDelete()
@ -598,15 +604,22 @@ function showAnswer(txt) {
# note the shortcuts listed here also need to be defined above
def showContextMenu(self):
opts = [
[_("Replay Audio"), "r", self.replayAudio],
[_("Mark Note"), "*", self.onMark],
[_("Bury Note"), "-", self.onBuryNote],
[_("Suspend Note"), "!", self.onSuspend],
[_("Delete Note"), "Delete", self.onDelete],
[_("Card Options"), "o", self.onOptions]
[_("Card Options"), "O", self.onOptions],
None,
[_("Replay Audio"), "R", self.replayAudio],
[_("Record Own Voice"), "Shift+V", self.onRecordVoice],
[_("Replay Own Voice"), "V", self.onReplayRecorded],
]
m = QMenu(self.mw)
for label, scut, func in opts:
for row in opts:
if not row:
m.addSeparator()
continue
label, scut, func = row
a = m.addAction(label)
a.setShortcut(QKeySequence(scut))
a.connect(a, SIGNAL("triggered()"), func)
@ -644,3 +657,13 @@ function showAnswer(txt) {
self.mw.reset()
tooltip(_("Note buried."))
def onRecordVoice(self):
self._recordedAudio = getAudio(self.mw, encode=False)
self.onReplayRecorded()
def onReplayRecorded(self):
print "replay"
if not self._recordedAudio:
return tooltip(_("You haven't recorded your voice yet."))
clearAudioQueue()
play(self._recordedAudio)

View file

@ -7,7 +7,7 @@ import time
from anki.sound import Recorder, play
from aqt.utils import saveGeom, restoreGeom
def getAudio(parent, string="", encode=True):
def getAudio(parent, encode=True):
"Record and return filename"
# record first
r = Recorder()
@ -27,8 +27,8 @@ def getAudio(parent, string="", encode=True):
mb.setText(txt % (time.time() - t))
mb.show()
QApplication.instance().processEvents()
# ensure at least a second captured
saveGeom(mb, "audioRecorder")
# ensure at least a second captured
while time.time() - t < 1:
time.sleep(0.1)
r.stop()