diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-03-05 16:51:37 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-05 16:43:47 +0000 |
commit | 5f250355c4d2ae112452cce3cbacc5833e523de3 (patch) | |
tree | 9d20697bd65382be01bc235b62b56e1f02b7cbdd | |
parent | bcb935d12dee170de2baa999fa02b5a624752f23 (diff) |
Enqueue new text if added while the engine is busy
Calling enqueue() should be equivalent to say() when the engine
is Ready, otherwise it should enqueue the text. The old
implementation only enqueued the text when the engine was
in Speaking state, overriding the current utterance when the
engine was already synthesizing, or paused.
Adjust test to enqueue the next text chunk as soon as the
engine transitions away from the Ready state.
Pick-to: 6.6
Fixes: QTBUG-122884
Change-Id: I19518a92d1ae73b01dc3de1d9ae6178f5f55b3ad
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 037fcecfaa40645994038f28f5d8ca98b80d6afd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/tts/qtexttospeech.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qtexttospeech/tst_qtexttospeech.cpp | 4 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/tts/qtexttospeech.cpp b/src/tts/qtexttospeech.cpp index c938771..8018a8f 100644 --- a/src/tts/qtexttospeech.cpp +++ b/src/tts/qtexttospeech.cpp @@ -826,11 +826,18 @@ qsizetype QTextToSpeech::enqueue(const QString &utterance) if (!d->m_engine || utterance.isEmpty()) return -1; - if (d->m_engine->state() == QTextToSpeech::Speaking) { - d->m_pendingUtterances.enqueue(utterance); - } else { + switch (d->m_engine->state()) { + case QTextToSpeech::Error: + return -1; + case QTextToSpeech::Ready: emit aboutToSynthesize(0); d->m_engine->say(utterance); + break; + case QTextToSpeech::Speaking: + case QTextToSpeech::Synthesizing: + case QTextToSpeech::Paused: + d->m_pendingUtterances.enqueue(utterance); + break; } return d->m_utteranceCounter++; diff --git a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp index b2b8fb8..ec31fef 100644 --- a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp +++ b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp @@ -696,8 +696,8 @@ void tst_QTextToSpeech::sayMultiple() for (qsizetype i = 0; i < textList.count(); ++i) { const QString &text = textList.at(i); tts.enqueue(text); - if (!i) // wait for the engine to start speaking - QTRY_COMPARE(tts.state(), QTextToSpeech::Speaking); + if (!i) // wait for the engine to start synthesizing + QTRY_COMPARE_NE(tts.state(), QTextToSpeech::Ready); } QTRY_VERIFY(doneSpeaking); |