2012-12-21 08:51:59 +01:00
|
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
from aqt.qt import *
|
|
|
|
|
|
|
|
import time
|
2012-12-22 01:17:10 +01:00
|
|
|
from anki.sound import Recorder
|
2012-12-21 08:51:59 +01:00
|
|
|
from aqt.utils import saveGeom, restoreGeom
|
|
|
|
|
|
|
|
def getAudio(parent, encode=True):
|
|
|
|
"Record and return filename"
|
|
|
|
# record first
|
|
|
|
r = Recorder()
|
|
|
|
mb = QMessageBox(parent)
|
|
|
|
restoreGeom(mb, "audioRecorder")
|
|
|
|
mb.setWindowTitle("Anki")
|
2017-06-23 05:04:32 +02:00
|
|
|
but = QPushButton(_("Save"))
|
|
|
|
mb.addButton(but, QMessageBox.AcceptRole)
|
|
|
|
but = QPushButton(_("Cancel"))
|
2012-12-21 08:51:59 +01:00
|
|
|
mb.addButton(but, QMessageBox.RejectRole)
|
2017-06-23 05:04:32 +02:00
|
|
|
mb.setEscapeButton(but)
|
2012-12-21 08:51:59 +01:00
|
|
|
t = time.time()
|
|
|
|
r.start()
|
|
|
|
QApplication.instance().processEvents()
|
|
|
|
while not mb.clickedButton():
|
|
|
|
txt =_("Recording...<br>Time: %0.1f")
|
|
|
|
mb.setText(txt % (time.time() - t))
|
|
|
|
mb.show()
|
|
|
|
QApplication.instance().processEvents()
|
2017-06-23 05:04:32 +02:00
|
|
|
if mb.clickedButton() == mb.escapeButton():
|
|
|
|
r.stop()
|
|
|
|
return
|
2012-12-21 08:51:59 +01:00
|
|
|
saveGeom(mb, "audioRecorder")
|
|
|
|
# ensure at least a second captured
|
|
|
|
while time.time() - t < 1:
|
|
|
|
time.sleep(0.1)
|
|
|
|
r.stop()
|
|
|
|
# process
|
|
|
|
r.postprocess(encode)
|
|
|
|
return r.file()
|