diff options
author | Michael Dippold <mike@dippold.com> | 2016-07-31 21:22:11 -0700 |
---|---|---|
committer | Maurice Kalinowski <maurice.kalinowski@qt.io> | 2016-08-09 13:37:03 +0000 |
commit | 716d5224941e5ded991cc8e2367c83a20d96899e (patch) | |
tree | 0d4472cdaaec9b8c0bfb61c3e19db0856875b9d1 | |
parent | 134cdfda5b20dee2644b38d8700f0a327d555cd6 (diff) |
Refactor android implementation to plugin structure
The android implementation was no longer building.
Change-Id: Idf411c5a613ca09e2131b1e1cfdc74cc737d07bf
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
16 files changed, 281 insertions, 75 deletions
diff --git a/src/tts/android/android.pro b/src/plugins/tts/android/android.pro index df58469..0a85400 100644 --- a/src/tts/android/android.pro +++ b/src/plugins/tts/android/android.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = jar +SUBDIRS = jar src diff --git a/src/tts/android/jar/AndroidManifest.xml b/src/plugins/tts/android/jar/AndroidManifest.xml index d4c1b88..d4c1b88 100644 --- a/src/tts/android/jar/AndroidManifest.xml +++ b/src/plugins/tts/android/jar/AndroidManifest.xml diff --git a/src/tts/android/jar/bundledjar.pro b/src/plugins/tts/android/jar/bundledjar.pro index fce2c53..fce2c53 100644 --- a/src/tts/android/jar/bundledjar.pro +++ b/src/plugins/tts/android/jar/bundledjar.pro diff --git a/src/tts/android/jar/distributedjar.pro b/src/plugins/tts/android/jar/distributedjar.pro index 9f163b1..9f163b1 100644 --- a/src/tts/android/jar/distributedjar.pro +++ b/src/plugins/tts/android/jar/distributedjar.pro diff --git a/src/tts/android/jar/jar.pri b/src/plugins/tts/android/jar/jar.pri index 4c14cec..4c14cec 100644 --- a/src/tts/android/jar/jar.pri +++ b/src/plugins/tts/android/jar/jar.pri diff --git a/src/tts/android/jar/jar.pro b/src/plugins/tts/android/jar/jar.pro index 8d19c1b..8d19c1b 100644 --- a/src/tts/android/jar/jar.pro +++ b/src/plugins/tts/android/jar/jar.pro diff --git a/src/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java b/src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java index 8770a1e..8770a1e 100644 --- a/src/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java +++ b/src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java diff --git a/src/plugins/tts/android/src/android_plugin.json b/src/plugins/tts/android/src/android_plugin.json new file mode 100644 index 0000000..ec4e10c --- /dev/null +++ b/src/plugins/tts/android/src/android_plugin.json @@ -0,0 +1,6 @@ +{ + "Keys": ["android"], + "Provider": "android", + "Version": 100, + "Features": [] +} diff --git a/src/tts/qtexttospeech_android.cpp b/src/plugins/tts/android/src/qtexttospeech_android.cpp index d29701e..0aa9030 100644 --- a/src/tts/qtexttospeech_android.cpp +++ b/src/plugins/tts/android/src/qtexttospeech_android.cpp @@ -33,48 +33,16 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "qtexttospeech_android.h" -#include "qtexttospeech_p.h" #include <jni.h> -#include <QtCore/private/qjni_p.h> #include <QtCore/private/qjnihelpers_p.h> QT_BEGIN_NAMESPACE static jclass g_qtSpeechClass = 0; -class QTextToSpeechPrivateAndroid : public QTextToSpeechPrivate -{ -public: - QTextToSpeechPrivateAndroid(QTextToSpeech *speech); - ~QTextToSpeechPrivateAndroid(); - - QVector<QLocale> availableLocales() const Q_DECL_OVERRIDE; - QVector<QVoice> availableVoices() const Q_DECL_OVERRIDE; - - void say(const QString &text) Q_DECL_OVERRIDE; - void stop() Q_DECL_OVERRIDE; - void pause() Q_DECL_OVERRIDE; - void resume() Q_DECL_OVERRIDE; - - double rate() const Q_DECL_OVERRIDE; - void setRate(double rate) Q_DECL_OVERRIDE; - double pitch() const Q_DECL_OVERRIDE; - void setPitch(double pitch) Q_DECL_OVERRIDE; - int volume() const Q_DECL_OVERRIDE; - void setVolume(int volume) Q_DECL_OVERRIDE; - void setLocale(const QLocale &locale) Q_DECL_OVERRIDE; - QLocale locale() const Q_DECL_OVERRIDE; - void setVoice(const QVoice &voice) Q_DECL_OVERRIDE; - QVoice voice() const Q_DECL_OVERRIDE; - QTextToSpeech::State state() const Q_DECL_OVERRIDE; - void setState(QTextToSpeech::State state); - -private: - QString m_text; - QJNIObjectPrivate m_speech; -}; - -typedef QMap<jlong, QTextToSpeechPrivateAndroid *> TextToSpeechMap; + +typedef QMap<jlong, QTextToSpeechEngineAndroid *> TextToSpeechMap; Q_GLOBAL_STATIC(TextToSpeechMap, textToSpeechMap) static void notifyError(JNIEnv *env, jobject thiz, jlong id) @@ -82,7 +50,7 @@ static void notifyError(JNIEnv *env, jobject thiz, jlong id) Q_UNUSED(env); Q_UNUSED(thiz); - QTextToSpeechPrivateAndroid *const tts = (*textToSpeechMap)[id]; + QTextToSpeechEngineAndroid *const tts = (*textToSpeechMap)[id]; if (!tts) return; @@ -94,7 +62,7 @@ static void notifyReady(JNIEnv *env, jobject thiz, jlong id) Q_UNUSED(env); Q_UNUSED(thiz); - QTextToSpeechPrivateAndroid *const tts = (*textToSpeechMap)[id]; + QTextToSpeechEngineAndroid *const tts = (*textToSpeechMap)[id]; if (!tts || tts->state() == QTextToSpeech::Paused) return; @@ -106,7 +74,7 @@ static void notifySpeaking(JNIEnv *env, jobject thiz, jlong id) Q_UNUSED(env); Q_UNUSED(thiz); - QTextToSpeechPrivateAndroid *const tts = (*textToSpeechMap)[id]; + QTextToSpeechEngineAndroid *const tts = (*textToSpeechMap)[id]; if (!tts) return; @@ -147,9 +115,13 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/) return JNI_VERSION_1_4; } -QTextToSpeechPrivateAndroid::QTextToSpeechPrivateAndroid(QTextToSpeech *speech) - : QTextToSpeechPrivate(speech) +QTextToSpeechEngineAndroid::QTextToSpeechEngineAndroid(const QVariantMap ¶meters, QObject *parent) + : QTextToSpeechEngine(parent) + , m_speech() + , m_state(QTextToSpeech::Ready) + , m_text() { + Q_UNUSED(parameters) Q_ASSERT(g_qtSpeechClass); const jlong id = reinterpret_cast<jlong>(this); @@ -161,19 +133,13 @@ QTextToSpeechPrivateAndroid::QTextToSpeechPrivateAndroid(QTextToSpeech *speech) (*textToSpeechMap)[id] = this; } -QTextToSpeechPrivateAndroid::~QTextToSpeechPrivateAndroid() +QTextToSpeechEngineAndroid::~QTextToSpeechEngineAndroid() { textToSpeechMap->remove(reinterpret_cast<jlong>(this)); m_speech.callMethod<void>("shutdown"); } -QTextToSpeech::QTextToSpeech(QObject *parent) - : QObject(*new QTextToSpeechPrivateAndroid(this), parent) -{ - qRegisterMetaType<QTextToSpeech::State>(); -} - -void QTextToSpeechPrivateAndroid::say(const QString &text) +void QTextToSpeechEngineAndroid::say(const QString &text) { if (text.isEmpty()) return; @@ -188,21 +154,21 @@ void QTextToSpeechPrivateAndroid::say(const QString &text) m_speech.callMethod<void>("say", "(Ljava/lang/String;)V", jstr); } -QTextToSpeech::State QTextToSpeechPrivateAndroid::state() const +QTextToSpeech::State QTextToSpeechEngineAndroid::state() const { return m_state; } -void QTextToSpeechPrivateAndroid::setState(QTextToSpeech::State state) +void QTextToSpeechEngineAndroid::setState(QTextToSpeech::State state) { if (m_state == state) return; m_state = state; - emitStateChanged(m_state); + emit stateChanged(m_state); } -void QTextToSpeechPrivateAndroid::stop() +void QTextToSpeechEngineAndroid::stop() { if (m_state == QTextToSpeech::Ready) return; @@ -210,7 +176,7 @@ void QTextToSpeechPrivateAndroid::stop() m_speech.callMethod<void>("stop", "()V"); } -void QTextToSpeechPrivateAndroid::pause() +void QTextToSpeechEngineAndroid::pause() { if (m_state == QTextToSpeech::Paused) return; @@ -219,7 +185,7 @@ void QTextToSpeechPrivateAndroid::pause() setState(QTextToSpeech::Paused); } -void QTextToSpeechPrivateAndroid::resume() +void QTextToSpeechEngineAndroid::resume() { if (m_state != QTextToSpeech::Paused) return; @@ -227,69 +193,68 @@ void QTextToSpeechPrivateAndroid::resume() say(m_text); } -double QTextToSpeechPrivateAndroid::pitch() const +double QTextToSpeechEngineAndroid::pitch() const { jfloat pitch = m_speech.callMethod<jfloat>("pitch"); return double(pitch - 1.0f); } -void QTextToSpeechPrivateAndroid::setPitch(double pitch) +bool QTextToSpeechEngineAndroid::setPitch(double pitch) { // 0 == SUCCESS and 1.0 == Android API's normal pitch. - if (m_speech.callMethod<int>("setPitch", "(F)I", pitch + 1.0) == 0) - emitPitchChanged(pitch); + return m_speech.callMethod<int>("setPitch", "(F)I", pitch + 1.0f) == 0; } -double QTextToSpeechPrivateAndroid::rate() const +double QTextToSpeechEngineAndroid::rate() const { jfloat rate = m_speech.callMethod<jfloat>("rate"); return double(rate - 1.0f); } -void QTextToSpeechPrivateAndroid::setRate(double rate) +bool QTextToSpeechEngineAndroid::setRate(double rate) { // 0 == SUCCESS and 1.0 == Android API's normal rate. - if (m_speech.callMethod<int>("setRate", "(F)I", rate + 1.0f) == 0) - emitRateChanged(rate); + return (m_speech.callMethod<int>("setRate", "(F)I", rate + 1.0f) == 0); } -int QTextToSpeechPrivateAndroid::volume() const +double QTextToSpeechEngineAndroid::volume() const { jfloat volume = m_speech.callMethod<jfloat>("volume"); - return int(volume * 100); + return volume; } -void QTextToSpeechPrivateAndroid::setVolume(int volume) +bool QTextToSpeechEngineAndroid::setVolume(double volume) { // 0 == SUCCESS - if (m_speech.callMethod<jint>("setVolume", "(F)I", float(volume) / 100) == 0) - emitVolumeChanged(volume); + return m_speech.callMethod<jint>("setVolume", "(F)I", float(volume)) == 0; } -QVector<QLocale> QTextToSpeechPrivateAndroid::availableLocales() const +QVector<QLocale> QTextToSpeechEngineAndroid::availableLocales() const { return QVector<QLocale>(); } -void QTextToSpeechPrivateAndroid::setLocale(const QLocale & /* locale */) +bool QTextToSpeechEngineAndroid::setLocale(const QLocale & /* locale */) { + return false; } -QLocale QTextToSpeechPrivateAndroid::locale() const +QLocale QTextToSpeechEngineAndroid::locale() const { return QLocale(); } -QVector<QVoice> QTextToSpeechPrivateAndroid::availableVoices() const +QVector<QVoice> QTextToSpeechEngineAndroid::availableVoices() const { return QVector<QVoice>(); } -void QTextToSpeechPrivateAndroid::setVoice(const QVoice & /* voice */) +bool QTextToSpeechEngineAndroid::setVoice(const QVoice & /* voice */) { + return false; } -QVoice QTextToSpeechPrivateAndroid::voice() const +QVoice QTextToSpeechEngineAndroid::voice() const { return QVoice(); } diff --git a/src/plugins/tts/android/src/qtexttospeech_android.h b/src/plugins/tts/android/src/qtexttospeech_android.h new file mode 100644 index 0000000..81a90bf --- /dev/null +++ b/src/plugins/tts/android/src/qtexttospeech_android.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Speech module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTEXTTOSPEECHENGINE_ANDROID_H +#define QTEXTTOSPEECHENGINE_ANDROID_H + +#include "qtexttospeechengine.h" +#include "qvoice.h" + +#include <QtCore/private/qjni_p.h> +#include <QtCore/QString> +#include <QtCore/QLocale> +#include <QtCore/QVector> + +QT_BEGIN_NAMESPACE + +class QTextToSpeechEngineAndroid : public QTextToSpeechEngine +{ + Q_OBJECT + +public: + QTextToSpeechEngineAndroid(const QVariantMap ¶meters, QObject *parent); + virtual ~QTextToSpeechEngineAndroid(); + + // Plug-in API: + QVector<QLocale> availableLocales() const override; + QVector<QVoice> availableVoices() const override; + void say(const QString &text) override; + void stop() override; + void pause() override; + void resume() override; + double rate() const override; + bool setRate(double rate) override; + double pitch() const override; + bool setPitch(double pitch) override; + QLocale locale() const override; + bool setLocale(const QLocale &locale) override; + double volume() const override; + bool setVolume(double volume) override; + QVoice voice() const override; + bool setVoice(const QVoice &voice) override; + QTextToSpeech::State state() const override; + + void setState(QTextToSpeech::State state); + +private: + QJNIObjectPrivate m_speech; + QTextToSpeech::State m_state; + QString m_text; + +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/tts/android/src/qtexttospeech_android_plugin.cpp b/src/plugins/tts/android/src/qtexttospeech_android_plugin.cpp new file mode 100644 index 0000000..f3bea94 --- /dev/null +++ b/src/plugins/tts/android/src/qtexttospeech_android_plugin.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Speech module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtexttospeech_android_plugin.h" +#include "qtexttospeech_android.h" + +QT_BEGIN_NAMESPACE + +Q_LOGGING_CATEGORY(lcSpeechTtsAndroid, "qt.speech.tts.android") + +QTextToSpeechEngine *QTextToSpeechPluginAndroid::createTextToSpeechEngine( + const QVariantMap ¶meters, QObject *parent, QString *errorString) const +{ + Q_UNUSED(errorString) + QTextToSpeechEngineAndroid *android = new QTextToSpeechEngineAndroid(parameters, parent); + if (android) { + return android; + } + delete android; + return 0; +} + +QT_END_NAMESPACE diff --git a/src/plugins/tts/android/src/qtexttospeech_android_plugin.h b/src/plugins/tts/android/src/qtexttospeech_android_plugin.h new file mode 100644 index 0000000..2176b18 --- /dev/null +++ b/src/plugins/tts/android/src/qtexttospeech_android_plugin.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Speech module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTEXTTOSPEECHPLUGIN_ANDROID_H +#define QTEXTTOSPEECHPLUGIN_ANDROID_H + +#include "qtexttospeechplugin.h" +#include "qtexttospeechengine.h" + +#include <QtCore/QObject> +#include <QtCore/QLoggingCategory> + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(lcSpeechTtsAndroid) + +class QTextToSpeechPluginAndroid : public QObject, public QTextToSpeechPlugin +{ + Q_OBJECT + Q_INTERFACES(QTextToSpeechPlugin) + Q_PLUGIN_METADATA(IID "org.qt-project.qt.speech.tts.plugin/5.0" + FILE "android_plugin.json") + +public: + QTextToSpeechEngine *createTextToSpeechEngine( + const QVariantMap ¶meters, + QObject *parent, + QString *errorString) const; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/tts/android/src/src.pro b/src/plugins/tts/android/src/src.pro new file mode 100644 index 0000000..70f6a40 --- /dev/null +++ b/src/plugins/tts/android/src/src.pro @@ -0,0 +1,17 @@ +TARGET = qttexttospeech_android +QT = core core-private texttospeech + +PLUGIN_TYPE = texttospeech +PLUGIN_CLASS_NAME = QTextToSpeechEngineAndroid +load(qt_plugin) + +HEADERS += \ + qtexttospeech_android.h \ + qtexttospeech_android_plugin.h + +SOURCES += \ + qtexttospeech_android.cpp \ + qtexttospeech_android_plugin.cpp + +OTHER_FILES += \ + android_plugin.json diff --git a/src/plugins/tts/tts.pro b/src/plugins/tts/tts.pro index 9e463ef..0d56920 100644 --- a/src/plugins/tts/tts.pro +++ b/src/plugins/tts/tts.pro @@ -14,6 +14,8 @@ winrt: SUBDIRS += winrt osx: SUBDIRS += osx +android: SUBDIRS += android + config_flite | config_flite_alsa { SUBDIRS += flite } diff --git a/src/src.pro b/src/src.pro index 9699454..f79ef8e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -4,6 +4,5 @@ QMAKE_DOCS = $$PWD/doc/qtspeech.qdocconf load(qt_docs) SUBDIRS = tts plugins -android:SUBDIRS += tts/android plugins.depends = tts diff --git a/src/tts/tts.pro b/src/tts/tts.pro index 6beb4d9..04d67f8 100644 --- a/src/tts/tts.pro +++ b/src/tts/tts.pro @@ -20,3 +20,10 @@ SOURCES = \ qtexttospeechplugin.cpp \ qtexttospeechengine.cpp \ qvoice.cpp \ + +ANDROID_BUNDLED_JAR_DEPENDENCIES = \ + jar/QtTextToSpeech-bundled.jar +ANDROID_JAR_DEPENDENCIES = \ + jar/QtTextToSpeech.jar +ANDROID_LIB_DEPENDENCIES = \ + plugins/texttospeech/libqttexttospeech_android.so |