Skip to content

Commit

Permalink
Merge pull request #561 from dlutton/web-set-language-fix
Browse files Browse the repository at this point in the history
Web set language fix
  • Loading branch information
dlutton authored Jan 29, 2025
2 parents 48eba56 + d93684a commit b9a8236
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## 4.2.2

### Fixes

- **Web:** Fixing setLanguage on iOS browsers

## 4.2.1

### Fixes
Expand Down
11 changes: 10 additions & 1 deletion lib/flutter_tts_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,16 @@ class FlutterTtsPlugin {
void _setRate(double rate) => utterance.rate = rate;
void _setVolume(double volume) => utterance.volume = volume;
void _setPitch(double pitch) => utterance.pitch = pitch;
void _setLanguage(String language) => utterance.lang = language;
void _setLanguage(String language) {
var targetList = synth.getVoices().toDart.where((e) {
return e.lang.toLowerCase().startsWith(language.toLowerCase());
});
if (targetList.isNotEmpty) {
utterance.voice = targetList.first;
utterance.lang = targetList.first.lang;
}
}

void _setVoice(Map<String?, String?> voice) {
var tmpVoices = synth.getVoices().toDart;
var targetList = tmpVoices.where((e) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_tts
description: A flutter plugin for Text to Speech. This plugin is supported on iOS, macOS, Android, Web, & Windows.
version: 4.2.1
version: 4.2.2
homepage: https://github.com/dlutton/flutter_tts

dependencies:
Expand Down

0 comments on commit b9a8236

Please sign in to comment.