Commit 878860d7 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Text based speech recognition: propose to show log on failure

parent b9fa9d61
Pipeline #50476 canceled with stage
import sys
import subprocess
import pkg_resources
required = {'vosk', 'srt'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed
if missing and len(sys.argv) > 1 :
print ("Installing missing pachages: ", missing)
python = sys.executable
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
......@@ -35,6 +35,7 @@
#include <QEvent>
#include <QKeyEvent>
#include <QToolButton>
#include <KMessageBox>
TextBasedEdit::TextBasedEdit(QWidget *parent)
: QWidget(parent)
......@@ -105,6 +106,11 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
});
info_message->hide();
m_logAction = new QAction(i18n("Show log"), this);
connect(m_logAction, &QAction::triggered, [this]() {
KMessageBox::sorry(this, m_errorString, i18n("Detailed log"));
});
speech_zone->setChecked(KdenliveSettings::speech_zone());
connect(speech_zone, &QCheckBox::stateChanged, [this](int state) {
KdenliveSettings::setSpeech_zone(state == Qt::Checked);
......@@ -197,6 +203,8 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
void TextBasedEdit::startRecognition()
{
info_message->hide();
m_errorString.clear();
info_message->removeAction(m_logAction);
QString pyExec = QStandardPaths::findExecutable(QStringLiteral("python3"));
if (pyExec.isEmpty()) {
info_message->setMessageType(KMessageWidget::Warning);
......@@ -275,7 +283,8 @@ void TextBasedEdit::startRecognition()
info_message->setText(i18n("Starting speech recognition on %1.", clipName));
info_message->animatedShow();
qApp->processEvents();
//m_speechJob->setProcessChannelMode(QProcess::MergedChannels);
connect(m_speechJob.get(), &QProcess::readyReadStandardError, this, &TextBasedEdit::slotProcessSpeechError);
connect(m_speechJob.get(), &QProcess::readyReadStandardOutput, this, &TextBasedEdit::slotProcessSpeech);
connect(m_speechJob.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &TextBasedEdit::slotProcessSpeechStatus);
listWidget->clear();
......@@ -297,6 +306,16 @@ void TextBasedEdit::slotProcessSpeechStatus(int, QProcess::ExitStatus status)
if (status == QProcess::CrashExit) {
info_message->setMessageType(KMessageWidget::Warning);
info_message->setText(i18n("Speech recognition aborted."));
if (!m_errorString.isEmpty()) {
info_message->addAction(m_logAction);
}
info_message->animatedShow();
} else if (listWidget->count() == 0) {
info_message->setMessageType(KMessageWidget::Information);
info_message->setText(i18n("No speech detected."));
if (!m_errorString.isEmpty()) {
info_message->addAction(m_logAction);
}
info_message->animatedShow();
} else {
info_message->setMessageType(KMessageWidget::Positive);
......@@ -306,6 +325,11 @@ void TextBasedEdit::slotProcessSpeechStatus(int, QProcess::ExitStatus status)
frame_progress->setVisible(false);
}
void TextBasedEdit::slotProcessSpeechError()
{
m_errorString.append(QString::fromUtf8(m_speechJob->readAllStandardError()));
}
void TextBasedEdit::slotProcessSpeech()
{
QString saveData = QString::fromUtf8(m_speechJob->readAllStandardOutput());
......
......@@ -26,6 +26,7 @@
#include "definitions.h"
#include <QProcess>
#include <QAction>
......@@ -46,6 +47,7 @@ public:
private slots:
void startRecognition();
void slotProcessSpeech();
void slotProcessSpeechError();
void parseVoskDictionaries();
void slotProcessSpeechStatus(int, QProcess::ExitStatus status);
void updateAvailability();
......@@ -57,6 +59,8 @@ private:
double m_clipDuration;
double m_offset;
int m_lastPosition;
QString m_errorString;
QAction *m_logAction;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment