From eb5cb55070c5807b0edaa445999b1b78f4301c2d Mon Sep 17 00:00:00 2001 From: Seungsoo Lee Date: Tue, 26 Nov 2024 15:53:50 +0900 Subject: [PATCH] Correct unnecessary code --- packages/flutter_tts/example/lib/main.dart | 25 ++++----- .../tizen/src/flutter_tts_tizen_plugin.cc | 8 +-- .../flutter_tts/tizen/src/text_to_speech.cc | 56 ++++++++----------- 3 files changed, 35 insertions(+), 54 deletions(-) diff --git a/packages/flutter_tts/example/lib/main.dart b/packages/flutter_tts/example/lib/main.dart index 4b3d7377a..8f95f460d 100644 --- a/packages/flutter_tts/example/lib/main.dart +++ b/packages/flutter_tts/example/lib/main.dart @@ -194,20 +194,17 @@ class _MyAppState extends State { return Text('Loading Languages...'); }); - Widget _inputSection() { - _newVoiceText = 'Hello everyone. This is a flutter tts example app.'; - return Container( - alignment: Alignment.topCenter, - padding: EdgeInsets.only(top: 25.0, left: 25.0, right: 25.0), - child: TextField( - maxLines: 11, - minLines: 6, - onChanged: (String value) { - _onChange(value); - }, - controller: TextEditingController(text: _newVoiceText), - )); - } + Widget _inputSection() => Container( + alignment: Alignment.topCenter, + padding: EdgeInsets.only(top: 25.0, left: 25.0, right: 25.0), + child: TextField( + maxLines: 11, + minLines: 6, + onChanged: (String value) { + _onChange(value); + }, + controller: TextEditingController(text: _newVoiceText), + )); Widget _btnSection() { return Container( diff --git a/packages/flutter_tts/tizen/src/flutter_tts_tizen_plugin.cc b/packages/flutter_tts/tizen/src/flutter_tts_tizen_plugin.cc index fef82d697..44e2a4a28 100644 --- a/packages/flutter_tts/tizen/src/flutter_tts_tizen_plugin.cc +++ b/packages/flutter_tts/tizen/src/flutter_tts_tizen_plugin.cc @@ -216,10 +216,8 @@ class FlutterTtsTizenPlugin : public flutter::Plugin { } void OnGetLanguages() { - auto languages = tts_->GetSupportedLanaguages(); - flutter::EncodableList list; - for (auto language : languages) { + for (auto language : tts_->GetSupportedLanaguages()) { list.push_back(flutter::EncodableValue(language)); } SendResult(flutter::EncodableValue(list)); @@ -256,10 +254,8 @@ class FlutterTtsTizenPlugin : public flutter::Plugin { } void OnGetVoices() { - auto voices = tts_->GetSupportedVoiceTypes(); - flutter::EncodableList list; - for (auto voice : voices) { + for (auto voice : tts_->GetSupportedVoiceTypes()) { flutter::EncodableMap map; map.insert(std::pair( flutter::EncodableValue("name"), diff --git a/packages/flutter_tts/tizen/src/text_to_speech.cc b/packages/flutter_tts/tizen/src/text_to_speech.cc index 05aaf2fdd..ff70e2d9c 100644 --- a/packages/flutter_tts/tizen/src/text_to_speech.cc +++ b/packages/flutter_tts/tizen/src/text_to_speech.cc @@ -138,35 +138,26 @@ void TextToSpeech::UnregisterCallbacks() { } void TextToSpeech::InitializeSupportedLanaguagesAndVoiceType() { - if (supported_lanaguages_.size() == 0 || supported_voice_types_.size() == 0) { - tts_foreach_supported_voices( - tts_, - [](tts_h tts, const char *language, int32_t voice_type, - void *user_data) -> bool { - if (language == nullptr) { - return false; - } - TextToSpeech *self = static_cast(user_data); - self->supported_lanaguages_.push_back(language); - - std::map item; - item["name"] = GetVoiceName(voice_type); - item["locale"] = language; - self->supported_voice_types_.push_back(item); - - LOG_INFO("Supported language: %s, voice_type: %s", - item["locale"].c_str(), item["name"].c_str()); - return true; - }, - this); - - supported_lanaguages_.erase( - unique(supported_lanaguages_.begin(), supported_lanaguages_.end()), - supported_lanaguages_.end()); - supported_voice_types_.erase( - unique(supported_voice_types_.begin(), supported_voice_types_.end()), - supported_voice_types_.end()); - } + tts_foreach_supported_voices( + tts_, + [](tts_h tts, const char *language, int32_t voice_type, + void *user_data) -> bool { + if (language == nullptr) { + return false; + } + TextToSpeech *self = static_cast(user_data); + self->supported_lanaguages_.push_back(language); + + std::map item; + item["name"] = GetVoiceName(voice_type); + item["locale"] = language; + self->supported_voice_types_.push_back(item); + + LOG_INFO("Supported language: %s, voice_type: %s", + item["locale"].c_str(), item["name"].c_str()); + return true; + }, + this); } std::optional> @@ -274,11 +265,8 @@ bool TextToSpeech::GetSpeedRange(int32_t *min, int32_t *normal, int32_t *max) { } bool TextToSpeech::IsLanguageAvailable(const std::string &language) { - if (std::find(supported_lanaguages_.begin(), supported_lanaguages_.end(), - language) != supported_lanaguages_.end()) { - return true; - } - return false; + return std::find(supported_lanaguages_.begin(), supported_lanaguages_.end(), + language) != supported_lanaguages_.end(); } void TextToSpeech::SwitchVolumeOnStateChange(tts_state_e previous,