Commit 9e839752 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Only list speech model folder if it contains an expected config file, and...

Only list speech model folder if it contains an expected config file, and disable/enable speech features when system config is updated
parent f5fa4ef3
Pipeline #50322 passed with stage
in 10 minutes and 20 seconds
......@@ -307,6 +307,8 @@ signals:
void closeSplash();
/** @brief Trigger an update of the the speech models list */
void voskModelUpdate(const QStringList models);
/** @brief This signal means that VOSK and/or SRT module availability changed*/
void updateVoskAvailability();
};
#endif
......@@ -1862,6 +1862,7 @@ void KdenliveSettingsDialog::checkVoskDependencies()
m_configSpeech.speech_info->removeAction(m_voskAction);
m_configSpeech.speech_info->animatedHide();
}
pCore->updateVoskAvailability();
}
} else {
m_configSpeech.speech_info->animatedHide();
......@@ -1882,7 +1883,7 @@ void KdenliveSettingsDialog::getDictionary()
m_configSpeech.speech_info->animatedShow();
connect(copyjob, &KIO::FileCopyJob::result, this, &KdenliveSettingsDialog::downloadModelFinished);
} else {
processArchive(url.toLocalFile());
}
}
......@@ -2004,14 +2005,21 @@ void KdenliveSettingsDialog::slotParseVoskDictionaries()
dir = QDir(modelDirectory);
}
QStringList dicts = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
m_configSpeech.listWidget->addItems(dicts);
QStringList final;
for (auto &d : dicts) {
QDir sub(dir.absoluteFilePath(d));
if (sub.exists(QStringLiteral("mfcc.conf")) || (sub.exists(QStringLiteral("conf/mfcc.conf")))) {
final << d;
}
}
m_configSpeech.listWidget->addItems(final);
if (!KdenliveSettings::vosk_folder_path().isEmpty()) {
m_configSpeech.custom_vosk_folder->setChecked(true);
m_configSpeech.vosk_folder->setUrl(QUrl::fromLocalFile(KdenliveSettings::vosk_folder_path()));
}
if (!dicts.isEmpty() && KdenliveSettings::vosk_found() && KdenliveSettings::vosk_srt_found()) {
if (!final.isEmpty() && KdenliveSettings::vosk_found() && KdenliveSettings::vosk_srt_found()) {
m_configSpeech.speech_info->animatedHide();
}
pCore->voskModelUpdate(dicts);
pCore->voskModelUpdate(final);
}
......@@ -43,10 +43,11 @@ SpeechDialog::SpeechDialog(const std::shared_ptr<TimelineItemModel> &timeline, Q
setupUi(this);
buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Process"));
speech_info->hide();
connect(pCore.get(), &Core::updateVoskAvailability, this, &SpeechDialog::updateAvailability);
connect(pCore.get(), &Core::voskModelUpdate, [&](QStringList models) {
language_box->clear();
language_box->addItems(models);
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(!models.isEmpty());
updateAvailability();
if (models.isEmpty()) {
speech_info->setMessageType(KMessageWidget::Information);
speech_info->setText(i18n("Please install speech recognition models"));
......@@ -58,7 +59,12 @@ SpeechDialog::SpeechDialog(const std::shared_ptr<TimelineItemModel> &timeline, Q
});
parseVoskDictionaries();
}
void SpeechDialog::updateAvailability()
{
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(KdenliveSettings::vosk_found() && KdenliveSettings::vosk_srt_found() && language_box->count() > 0);
}
void SpeechDialog::slotProcessSpeech(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone)
{
QString pyExec = QStandardPaths::findExecutable(QStringLiteral("python3"));
......@@ -161,5 +167,12 @@ void SpeechDialog::parseVoskDictionaries()
dir = QDir(modelDirectory);
}
QStringList dicts = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
pCore->voskModelUpdate(dicts);
QStringList final;
for (auto &d : dicts) {
QDir sub(dir.absoluteFilePath(d));
if (sub.exists(QStringLiteral("mfcc.conf")) || (sub.exists(QStringLiteral("conf/mfcc.conf")))) {
final << d;
}
}
pCore->voskModelUpdate(final);
}
......@@ -42,6 +42,7 @@ private:
private slots:
void slotProcessSpeech(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone);
void updateAvailability();
};
#endif
......@@ -48,10 +48,11 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
connect(button_start, &QPushButton::clicked, this, &TextBasedEdit::startRecognition);
listWidget->setWordWrap(true);
search_frame->setVisible(false);
connect(pCore.get(), &Core::updateVoskAvailability, this, &TextBasedEdit::updateAvailability);
connect(pCore.get(), &Core::voskModelUpdate, [&](QStringList models) {
language_box->clear();
language_box->addItems(models);
button_start->setEnabled(!models.isEmpty());
updateAvailability();
if (models.isEmpty()) {
info_message->setMessageType(KMessageWidget::Information);
info_message->setText(i18n("Please install speech recognition models"));
......@@ -147,6 +148,11 @@ void TextBasedEdit::startRecognition()
}*/
}
void TextBasedEdit::updateAvailability()
{
button_start->setEnabled(KdenliveSettings::vosk_found() && language_box->count() > 0);
}
void TextBasedEdit::slotProcessSpeechStatus(int, QProcess::ExitStatus status)
{
info_message->removeAction(m_abortAction);
......@@ -247,5 +253,12 @@ void TextBasedEdit::parseVoskDictionaries()
dir = QDir(modelDirectory);
}
QStringList dicts = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
pCore->voskModelUpdate(dicts);
QStringList final;
for (auto &d : dicts) {
QDir sub(dir.absoluteFilePath(d));
if (sub.exists(QStringLiteral("mfcc.conf")) || (sub.exists(QStringLiteral("conf/mfcc.conf")))) {
final << d;
}
}
pCore->voskModelUpdate(final);
}
......@@ -48,6 +48,7 @@ private slots:
void slotProcessSpeech();
void parseVoskDictionaries();
void slotProcessSpeechStatus(int, QProcess::ExitStatus status);
void updateAvailability();
private:
std::unique_ptr<QProcess> m_speechJob;
......
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