Skip to content

Commit

Permalink
Correct unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
seungsoo47 committed Nov 26, 2024
1 parent e3dcd24 commit eb5cb55
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 54 deletions.
25 changes: 11 additions & 14 deletions packages/flutter_tts/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,17 @@ class _MyAppState extends State<MyApp> {
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(
Expand Down
8 changes: 2 additions & 6 deletions packages/flutter_tts/tizen/src/flutter_tts_tizen_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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, flutter::EncodableValue>(
flutter::EncodableValue("name"),
Expand Down
56 changes: 22 additions & 34 deletions packages/flutter_tts/tizen/src/text_to_speech.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextToSpeech *>(user_data);
self->supported_lanaguages_.push_back(language);

std::map<std::string, std::string> 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<TextToSpeech *>(user_data);
self->supported_lanaguages_.push_back(language);

std::map<std::string, std::string> 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<std::pair<std::string, std::string>>
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit eb5cb55

Please sign in to comment.