diff options
-rw-r--r-- | examples/speech/quickspeech/main.qml | 2 | ||||
-rw-r--r-- | src/plugins/tts/android/src/qtexttospeech_android.cpp | 3 | ||||
-rw-r--r-- | src/plugins/tts/darwin/qtexttospeech_darwin.mm | 6 | ||||
-rw-r--r-- | src/plugins/tts/flite/qtexttospeech_flite_processor.cpp | 2 | ||||
-rw-r--r-- | src/plugins/tts/flite/qtexttospeech_flite_processor.h | 2 | ||||
-rw-r--r-- | src/plugins/tts/macos/qtexttospeech_macos.mm | 6 | ||||
-rw-r--r-- | src/plugins/tts/mock/qtexttospeech_mock.cpp | 2 | ||||
-rw-r--r-- | src/plugins/tts/sapi/qtexttospeech_sapi.cpp | 3 | ||||
-rw-r--r-- | src/plugins/tts/winrt/qtexttospeech_winrt.cpp | 3 | ||||
-rw-r--r-- | src/tts/qtexttospeech.cpp | 16 | ||||
-rw-r--r-- | src/tts/qtexttospeech.h | 2 | ||||
-rw-r--r-- | src/tts/qtexttospeechengine.h | 2 | ||||
-rw-r--r-- | tests/auto/qtexttospeech/tst_qtexttospeech.cpp | 21 |
13 files changed, 45 insertions, 25 deletions
diff --git a/examples/speech/quickspeech/main.qml b/examples/speech/quickspeech/main.qml index 7bdcaf7..169a33c 100644 --- a/examples/speech/quickspeech/main.qml +++ b/examples/speech/quickspeech/main.qml @@ -41,7 +41,7 @@ ApplicationWindow { //! [stateChanged] //! [sayingWord] - onSayingWord: (start, length)=> { + onSayingWord: (word, id, start, length)=> { input.select(start, start + length) } //! [sayingWord] diff --git a/src/plugins/tts/android/src/qtexttospeech_android.cpp b/src/plugins/tts/android/src/qtexttospeech_android.cpp index ab18786..0cdfac6 100644 --- a/src/plugins/tts/android/src/qtexttospeech_android.cpp +++ b/src/plugins/tts/android/src/qtexttospeech_android.cpp @@ -309,7 +309,8 @@ void QTextToSpeechEngineAndroid::processNotifySpeaking() void QTextToSpeechEngineAndroid::processNotifyRangeStart(int start, int end, int frame) { Q_UNUSED(frame); - emit sayingWord(start, end - start); + const int length = end - start; + emit sayingWord(m_text.sliced(start, length), start,length); } void QTextToSpeechEngineAndroid::stop(QTextToSpeech::BoundaryHint boundaryHint) diff --git a/src/plugins/tts/darwin/qtexttospeech_darwin.mm b/src/plugins/tts/darwin/qtexttospeech_darwin.mm index a62fd89..7161cf3 100644 --- a/src/plugins/tts/darwin/qtexttospeech_darwin.mm +++ b/src/plugins/tts/darwin/qtexttospeech_darwin.mm @@ -84,8 +84,10 @@ auto length = characterRange.length; if (length && text.at(characterRange.location + length - 1).isPunct()) --length; - if (length) - _engine->sayingWord(characterRange.location, length); + if (length) { + _engine->sayingWord(text.sliced(characterRange.location, length), + characterRange.location, length); + } } @end diff --git a/src/plugins/tts/flite/qtexttospeech_flite_processor.cpp b/src/plugins/tts/flite/qtexttospeech_flite_processor.cpp index 3c0d974..366331b 100644 --- a/src/plugins/tts/flite/qtexttospeech_flite_processor.cpp +++ b/src/plugins/tts/flite/qtexttospeech_flite_processor.cpp @@ -152,7 +152,7 @@ void QTextToSpeechProcessorFlite::timerEvent(QTimerEvent *event) qCDebug(lcSpeechTtsFlite) << "Moving current token" << m_currentToken << m_tokens.size(); auto currentToken = m_tokens.at(m_currentToken); m_index = m_text.indexOf(currentToken.text, m_index); - emit sayingWord(m_index, currentToken.text.length()); + emit sayingWord(currentToken.text, m_index, currentToken.text.length()); m_index += currentToken.text.length(); ++m_currentToken; if (m_currentToken == m_tokens.size()) diff --git a/src/plugins/tts/flite/qtexttospeech_flite_processor.h b/src/plugins/tts/flite/qtexttospeech_flite_processor.h index 0da6987..9a1a797 100644 --- a/src/plugins/tts/flite/qtexttospeech_flite_processor.h +++ b/src/plugins/tts/flite/qtexttospeech_flite_processor.h @@ -87,7 +87,7 @@ private slots: Q_SIGNALS: void errorOccurred(QTextToSpeech::ErrorReason error, const QString &errorString); void stateChanged(QTextToSpeech::State); - void sayingWord(qsizetype begin, qsizetype length); + void sayingWord(const QString &word, qsizetype begin, qsizetype length); void synthesized(const QAudioFormat &format, const QByteArray &array); protected: diff --git a/src/plugins/tts/macos/qtexttospeech_macos.mm b/src/plugins/tts/macos/qtexttospeech_macos.mm index d305823..db16065 100644 --- a/src/plugins/tts/macos/qtexttospeech_macos.mm +++ b/src/plugins/tts/macos/qtexttospeech_macos.mm @@ -38,8 +38,10 @@ using namespace Qt::StringLiterals; auto length = characterRange.length; if (text.at(characterRange.location + length - 1).isPunct()) --length; - if (length) - emit speechPrivate->sayingWord(characterRange.location, length); + if (length) { + emit speechPrivate->sayingWord(text.sliced(characterRange.location, length), + characterRange.location, length); + } speechPrivate->speaking(); } diff --git a/src/plugins/tts/mock/qtexttospeech_mock.cpp b/src/plugins/tts/mock/qtexttospeech_mock.cpp index 2aad44c..a5b0e7e 100644 --- a/src/plugins/tts/mock/qtexttospeech_mock.cpp +++ b/src/plugins/tts/mock/qtexttospeech_mock.cpp @@ -180,7 +180,7 @@ void QTextToSpeechEngineMock::timerEvent(QTimerEvent *e) if (nextSpace == -1) nextSpace = m_text.length(); const QString word = m_text.sliced(m_currentIndex, nextSpace - m_currentIndex); - sayingWord(m_currentIndex, nextSpace - m_currentIndex); + sayingWord(word, m_currentIndex, nextSpace - m_currentIndex); m_currentIndex = nextSpace + match.captured().length(); emit synthesized(m_format, QByteArray(m_format.bytesForDuration(wordTime() * 1000), 0)); diff --git a/src/plugins/tts/sapi/qtexttospeech_sapi.cpp b/src/plugins/tts/sapi/qtexttospeech_sapi.cpp index 26e38dc..2649875 100644 --- a/src/plugins/tts/sapi/qtexttospeech_sapi.cpp +++ b/src/plugins/tts/sapi/qtexttospeech_sapi.cpp @@ -549,7 +549,8 @@ HRESULT QTextToSpeechEngineSapi::NotifyCallback(WPARAM /*wParam*/, LPARAM /*lPar m_state = QTextToSpeech::Ready; break; case SPEI_WORD_BOUNDARY: - emit sayingWord(event.lParam - textOffset, event.wParam); + emit sayingWord(currentText.sliced(event.lParam - textOffset, event.wParam), + event.lParam - textOffset, event.wParam); break; // these are the other TTS events which might be interesting for us at some point case SPEI_SENTENCE_BOUNDARY: diff --git a/src/plugins/tts/winrt/qtexttospeech_winrt.cpp b/src/plugins/tts/winrt/qtexttospeech_winrt.cpp index fdbaad0..4acf1f2 100644 --- a/src/plugins/tts/winrt/qtexttospeech_winrt.cpp +++ b/src/plugins/tts/winrt/qtexttospeech_winrt.cpp @@ -344,7 +344,8 @@ void QTextToSpeechEngineWinRT::timerEvent(QTimerEvent *e) const qint64 expected = d->currentBoundary->startTime; const qint64 elapsed = d->elapsedTimer.nsecsElapsed() / 1000 + d->playedTime; if (d->currentBoundary->type == AudioSource::Boundary::Word) - emit sayingWord(d->currentBoundary->beginIndex, d->currentBoundary->endIndex - d->currentBoundary->beginIndex + 1); + emit sayingWord(d->currentBoundary->text, d->currentBoundary->beginIndex, + d->currentBoundary->endIndex - d->currentBoundary->beginIndex + 1); ++d->currentBoundary; const qint64 msecsToNext = qMax((d->currentBoundary->startTime - elapsed) / 1000, 0); if (d->audioSource && d->currentBoundary != d->boundaries.constEnd()) { diff --git a/src/tts/qtexttospeech.cpp b/src/tts/qtexttospeech.cpp index b7fa8a2..9121a8b 100644 --- a/src/tts/qtexttospeech.cpp +++ b/src/tts/qtexttospeech.cpp @@ -79,7 +79,9 @@ void QTextToSpeechPrivate::setEngineProvider(const QString &engine, const QVaria QObject::connect(m_engine.get(), &QTextToSpeechEngine::errorOccurred, q, &QTextToSpeech::errorOccurred); QObject::connect(m_engine.get(), &QTextToSpeechEngine::sayingWord, - q, &QTextToSpeech::sayingWord); + q, [this, q](const QString &word, qsizetype start, qsizetype length){ + emit q->sayingWord(word, m_currentUtterance, start, length); + }); QObject::connect(m_engine.get(), &QTextToSpeechEngine::synthesized, q, &QTextToSpeech::synthesized); } else { @@ -640,11 +642,11 @@ QTextToSpeech::State QTextToSpeech::state() const */ /*! - \qmlsignal TextToSpeech::sayingWord(int start, int length) + \qmlsignal TextToSpeech::sayingWord(string word, int id, int start, int length) \since 6.6 - This signal is emitted when the word indicated by \a start and \a length - in the currently spoken text gets played to the audio device. + This signal is emitted when the \a word, which is the slice of text indicated + by \a start and \a length in the utterance \a id, gets played to the audio device. \note This signal requires that the engine has the \l {QTextToSpeech::Capability::}{WordByWordProgress} capability. @@ -656,11 +658,11 @@ QTextToSpeech::State QTextToSpeech::state() const */ /*! - \fn void QTextToSpeech::sayingWord(qsizetype start, qsizetype length) + \fn void QTextToSpeech::sayingWord(const QString &word, qsizetype id, qsizetype start, qsizetype length) \since 6.6 - This signal is emitted when the word indicated by \a start and \a length - in the currently spoken text gets played to the audio device. + This signal is emitted when the \a word, which is the slice of text indicated + by \a start and \a length in the utterance \a id, gets played to the audio device. \note This signal requires that the engine has the \l {QTextToSpeech::Capability::}{WordByWordProgress} capability. diff --git a/src/tts/qtexttospeech.h b/src/tts/qtexttospeech.h index c33403b..fb586b5 100644 --- a/src/tts/qtexttospeech.h +++ b/src/tts/qtexttospeech.h @@ -158,7 +158,7 @@ Q_SIGNALS: void volumeChanged(double volume); void voiceChanged(const QVoice &voice); - void sayingWord(qsizetype start, qsizetype length); + void sayingWord(const QString &word, qsizetype id, qsizetype start, qsizetype length); void synthesized(const QAudioFormat &format, const QByteArray &data); void aboutToSynthesize(qsizetype id); diff --git a/src/tts/qtexttospeechengine.h b/src/tts/qtexttospeechengine.h index f2b9ecd..fe02ff9 100644 --- a/src/tts/qtexttospeechengine.h +++ b/src/tts/qtexttospeechengine.h @@ -59,7 +59,7 @@ Q_SIGNALS: void stateChanged(QTextToSpeech::State state); void errorOccurred(QTextToSpeech::ErrorReason error, const QString &errorString); - void sayingWord(qsizetype start, qsizetype length); + void sayingWord(const QString &word, qsizetype start, qsizetype length); void synthesized(const QAudioFormat &format, const QByteArray &data); }; diff --git a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp index 9c9dac4..1ab869c 100644 --- a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp +++ b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp @@ -730,13 +730,17 @@ void tst_QTextToSpeech::pauseAtUtterance() } }); QStringList wordsSpoken; - connect(&tts, &QTextToSpeech::sayingWord, [&](int at, int length){ - wordsSpoken += textList.at(atIndex).mid(at, length); + connect(&tts, &QTextToSpeech::sayingWord, + [&](const QString &word, qsizetype id, qsizetype at, qsizetype length){ + const QString text = textList.at(atIndex).mid(at, length); + QCOMPARE(id, atIndex); + QCOMPARE(text, word); + wordsSpoken += text; }); for (qsizetype i = 0; i < textList.count(); ++i) { const QString &text = textList.at(i); - tts.enqueue(text); + QCOMPARE(tts.enqueue(text), i); if (!i) QTRY_COMPARE(tts.state(), QTextToSpeech::Speaking); } @@ -784,7 +788,11 @@ void tst_QTextToSpeech::sayingWord() QElapsedTimer timer; QStringList words; QList<qint64> times; - connect(&tts, &QTextToSpeech::sayingWord, [&words, ×, &timer, text](qsizetype start, qsizetype length) { + connect(&tts, &QTextToSpeech::sayingWord, + [&words, ×, &timer, text](const QString &word, qsizetype id, qsizetype start, qsizetype length) { + const QString &slice = text.sliced(start, length); + QCOMPARE(word, slice); + QCOMPARE(id, 0); words << text.sliced(start, length); times << timer.elapsed(); }); @@ -843,7 +851,10 @@ void tst_QTextToSpeech::sayingWordWithPause() selectWorkingVoice(&tts); QStringList spokenWords; - connect(&tts, &QTextToSpeech::sayingWord, [&](qsizetype start, qsizetype length) { + connect(&tts, &QTextToSpeech::sayingWord, + [&](const QString &word, qsizetype id, qsizetype start, qsizetype length) { + QCOMPARE(word, text.sliced(start, length)); + QCOMPARE(id, 0); spokenWords << text.sliced(start, length); if (spokenWords.size() == pauseAt) tts.pause(QTextToSpeech::BoundaryHint::Word); |