@@ -52,10 +52,6 @@ class FlutterTtsTizenPlugin : public flutter::Plugin {
5252 });
5353
5454 tts_ = std::make_unique<TextToSpeech>();
55- if (!tts_->Initialize ()) {
56- tts_ = nullptr ;
57- return ;
58- }
5955 tts_->SetStateChanagedCallback ([this ](TtsState previous, TtsState current) {
6056 std::unique_ptr<flutter::EncodableValue> value =
6157 std::make_unique<flutter::EncodableValue>(true );
@@ -83,6 +79,16 @@ class FlutterTtsTizenPlugin : public flutter::Plugin {
8379 channel_->InvokeMethod (" speak.onComplete" , std::move (args));
8480 HandleAwaitSpeakCompletion (flutter::EncodableValue (1 ));
8581 });
82+ tts_->SetErrorCallback ([this ](const std::string &message) {
83+ std::unique_ptr<flutter::EncodableValue> args =
84+ std::make_unique<flutter::EncodableValue>(message);
85+ channel_->InvokeMethod (" speak.onError" , std::move (args));
86+ HandleAwaitSpeakCompletion (flutter::EncodableValue (0 ));
87+ });
88+ if (!tts_->Initialize ()) {
89+ tts_ = nullptr ;
90+ return ;
91+ }
8692 }
8793
8894 virtual ~FlutterTtsTizenPlugin () {}
@@ -196,7 +202,10 @@ class FlutterTtsTizenPlugin : public flutter::Plugin {
196202 rate = std::min (rate, 1.0 );
197203 // Scale the value to be between the supported range.
198204 int32_t min = 0 , normal = 0 , max = 0 ;
199- tts_->GetSpeedRange (&min, &normal, &max);
205+ if (!tts_->GetSpeedRange (&min, &normal, &max) || max < min) {
206+ SendResult (flutter::EncodableValue (0 ));
207+ return ;
208+ }
200209 int32_t speed = min + (max - min) * rate;
201210 tts_->SetTtsSpeed (speed);
202211 SendResult (flutter::EncodableValue (1 ));
@@ -304,7 +313,7 @@ class FlutterTtsTizenPlugin : public flutter::Plugin {
304313 }
305314
306315 void HandleAwaitSpeakCompletion (const flutter::EncodableValue &result) {
307- if (await_speak_completion_) {
316+ if (await_speak_completion_ && result_for_await_speak_completion_ ) {
308317 result_for_await_speak_completion_->Success (result);
309318 result_for_await_speak_completion_ = nullptr ;
310319 }
0 commit comments