diff --git a/src/speechclient.cc b/src/speechclient.cc index db779d67..2d7b6888 100644 --- a/src/speechclient.cc +++ b/src/speechclient.cc @@ -1,9 +1,11 @@ #include "speechclient.hh" #include +#include +#include SpeechClient::SpeechClient( Config::VoiceEngine const & e, QObject * parent ): QObject( parent ), - internalData( std::make_unique< InternalData >( e ) ) + internalData( new InternalData( e ) ) { } @@ -14,28 +16,30 @@ SpeechClient::Engines SpeechClient::availableEngines() const auto innerEngines = QTextToSpeech::availableEngines(); for ( const auto & engine_name : innerEngines ) { - const auto sp = new QTextToSpeech( engine_name == "default" ? nullptr : engine_name ); + const auto sp = new QTextToSpeech( engine_name ); - #if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) +#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) if ( !sp || sp->state() == QTextToSpeech::Error ) continue; - #else - if ( !sp || sp->state() == QTextToSpeech::BackendError ) - continue; - #endif +#else + if ( !sp || sp->state() == QTextToSpeech::BackendError ) + continue; +#endif qDebug() << engine_name << sp->state(); - const QVector< QLocale > locales = sp->availableLocales(); - for ( const QLocale & locale : locales ) { + // const QVector< QLocale > locales = sp->availableLocales(); + // for ( const QLocale & locale : locales ) + { + QLocale locale; //on some platforms ,change the locale will change voices too. sp->setLocale( locale ); for ( const QVoice & voice : sp->availableVoices() ) { const QString name( QString( "%4 - %3 %1 (%2)" ) - .arg( QLocale::languageToString( locale.language() ), - ( QLocale::countryToString( locale.country() ) ), - voice.name(), - engine_name ) ); + .arg( QLocale::languageToString( locale.language() ), + ( QLocale::countryToString( locale.country() ) ), + voice.name(), + engine_name ) ); Engine engine( Config::VoiceEngine( engine_name, name, voice.name(), QLocale( locale ), 50, 0 ) ); engines.push_back( engine ); } diff --git a/src/speechclient.hh b/src/speechclient.hh index b72224fc..266dbeec 100644 --- a/src/speechclient.hh +++ b/src/speechclient.hh @@ -6,6 +6,7 @@ #include #include #include +#include class SpeechClient: public QObject { @@ -38,7 +39,7 @@ public: struct InternalData { explicit InternalData( Config::VoiceEngine const & e ): - sp( std::make_unique< QTextToSpeech >( e.engine_name ) ), + sp( new QTextToSpeech( e.engine_name ) ), engine( e ) { qDebug() << QStringLiteral( "initialize tts" ) << e.engine_name; @@ -63,7 +64,7 @@ public: sp->setRate( e.rate / 10.0 ); } - std::unique_ptr< QTextToSpeech > sp; + QSharedPointer< QTextToSpeech > sp; Engine engine; }; @@ -77,7 +78,7 @@ public: bool tell( QString const & text ) const; private: - std::unique_ptr< InternalData > internalData; + QSharedPointer< InternalData > internalData; }; #endif // __SPEECHCLIENT_HH_INCLUDED__