mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
fix: tts null check
This commit is contained in:
parent
f909413caa
commit
4d452e7a63
|
@ -455,6 +455,7 @@ int main( int argc, char ** argv )
|
|||
|
||||
if ( gdcl.notts ) {
|
||||
cfg.notts = true;
|
||||
cfg.voiceEngines.clear();
|
||||
}
|
||||
|
||||
cfg.resetState = gdcl.resetState;
|
||||
|
|
|
@ -49,7 +49,7 @@ SpeechClient::Engines SpeechClient::availableEngines()
|
|||
|
||||
bool SpeechClient::tell( QString const & text, int volume, int rate ) const
|
||||
{
|
||||
if( internalData->sp->state() != QTextToSpeech::Ready )
|
||||
if ( !internalData || !internalData->sp || internalData->sp->state() != QTextToSpeech::Ready )
|
||||
return false;
|
||||
|
||||
internalData->sp->setVolume( volume / 100.0 );
|
||||
|
|
|
@ -40,10 +40,18 @@ public:
|
|||
sp( std::make_unique< QTextToSpeech >( e.engine_name ) ),
|
||||
engine( e )
|
||||
{
|
||||
qDebug() << "initialize tts" << e.engine_name;
|
||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
if ( !sp || sp->state() == QTextToSpeech::Error )
|
||||
return;
|
||||
#else
|
||||
if ( !sp || sp->state() == QTextToSpeech::BackendError )
|
||||
return;
|
||||
#endif
|
||||
sp->setLocale( e.locale );
|
||||
auto voices = sp->availableVoices();
|
||||
for( const auto & voice : voices ) {
|
||||
if( voice.name() == e.voice_name ) {
|
||||
for ( const auto & voice : voices ) {
|
||||
if ( voice.name() == e.voice_name ) {
|
||||
sp->setVoice( voice );
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue