Skip to content

Commit

Permalink
Merge pull request #1143 from kiwix/Issue#44-tts
Browse files Browse the repository at this point in the history
Implement Basic Text to Speech
  • Loading branch information
kelson42 authored Nov 15, 2024
2 parents 1a0580d + e3106ea commit 5d7eb1a
Show file tree
Hide file tree
Showing 17 changed files with 611 additions and 2 deletions.
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Build-Depends: debhelper-compat (= 13),
pkg-config,
qtbase5-dev,
qtwebengine5-dev,
libqt5texttospeech5-dev,
libkiwix-dev (>= 14.0.0), libkiwix-dev (<< 15.0.0),
libzim-dev (>= 9.0.0), libzim-dev (<< 10.0.0),
Standards-Version: 4.5.0
Expand Down
7 changes: 7 additions & 0 deletions kiwix-desktop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
QT += core gui network
QT += webenginewidgets webchannel
QT += printsupport
qtHaveModule(texttospeech): QT += texttospeech

# Avoid stripping incompatible files, due to false identification as executables, on WSL
DETECT_WSL = $$system(test -f /proc/sys/fs/binfmt_misc/WSLInterop && echo true || echo false)
Expand Down Expand Up @@ -94,6 +95,8 @@ SOURCES += \
src/zimview.cpp \
src/multizimbutton.cpp \

qtHaveModule(texttospeech): SOURCES += src/texttospeechbar.cpp \

HEADERS += \
src/choiceitem.h \
src/contentmanagerdelegate.h \
Expand Down Expand Up @@ -149,6 +152,8 @@ HEADERS += \
src/multizimbutton.h \
src/kiwixwebchannelobject.h \

qtHaveModule(texttospeech): HEADERS += src/texttospeechbar.h \

FORMS += \
src/choiceitem.ui \
src/contentmanagerview.ui \
Expand All @@ -163,6 +168,8 @@ FORMS += \
ui/settings.ui \
src/tableofcontentbar.ui \

qtHaveModule(texttospeech): FORMS += src/texttospeechbar.ui \

include(subprojects/QtSingleApplication/src/qtsingleapplication.pri)
CODECFORSRC = UTF-8

Expand Down
61 changes: 61 additions & 0 deletions resources/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,64 @@ ContentTypeFilter {
#tableofcontentbar QScrollBar::handle {
background-color: grey;
}

/* ----------------------------------------
Text to Speech Page
*/

TextToSpeechBar {
border-top: 1px solid #ccc;
}

TextToSpeechBar #closeButton {
outline: none;
max-height: 36px;
max-width: 36px;
border: 1px solid #ccc;
border-radius: 0;
}

TextToSpeechBar #stopButton {
outline: none;
max-height: 36px;
padding: 0px 10px;

background-color: white;
border: 1px solid #ccc;
border-radius: 0;
}

TextToSpeechBar #stopButton:hover {
background-color: #D9E9FF;
border: 1px solid #3366CC;
}

TextToSpeechBar #stopButton:disabled {
color: grey;
background-color: darkgrey;
}

TextToSpeechBar QComboBox::drop-down {
height: 22px;
width: 15px;
padding: 0px 2px;
margin: 0px;

image: url(":/icons/drop-down.svg");
background-color: white;
}

TextToSpeechBar QComboBox {
background-color: white;
border: 1px solid #ccc;
}

TextToSpeechBar QAbstractItemView QScrollBar {
width: 5px;
border: none;
outline: none;
}

TextToSpeechBar QAbstractItemView QScrollBar::handle {
background-color: grey;
}
9 changes: 8 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,12 @@
"scroll-next-tab": "Scroll to next tab",
"scroll-previous-tab": "Scroll to previous tab",
"kiwix-search": "Kiwix search",
"search-options": "Search Options"
"search-options": "Search Options",
"read-article": "Read article",
"read-text": "Read selected text",
"read-stop": "Stop reading",
"stop": "Stop",
"voice": "Voice",
"select-read-voice": "Select reading voice",
"select-read-language": "Select reading language"
}
9 changes: 8 additions & 1 deletion resources/i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,12 @@
"scroll-next-tab": "Represents the action of scrolling to the next tab of the current tab which toward the end of the tab bar.",
"scroll-previous-tab": "Represents the action of scrolling to the previous tab of the current tab which toward the start of the tab bar.",
"kiwix-search": "Title text for a list of search results, which notes to the user those are from Kiwix's Search Engine",
"search-options": "The term for a collection of additional search filtering options to help users narrow down search results."
"search-options": "The term for a collection of additional search filtering options to help users narrow down search results.",
"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.",
"read-stop": "Represents the action of stopping the on-going reading.",
"stop": "{{Identical|Stop}}",
"voice": "{{Identical|Voice}}",
"select-read-voice": "Represents the action of opening the voice selection for text-to-speech.",
"select-read-language": "Represents the action of opening the language selection for text-to-speech."
}
3 changes: 3 additions & 0 deletions resources/icons/drop-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/icons/stop-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions resources/kiwix.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@
<file>icons/home-button.svg</file>
<file>icons/more-vertical.svg</file>
<file>icons/caret-left-solid.svg</file>
<file>icons/stop-circle.svg</file>
<file>icons/drop-down.svg</file>
</qresource>
</RCC>
18 changes: 18 additions & 0 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,14 @@ void KiwixApp::createActions()
DISABLE_ACTION(HistoryBackAction);
DISABLE_ACTION(HistoryForwardAction);

