diff --git a/resources/i18n/en.json b/resources/i18n/en.json index ae77e82da..b603d42dd 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -171,5 +171,6 @@ "scroll-previous-tab": "Scroll to previous tab", "read-article": "Read article", "read-text": "Read selected text", - "stop": "Stop" + "stop": "Stop", + "voice": "Voice" } diff --git a/resources/i18n/qqq.json b/resources/i18n/qqq.json index baf836abb..542853de4 100644 --- a/resources/i18n/qqq.json +++ b/resources/i18n/qqq.json @@ -179,5 +179,6 @@ "scroll-previous-tab": "Represents the action of scrolling to the previous tab of the current tab which toward the start of the tab bar.", "read-article": "Represents the action of letting the computer read out all the text in the current article.", "read-text": "Represents the action of letting the computer read out the selected text on the article.", - "stop": "{{Identical|Stop}}" + "stop": "{{Identical|Stop}}", + "voice": "{{Identical|Voice}}" } diff --git a/src/texttospeechbar.cpp b/src/texttospeechbar.cpp index 08b590fe9..84cf63e4e 100644 --- a/src/texttospeechbar.cpp +++ b/src/texttospeechbar.cpp @@ -10,6 +10,7 @@ TextToSpeechBar::TextToSpeechBar(QWidget *parent) close(); mp_ui->setupUi(this); mp_ui->stopButton->setText(gt("stop")); + mp_ui->voiceLabel->setText(gt("voice")); connect(mp_speech, &QTextToSpeech::stateChanged, this, &TextToSpeechBar::onStateChanged); connect(mp_ui->stopButton, &QPushButton::released, this, @@ -59,7 +60,25 @@ void TextToSpeechBar::onStateChanged(QTextToSpeech::State state) void TextToSpeechBar::languageSelected(int index) { QLocale locale = mp_ui->langComboBox->itemData(index).toLocale(); - mp_speech->setLocale(locale); + disconnect(mp_ui->voiceComboBox, &QComboBox::currentIndexChanged, this, &TextToSpeechBar::voiceSelected); + mp_ui->voiceComboBox->clear(); + + m_voices = mp_speech->availableVoices(); + QVoice currentVoice = mp_speech->voice(); + for (auto voice : m_voices) + { + mp_ui->voiceComboBox->addItem(QString("%1 - %2 - %3").arg(voice.name()) + .arg(QVoice::genderName(voice.gender())) + .arg(QVoice::ageName(voice.age()))); + if (voice.name() == currentVoice.name()) + mp_ui->voiceComboBox->setCurrentIndex(mp_ui->voiceComboBox->count() - 1); + } + connect(mp_ui->voiceComboBox, &QComboBox::currentIndexChanged, this, &TextToSpeechBar::voiceSelected); +} + +void TextToSpeechBar::voiceSelected(int index) +{ + mp_speech->setVoice(m_voices.at(index)); } void TextToSpeechBar::speechBarClose() diff --git a/src/texttospeechbar.h b/src/texttospeechbar.h index 56621aeaa..4ebc50a07 100644 --- a/src/texttospeechbar.h +++ b/src/texttospeechbar.h @@ -20,11 +20,13 @@ class TextToSpeechBar : public QFrame public slots: void speechBarClose(); void languageSelected(int index); + void voiceSelected(int index); void onStateChanged(QTextToSpeech::State state); private: QTextToSpeech *mp_speech; Ui::TextToSpeechBar *mp_ui; + QVector m_voices; }; #endif // TEXTTOSPEECHMANAGER_H diff --git a/src/texttospeechbar.ui b/src/texttospeechbar.ui index 819c91cf0..8339c6b4c 100644 --- a/src/texttospeechbar.ui +++ b/src/texttospeechbar.ui @@ -37,6 +37,20 @@ + + + + + + + + + + + true + + +