diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-22 11:57:25 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-25 16:51:53 +0200 |
commit | 48a9a6a394d15f30074c2d257422bca15018814b (patch) | |
tree | 2344c04381e8f2c5fa2b4ad4f173545ca5fd4284 /tests/auto | |
parent | 5ed54428c7315cc9f1378538099dc1cd9287baee (diff) |
TextToSpeech: delay engine creation, make order-agnostic
With QML, the engine property will always be set after the QTextToSpeech
object was created with the default engine. That QTextToSpeech's
default constructure (with the engine left empty) creates the default
engine implicitly is wasteful if it later gets replaced.
And what's worse, the engine was the only place where property values
are stored, and overriding the engine would not maintain those values.
This makes TextToSpeech susceptible to the order in which declared
properties are set, which breaks declarative programming.
Use the special engine name "none" to delay the creation of the engine
in the default constructor, and override the "engine" property to
intercept calls to getter and setter. Set the engine then in the
override of componentComplete.
And store set values for pitch, rate, and volume in the QTextToSpeech
object directly so that we can initialize the engine with those values,
no matter the order in which properties are set. This also allows us to
maintain the values from the old engine when changing engine.
We cannot do that for locale and voice, as those are engine-dependent.
However, it's not possible to set a voice directly anyway without
getting it from the engine first anyway, and the voice selector is only
executed at the end of componentComplete.
Add test to verify that all relevant properties have the right values,
even when setting or changing the engine later.
Change-Id: Ib162f87c1f9ceaad1fe8674c149290ac9141fccc
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qtexttospeech_qml/tst_texttospeech.qml | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/auto/qtexttospeech_qml/tst_texttospeech.qml b/tests/auto/qtexttospeech_qml/tst_texttospeech.qml index 8caed32..7782694 100644 --- a/tests/auto/qtexttospeech_qml/tst_texttospeech.qml +++ b/tests/auto/qtexttospeech_qml/tst_texttospeech.qml @@ -15,11 +15,34 @@ TestCase { engine: "mock" } - // verifies that the mock engine is synchronous + // verifies that the mock engine is synchronous by default function initTestCase() { compare(tts.state, TextToSpeech.Ready) } + Component { + id: defaultEngine + TextToSpeech { + rate: 0.5 + volume: 0.8 + pitch: 0.1 + } + } + + function test_defaultEngine() { + let def = createTemporaryObject(defaultEngine, testCase) + if (!def.engine) + skip("No default engine available on this platform") + else if (def.engine == "speechd") + skip("Older libspeechd versions don't implement attribute getters") + else + console.log("The default tts engine is " + def.engine) + + compare(def.rate, 0.5) + compare(def.volume, 0.8) + compare(def.pitch, 0.1) + } + function test_availableLocales() { compare(tts.availableLocales().length, 5) } @@ -52,6 +75,37 @@ TestCase { } Component { + id: lateEngine + TextToSpeech { + rate: 0.5 + volume: 0.8 + pitch: 0.1 + engine: "mock" + } + } + + function test_lateEngine() { + let tts = createTemporaryObject(lateEngine, testCase) + tryCompare(tts, "state", TextToSpeech.Ready) + + compare(tts.rate, 0.5) + compare(tts.volume, 0.8) + compare(tts.pitch, 0.1) + compare(tts.engine, "mock") + + tts.engine = "" + // If there is no default engine, then we use mock + if (!tts.engine) + tts.engine = "mock"; + else if (tts.engine == "speechd") + skip("Older libspeechd versions don't implement attribute getters") + + compare(tts.rate, 0.5) + compare(tts.volume, 0.8) + compare(tts.pitch, 0.1) + } + + Component { id: name_selector TextToSpeech { engine: "mock" |