Port KAccessible app to KSpeech
Miha Čančula <[email protected]>
| Newsgroups | gmane.comp.kde.devel.accessibility |
|---|---|
| Message-ID | <[email protected]> |
Hello! Currently, KAccessible uses speech-dispatcher directly, rather than through Jovie. Because of this, it has its own speaker configuration and whatnot. I changed this so it uses Jovie through D-Bus, meaning there is only one place for configuration. It also removes a compile-time dependency (Jovie is only needed at run-time). I'm not subscribed to this list (please CC me), so I don't know if this was discussed before. If you think it's better to keep things this way, just let me know. I'm attaching the patch, there are probably still things that I missed and could be changed or removed. I do have a svn account though, so I can commit it. Regards, Miha Čančula _______________________________________________ kde-accessibility mailing list [email protected] https://mail.kde.org/mailman/listinfo/kde-accessibility
kaccessible-jovie.patch
(text/x-patch, 9.3 KB)
Index: /home/miha/kdesrc/kdeaccessibility/kaccessible/kaccessibleapp.h
===================================================================
--- /home/miha/kdesrc/kdeaccessibility/kaccessible/kaccessibleapp.h (revision 1223553)
+++ /home/miha/kdesrc/kdeaccessibility/kaccessible/kaccessibleapp.h (working copy)
@@ -28,6 +28,7 @@
/**
* Highlevel text-to-speech interface.
*/
+
class Speaker : public QObject
{
Q_OBJECT
Index: /home/miha/kdesrc/kdeaccessibility/kaccessible/kaccessibleapp.cpp
===================================================================
--- /home/miha/kdesrc/kdeaccessibility/kaccessible/kaccessibleapp.cpp (revision 1223553)
+++ /home/miha/kdesrc/kdeaccessibility/kaccessible/kaccessibleapp.cpp (working copy)
@@ -54,11 +54,9 @@
#include <kdebug.h>
#include <kpagewidget.h>
#include <kpagewidgetmodel.h>
+#include <kspeechinterface.h>
+#include <kspeech.h>
-#if defined(SPEECHD_FOUND)
-#include <libspeechd.h>
-#endif
-
Q_GLOBAL_STATIC(Speaker, speaker)
class Speaker::Private
@@ -68,53 +66,25 @@
int m_voiceType;
QStack< QPair<QString,Speaker::Priority> > m_sayStack;
QMutex m_mutex;
-#if defined(SPEECHD_FOUND)
- SPDConnection *m_connection;
-#endif
+ org::kde::KSpeech* m_speech;
explicit Private()
: m_isSpeaking(false)
, m_voiceType(1)
-#if defined(SPEECHD_FOUND)
- , m_connection(0)
-#endif
{
+
}
-#if defined(SPEECHD_FOUND)
- static void speechdCallback(size_t msg_id, size_t client_id, SPDNotificationType state)
- {
- Q_UNUSED(msg_id);
- Q_UNUSED(client_id);
- switch(state) {
- case SPD_EVENT_BEGIN:
- Speaker::instance()->setSpeaking(true);
- break;
- case SPD_EVENT_END:
- Speaker::instance()->setSpeaking(false);
- QTimer::singleShot(0, Speaker::instance(), SLOT(sayNext()));
- break;
- case SPD_EVENT_CANCEL:
- Speaker::instance()->setSpeaking(false);
- Speaker::instance()->clearSayStack();
- break;
- case SPD_EVENT_PAUSE:
- break;
- case SPD_EVENT_RESUME:
- break;
- case SPD_EVENT_INDEX_MARK:
- break;
- }
- }
-#endif
};
Speaker::Speaker()
: d(new Private)
{
+ d->m_speech = new org::kde::KSpeech(QLatin1String("org.kde.kttsd"), QLatin1String("/KSpeech"), QDBusConnection::sessionBus());
}
Speaker::~Speaker()
{
disconnect();
+ delete d->m_speech;
delete d;
}
@@ -125,51 +95,16 @@
bool Speaker::isConnected() const
{
-#if defined(SPEECHD_FOUND)
- return d->m_connection;
-#else
return true;
-#endif
}
void Speaker::disconnect()
{
-#if defined(SPEECHD_FOUND)
- if(d->m_connection) {
- spd_set_notification_off(d->m_connection, SPD_BEGIN);
- spd_set_notification_off(d->m_connection, SPD_END);
- spd_set_notification_off(d->m_connection, SPD_CANCEL);
- spd_set_notification_off(d->m_connection, SPD_PAUSE);
- spd_set_notification_off(d->m_connection, SPD_RESUME);
- d->m_connection->callback_begin = d->m_connection->callback_end = d->m_connection->callback_cancel = d->m_connection->callback_pause = d->m_connection->callback_resume = 0;
- spd_cancel_all(d->m_connection);
- spd_close(d->m_connection);
- d->m_connection = 0;
- d->m_isSpeaking = false;
- d->m_sayStack.clear();
- }
-#endif
}
bool Speaker::reconnect()
{
disconnect();
-
-#if defined(SPEECHD_FOUND)
- d->m_connection = spd_open("kaccessible", "main", NULL, SPD_MODE_THREADED); //SPD_MODE_SINGLE);
- if( ! d->m_connection) {
- kWarning() << "Failed to connect with speech-dispatcher";
- return false;
- }
-
- d->m_connection->callback_begin = d->m_connection->callback_end = d->m_connection->callback_cancel = d->m_connection->callback_pause = d->m_connection->callback_resume = Private::speechdCallback;
- spd_set_notification_on(d->m_connection, SPD_BEGIN);
- spd_set_notification_on(d->m_connection, SPD_END);
- spd_set_notification_on(d->m_connection, SPD_CANCEL);
- spd_set_notification_on(d->m_connection, SPD_PAUSE);
- spd_set_notification_on(d->m_connection, SPD_RESUME);
-#endif
-
setVoiceType(d->m_voiceType);
return true;
}
@@ -188,11 +123,6 @@
{
QMutexLocker locker(&d->m_mutex);
d->m_sayStack.clear();
-#if defined(SPEECHD_FOUND)
- if(d->m_connection) {
- spd_cancel_all(d->m_connection);
- }
-#endif
}
bool Speaker::say(const QString& text, Priority priority)
@@ -213,51 +143,23 @@
return;
}
QPair<QString,Speaker::Priority> p = d->m_sayStack.pop();
-#if defined(SPEECHD_FOUND)
- if(d->m_connection) {
- SPDPriority spdpriority = (SPDPriority) p.second;
- int msg_id = spd_say(d->m_connection, spdpriority, p.first.toUtf8().data());
- if(msg_id == -1) {
- kWarning() << "Failed to say text=" << p.first;
- }
- }
-#else
- //QDBusInterface iface("org.kde.jovie","/KSpeech");
- //iface.asyncCall("say", text, 0);
-#endif
+ d->m_speech->say(p.first, KSpeech::soPlainText);
+
}
char** Speaker::modules() const
{
-#if defined(SPEECHD_FOUND)
- if(d->m_connection)
- return spd_list_modules(d->m_connection);
-#endif
return NULL;
}
char** Speaker::voices() const
{
-#if defined(SPEECHD_FOUND)
- if(d->m_connection)
- return spd_list_voices(d->m_connection);
-#endif
return NULL;
}
QStringList Speaker::languages() const
{
QStringList result;
-#if defined(SPEECHD_FOUND)
- if(d->m_connection) {
- SPDVoice** voices = spd_list_synthesis_voices(d->m_connection);
- while(voices && voices[0]) {
- const QString lng = QString::fromLatin1(voices[0]->language);
- if(!lng.isEmpty() && !result.contains(lng)) result.append(lng);
- ++voices;
- }
- }
-#endif
return result;
}
@@ -269,11 +171,6 @@
void Speaker::setVoiceType(int type)
{
d->m_voiceType = type;
-#if defined(SPEECHD_FOUND)
- if(d->m_connection) {
- spd_set_voice_type_all(d->m_connection, (SPDVoiceType) type);
- }
-#endif
}
void Speaker::clearSayStack()
@@ -567,34 +464,11 @@
readerPage->setLayout(readerLayout);
QCheckBox *enableReader = new QCheckBox(i18n("Enable Screenreader"));
readerLayout->addWidget(enableReader,0,0,1,2);
-#if defined(SPEECHD_FOUND)
enableReader->setChecked(d->m_adaptor->speechEnabled());
connect(d->m_adaptor, SIGNAL(speechEnabledChanged(bool)), enableReader, SLOT(setChecked(bool)));
connect(enableReader, SIGNAL(stateChanged(int)), this, SLOT(enableReaderChanged(int)));
-
- QLabel *voiceTypeLabel = new QLabel(i18n("Voice Type:"), readerPage);
- readerLayout->addWidget(voiceTypeLabel,1,0);
- d->m_voiceTypeCombo = new QComboBox(this);
- voiceTypeLabel->setBuddy(d->m_voiceTypeCombo);
- d->m_voiceTypeCombo->addItem(i18n("Male 1"), SPD_MALE1);
- d->m_voiceTypeCombo->addItem(i18n("Male 2"), SPD_MALE2);
- d->m_voiceTypeCombo->addItem(i18n("Male 3"), SPD_MALE3);
- d->m_voiceTypeCombo->addItem(i18n("Female 1"), SPD_FEMALE1);
- d->m_voiceTypeCombo->addItem(i18n("Female 2"), SPD_FEMALE2);
- d->m_voiceTypeCombo->addItem(i18n("Female 3"), SPD_FEMALE3);
- d->m_voiceTypeCombo->addItem(i18n("Boy"), SPD_CHILD_MALE);
- d->m_voiceTypeCombo->addItem(i18n("Girl"), SPD_CHILD_FEMALE);
- for(int i = 0; i < d->m_voiceTypeCombo->count(); ++i)
- if(d->m_voiceTypeCombo->itemData(i).toInt() == Speaker::instance()->voiceType())
- d->m_voiceTypeCombo->setCurrentIndex(i);
- connect(d->m_voiceTypeCombo, SIGNAL(activated(int)), this, SLOT(voiceTypeChanged(int)));
- readerLayout->addWidget(d->m_voiceTypeCombo,1,1);
-
- readerLayout->setRowStretch(2,1);
-#else
- enableReader->setEnabled(false);
readerLayout->setRowStretch(1,1);
-#endif
+
readerLayout->setColumnStretch(2,1);
d->addPage(readerPage, KIcon(QLatin1String( "text-speak" )), i18n("Screenreader"));
Index: /home/miha/kdesrc/kdeaccessibility/kaccessible/CMakeLists.txt
===================================================================
--- /home/miha/kdesrc/kdeaccessibility/kaccessible/CMakeLists.txt (revision 1223553)
+++ /home/miha/kdesrc/kdeaccessibility/kaccessible/CMakeLists.txt (working copy)
@@ -59,15 +59,10 @@
##################################################################
-macro_optional_find_package(Speechd)
-if(SPEECHD_FOUND)
- set(SPEECH_LIB speechd)
- add_definitions(-DSPEECHD_FOUND)
-endif(SPEECHD_FOUND)
-
set(kaccessibleapp_SRCS kaccessibleapp.cpp)
qt4_wrap_cpp(kaccessibleapp_SRCS kaccessibleapp.h)
+qt4_add_dbus_interfaces(kaccessibleapp_SRCS ${KDE4_DBUS_INTERFACES_DIR}/org.kde.KSpeech.xml)
add_executable(kaccessibleapp ${kaccessibleapp_SRCS})
#INCLUDE_DIRECTORIES(. .. ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
-target_link_libraries(kaccessibleapp ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTDBUS_LIBRARY} ${SPEECH_LIB})
+target_link_libraries(kaccessibleapp ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTDBUS_LIBRARY})
install(TARGETS kaccessibleapp RUNTIME DESTINATION ${LIBEXEC_INSTALL_DIR})
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEABECAAYFAk1vzuoACgkQMJUOPb6zeZ74UwCgmNMmecauFetb1DLV0czJiGgV e5gAnjcj2l4+BbKVfPZAWWtIeRYsBGIh =0Xlj -----END PGP SIGNATURE-----