CREATE_ACTION_SHORTCUT(ReadArticleAction, gt("read-article"), QKeySequence(Qt::ALT | Qt::SHIFT | Qt::Key_A));
CREATE_ACTION_SHORTCUT(ReadTextAction, gt("read-text"), QKeySequence(Qt::ALT | Qt::SHIFT | Qt::Key_S));
CREATE_ACTION_SHORTCUT(ReadStopAction, gt("read-stop"), QKeySequence(Qt::ALT | Qt::SHIFT | Qt::Key_X));
CREATE_ACTION_SHORTCUT(ToggleTTSLanguageAction, gt("select-read-language"), QKeySequence(Qt::ALT | Qt::SHIFT | Qt::Key_L));
CREATE_ACTION_SHORTCUT(ToggleTTSVoiceAction, gt("select-read-voice"), QKeySequence(Qt::ALT | Qt::SHIFT | Qt::Key_V));
mpa_actions[ToggleTTSLanguageAction]->setCheckable(true);
mpa_actions[ToggleTTSVoiceAction]->setCheckable(true);

CREATE_ACTION_ICON_SHORTCUT(PrintAction, "print", gt("print"), QKeySequence::Print);
connect(mpa_actions[PrintAction], &QAction::triggered,
this, &KiwixApp::printPage);
Expand Down Expand Up @@ -541,6 +549,11 @@ void KiwixApp::saveWindowState()
mp_session->setValue("windowState", getMainWindow()->saveState());
}

void KiwixApp::saveVoiceName(const QString& langName, const QString& voiceName)
{
mp_session->setValue("voice/" + langName, voiceName);
}

void KiwixApp::restoreWindowState()
{
getMainWindow()->restoreGeometry(mp_session->value("geometry").toByteArray());
Expand All @@ -557,6 +570,11 @@ void KiwixApp::savePrevSaveDir(const QString &prevSaveDir)
mp_session->setValue("prevSaveDir", prevSaveDir);
}

QString KiwixApp::getSavedVoiceName(const QString& langName) const
{
return mp_session->value("voice/" + langName, "").toString();
}

QString KiwixApp::getPrevSaveDir() const
{
QString prevSaveDir = mp_session->value("prevSaveDir", DEFAULT_SAVE_DIR).toString();
Expand Down
7 changes: 7 additions & 0 deletions src/kiwixapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ class KiwixApp : public QtSingleApplication
ToggleTOCAction,
ToggleReadingListAction,
ToggleAddBookmarkAction,
ToggleTTSLanguageAction,
ToggleTTSVoiceAction,
ZoomInAction,
ZoomOutAction,
ZoomResetAction,
NextTabAction,
PreviousTabAction,
HistoryBackAction,
HistoryForwardAction,
ReadTextAction,
ReadArticleAction,
ReadStopAction,
HelpAction,
FeedbackAction,
ReportBugAction,
Expand Down Expand Up @@ -95,9 +100,11 @@ class KiwixApp : public QtSingleApplication
QString parseStyleFromFile(QString filePath);
void saveListOfOpenTabs();
void saveWindowState();
void saveVoiceName(const QString& langName, const QString& voiceName);
void restoreWindowState();
void saveCurrentTabIndex();
void savePrevSaveDir(const QString& prevSaveDir);
QString getSavedVoiceName(const QString& langName) const;
QString getPrevSaveDir() const;

public slots:
Expand Down
7 changes: 7 additions & 0 deletions src/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ MainMenu::MainMenu(QWidget *parent) :
m_editMenu.ADD_ACTION(FindInPageAction);
m_editMenu.ADD_ACTION(ToggleAddBookmarkAction);
m_editMenu.ADD_ACTION(OpenMultiZimAction);
#if defined(QT_TEXTTOSPEECH_LIB)
m_editMenu.ADD_ACTION(ReadArticleAction);
m_editMenu.ADD_ACTION(ReadTextAction);
m_editMenu.ADD_ACTION(ReadStopAction);
#endif
addMenu(&m_editMenu);

m_viewMenu.setTitle(gt("view"));
m_viewMenu.ADD_ACTION(ToggleFullscreenAction);
m_viewMenu.ADD_ACTION(ToggleTOCAction);
m_viewMenu.ADD_ACTION(ToggleReadingListAction);
m_viewMenu.ADD_ACTION(ToggleTTSLanguageAction);
m_viewMenu.ADD_ACTION(ToggleTTSVoiceAction);
m_viewMenu.ADD_ACTION(ZoomInAction);
m_viewMenu.ADD_ACTION(ZoomOutAction);
m_viewMenu.ADD_ACTION(ZoomResetAction);
Expand Down
Loading

0 comments on commit 5d7eb1a

Please sign in to comment.