fix: tts null check

This commit is contained in:
YiFang Xiao 2023-06-23 09:26:06 +08:00
parent f909413caa
commit 4d452e7a63
3 changed files with 12 additions and 3 deletions

View file

@ -455,6 +455,7 @@ int main( int argc, char ** argv )
if ( gdcl.notts ) {
cfg.notts = true;
cfg.voiceEngines.clear();
}
cfg.resetState = gdcl.resetState;

View file

@ -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 );

View file

@ -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;