mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +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 ) {
|
if ( gdcl.notts ) {
|
||||||
cfg.notts = true;
|
cfg.notts = true;
|
||||||
|
cfg.voiceEngines.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.resetState = gdcl.resetState;
|
cfg.resetState = gdcl.resetState;
|
||||||
|
|
|
@ -49,7 +49,7 @@ SpeechClient::Engines SpeechClient::availableEngines()
|
||||||
|
|
||||||
bool SpeechClient::tell( QString const & text, int volume, int rate ) const
|
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;
|
return false;
|
||||||
|
|
||||||
internalData->sp->setVolume( volume / 100.0 );
|
internalData->sp->setVolume( volume / 100.0 );
|
||||||
|
|
|
@ -40,10 +40,18 @@ public:
|
||||||
sp( std::make_unique< QTextToSpeech >( e.engine_name ) ),
|
sp( std::make_unique< QTextToSpeech >( e.engine_name ) ),
|
||||||
engine( e )
|
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 );
|
sp->setLocale( e.locale );
|
||||||
auto voices = sp->availableVoices();
|
auto voices = sp->availableVoices();
|
||||||
for( const auto & voice : voices ) {
|
for ( const auto & voice : voices ) {
|
||||||
if( voice.name() == e.voice_name ) {
|
if ( voice.name() == e.voice_name ) {
|
||||||
sp->setVoice( voice );
|
sp->setVoice( voice );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue