mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
fix:qtexttospeech crash when initialized
This commit is contained in:
parent
cfa393f0d9
commit
2f22aa1580
|
@ -1,7 +1,6 @@
|
|||
#include "speechclient.hh"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
SpeechClient::SpeechClient( Config::VoiceEngine const & e, QObject * parent ):
|
||||
QObject( parent ),
|
||||
internalData( std::make_unique< InternalData >( e ) )
|
||||
|
@ -14,28 +13,41 @@ SpeechClient::Engines SpeechClient::availableEngines()
|
|||
Engines engines;
|
||||
const auto innerEngines = QTextToSpeech::availableEngines();
|
||||
|
||||
for( const auto & engine_name : innerEngines ) {
|
||||
std::unique_ptr< QTextToSpeech > sp( std::make_unique< QTextToSpeech >( engine_name ) );
|
||||
for ( const auto & engine_name : innerEngines ) {
|
||||
const auto sp = new QTextToSpeech( engine_name == "default" ? nullptr : engine_name );
|
||||
|
||||
#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
|
||||
|
||||
qDebug() << engine_name << sp->state();
|
||||
|
||||
const QVector< QLocale > locales = sp->availableLocales();
|
||||
for( const QLocale & locale : locales ) {
|
||||
for ( const QLocale & locale : locales ) {
|
||||
//on some platforms ,change the locale will change voices too.
|
||||
sp->setLocale( locale );
|
||||
for( const QVoice & voice : sp->availableVoices() ) {
|
||||
QString name( QString( "%4 - %3 %1 (%2)" )
|
||||
.arg( QLocale::languageToString( locale.language() ),
|
||||
( QLocale::countryToString( locale.country() ) ),
|
||||
voice.name(),
|
||||
engine_name ) );
|
||||
SpeechClient::Engine engine( Config::VoiceEngine( engine_name, name, voice.name(), locale, 50, 0 ) );
|
||||
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 ) );
|
||||
Engine engine( Config::VoiceEngine( engine_name, name, voice.name(), QLocale( locale ), 50, 0 ) );
|
||||
engines.push_back( engine );
|
||||
}
|
||||
|
||||
sp->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
return engines;
|
||||
}
|
||||
|
||||
bool SpeechClient::tell( QString const & text, int volume, int rate )
|
||||
bool SpeechClient::tell( QString const & text, int volume, int rate ) const
|
||||
{
|
||||
if( internalData->sp->state() != QTextToSpeech::Ready )
|
||||
return false;
|
||||
|
@ -47,7 +59,7 @@ bool SpeechClient::tell( QString const & text, int volume, int rate )
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SpeechClient::tell( QString const & text )
|
||||
bool SpeechClient::tell( QString const & text ) const
|
||||
{
|
||||
return tell(text, internalData->engine.volume, internalData->engine.rate);
|
||||
}
|
||||
|
|
|
@ -64,8 +64,8 @@ public:
|
|||
|
||||
static Engines availableEngines();
|
||||
|
||||
bool tell( QString const & text, int volume, int rate );
|
||||
bool tell( QString const & text );
|
||||
bool tell( QString const & text, int volume, int rate ) const;
|
||||
bool tell( QString const & text ) const;
|
||||
|
||||
signals:
|
||||
void started( bool ok );
|
||||
|
|
Loading…
Reference in a new issue