diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2023-08-22 16:13:34 +0300 |
---|---|---|
committer | Axel Spoerl <axel.spoerl@qt.io> | 2023-08-23 08:53:32 +0000 |
commit | 334f29f37398ffed3619dabd535bdf87248db609 (patch) | |
tree | 181f620ac1d41ee0bd905ff85184917b45f24899 /src | |
parent | 4e2352951d8396d37d547817748ae8eb398efb60 (diff) |
winrt: Fix crash if initialization fails
Add early returns, if no OneCore voices installed.
Pick-to: 6.6 6.5
Change-Id: I9e95b06b35a212e9471c192415e406d1e8c3e461
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/tts/winrt/qtexttospeech_winrt.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/plugins/tts/winrt/qtexttospeech_winrt.cpp b/src/plugins/tts/winrt/qtexttospeech_winrt.cpp index 4acf1f2..ee1f3dd 100644 --- a/src/plugins/tts/winrt/qtexttospeech_winrt.cpp +++ b/src/plugins/tts/winrt/qtexttospeech_winrt.cpp @@ -124,6 +124,7 @@ QTextToSpeechEngineWinRT::QTextToSpeechEngineWinRT(const QVariantMap ¶ms, QO if (!SUCCEEDED(hr)) { d->setError(QTextToSpeech::ErrorReason::Initialization, QCoreApplication::translate("QTextToSpeech", "Could not initialize text-to-speech engine.")); + return; } else if (voice() == QVoice()) { d->setError(QTextToSpeech::ErrorReason::Configuration, QCoreApplication::translate("QTextToSpeech", "Could not set default voice.")); @@ -232,6 +233,8 @@ void QTextToSpeechEngineWinRTPrivate::forEachVoice(Fn &&lambda) const QList<QLocale> QTextToSpeechEngineWinRT::availableLocales() const { Q_D(const QTextToSpeechEngineWinRT); + if (!d->synth) + return QList<QLocale>(); QSet<QLocale> uniqueLocales; d->forEachVoice([&uniqueLocales](const ComPtr<IVoiceInformation> &voiceInfo) { HString voiceLanguage; @@ -247,6 +250,8 @@ QList<QLocale> QTextToSpeechEngineWinRT::availableLocales() const QList<QVoice> QTextToSpeechEngineWinRT::availableVoices() const { Q_D(const QTextToSpeechEngineWinRT); + if (!d->synth) + return QList<QVoice>(); QList<QVoice> voices; const QLocale currentLocale = locale(); d->forEachVoice([&](const ComPtr<IVoiceInformation> &voiceInfo) { @@ -261,6 +266,8 @@ QList<QVoice> QTextToSpeechEngineWinRT::availableVoices() const QLocale QTextToSpeechEngineWinRT::locale() const { Q_D(const QTextToSpeechEngineWinRT); + if (!d->synth) + return QLocale(QLocale::C, QLocale::AnyTerritory); ComPtr<IVoiceInformation> voiceInfo; HRESULT hr = d->synth->get_Voice(&voiceInfo); @@ -274,6 +281,8 @@ QLocale QTextToSpeechEngineWinRT::locale() const bool QTextToSpeechEngineWinRT::setLocale(const QLocale &locale) { Q_D(QTextToSpeechEngineWinRT); + if (!d->synth) + return false; ComPtr<IVoiceInformation> foundVoice; d->forEachVoice([&locale, &foundVoice](const ComPtr<IVoiceInformation> &voiceInfo) { @@ -301,6 +310,8 @@ bool QTextToSpeechEngineWinRT::setLocale(const QLocale &locale) QVoice QTextToSpeechEngineWinRT::voice() const { Q_D(const QTextToSpeechEngineWinRT); + if (!d->synth) + return QVoice(); ComPtr<IVoiceInformation> voiceInfo; d->synth->get_Voice(&voiceInfo); @@ -311,6 +322,8 @@ QVoice QTextToSpeechEngineWinRT::voice() const bool QTextToSpeechEngineWinRT::setVoice(const QVoice &voice) { Q_D(QTextToSpeechEngineWinRT); + if (!d->synth) + return false; const QString data = QTextToSpeechEngine::voiceData(voice).toString(); if (data.isEmpty()) @@ -439,6 +452,8 @@ void QTextToSpeechEngineWinRTPrivate::sinkStateChanged(QAudio::State sinkState) void QTextToSpeechEngineWinRT::say(const QString &text) { Q_D(QTextToSpeechEngineWinRT); + if (!d->synth) + return; // stop ongoing speech stop(QTextToSpeech::BoundaryHint::Default); |