1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/***************************************************************************
* Copyright (C) 2002 by Gunnar Schmi Dt <kmouth@schmi-dt.de *
* (C) 2015 by Jeremy Whiting <jpwhiting@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "texttospeechconfigurationwidget.h"
#include <KLocalizedString>
#include "speech.h"
#include "texttospeechsystem.h"
#include <QtTextToSpeech>
TextToSpeechConfigurationWidget::TextToSpeechConfigurationWidget(QWidget *parent, const QString &name)
: QWizardPage(parent)
{
setObjectName(name);
setupUi(this);
ttsSystem = new TextToSpeechSystem(this);
connect(qtspeechGroupBox, &QGroupBox::toggled, this, &TextToSpeechConfigurationWidget::useQtspeechChanged);
buildCodecList();
// BEGIN Text-to-speech section
// Populate tts engines and use their names directly as key and item text:
const QStringList engines = QTextToSpeech::availableEngines();
for (const QString &engine : engines) {
if (engine != QLatin1String("mock")) {
engineComboBox->addItem(engine);
}
}
connect(engineComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &TextToSpeechConfigurationWidget::slotTTSEngineChanged);
connect(voiceComboBox, &QComboBox::currentTextChanged, this, &TextToSpeechConfigurationWidget::slotTTSVoiceChanged);
// Preload voice list
slotTTSEngineChanged();
}
TextToSpeechConfigurationWidget::~TextToSpeechConfigurationWidget()
{
}
void TextToSpeechConfigurationWidget::buildCodecList()
{
for (int encoding = QStringConverter::System; encoding <= QStringConverter::System; ++encoding) {
QString name = QLatin1String(QStringConverter::nameForEncoding(QStringConverter::Encoding(encoding)));
characterCodingBox->addItem(name, encoding);
}
}
void TextToSpeechConfigurationWidget::cancel()
{
urlReq->setUrl(QUrl::fromLocalFile(ttsSystem->ttsCommand));
stdInButton->setChecked(ttsSystem->stdIn);
characterCodingBox->setCurrentIndex(ttsSystem->encoding);
qtspeechGroupBox->setChecked(ttsSystem->useQtSpeech);
}
void TextToSpeechConfigurationWidget::useQtspeechChanged(bool enabled)
{
alternativeGroupBox->setEnabled(!enabled);
}
void TextToSpeechConfigurationWidget::slotTTSEngineChanged()
{
QString engine = engineComboBox->currentText();
ttsSystem->ttsEngine = engine;
// Get list of voices and repopulate voice tts combobox
QTextToSpeech *ttsEngine = new QTextToSpeech(engine);
const QList<QVoice> voices = ttsEngine->availableVoices();
voiceComboBox->blockSignals(true);
voiceComboBox->clear();
for (const QVoice &voice : voices) {
voiceComboBox->addItem(voice.name());
}
delete ttsEngine;
// If there's a voice set, try to load it
if (!ttsSystem->ttsVoice.isEmpty()) {
voiceComboBox->setCurrentText(ttsSystem->ttsVoice);
}
voiceComboBox->blockSignals(false);
}
void TextToSpeechConfigurationWidget::slotTTSVoiceChanged(const QString &voice)
{
ttsSystem->ttsVoice = voice;
}
void TextToSpeechConfigurationWidget::ok()
{
ttsSystem->ttsCommand = urlReq->url().toLocalFile();
ttsSystem->stdIn = stdInButton->isChecked();
ttsSystem->encoding = QStringConverter::Encoding(characterCodingBox->currentIndex());
ttsSystem->useQtSpeech = qtspeechGroupBox->isChecked();
}
TextToSpeechSystem *TextToSpeechConfigurationWidget::getTTSSystem() const
{
return ttsSystem;
}
void TextToSpeechConfigurationWidget::readOptions(const QString &langGroup)
{
ttsSystem->readOptions(langGroup);
urlReq->setUrl(QUrl::fromLocalFile(ttsSystem->ttsCommand));
stdInButton->setChecked(ttsSystem->stdIn);
characterCodingBox->setCurrentIndex(ttsSystem->encoding);
qtspeechGroupBox->setChecked(ttsSystem->useQtSpeech);
engineComboBox->setCurrentText(ttsSystem->ttsEngine);
if (!ttsSystem->ttsVoice.isEmpty()) {
voiceComboBox->setCurrentText(ttsSystem->ttsVoice);
}
}
void TextToSpeechConfigurationWidget::saveOptions(const QString &langGroup)
{
ttsSystem->saveOptions(langGroup);
}
|