Skip to content

android: getEngines now returns voice label #584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ class FlutterTtsPlugin : MethodCallHandler, FlutterPlugin {
}

private fun getEngines(result: Result) {
val engines = ArrayList<String>()
val engines = ArrayList<HashMap<String, String>>()
try {
for (engineInfo in tts!!.engines) {
engines.add(engineInfo.name)
engines.add(hashMapOf("name" to engineInfo.name, "label" to engineInfo.label))
}
} catch (e: Exception) {
Log.d(tag, "getEngines: " + e.message)
Expand Down
60 changes: 34 additions & 26 deletions lib/flutter_tts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

typedef ErrorHandler = void Function(dynamic message);
typedef ProgressHandler = void Function(
String text, int start, int end, String word);
typedef ProgressHandler =
void Function(String text, int start, int end, String word);

const String iosAudioCategoryOptionsKey = 'iosAudioCategoryOptionsKey';
const String iosAudioCategoryKey = 'iosAudioCategoryKey';
Expand Down Expand Up @@ -373,13 +373,15 @@ class FlutterTts {

/// [Future] which invokes the platform specific method for synthesizeToFile
/// ***Android and iOS supported only***
Future<dynamic> synthesizeToFile(String text, String fileName,
[bool isFullPath = false]) async =>
_channel.invokeMethod('synthesizeToFile', <String, dynamic>{
"text": text,
"fileName": fileName,
"isFullPath": isFullPath,
});
Future<dynamic> synthesizeToFile(
String text,
String fileName, [
bool isFullPath = false,
]) async => _channel.invokeMethod('synthesizeToFile', <String, dynamic>{
"text": text,
"fileName": fileName,
"isFullPath": isFullPath,
});

/// [Future] which invokes the platform specific method for setLanguage
Future<dynamic> setLanguage(String language) async =>
Expand Down Expand Up @@ -408,14 +410,15 @@ class FlutterTts {

/// [Future] which invokes the platform specific method for setting audio category
/// ***Ios supported only***
Future<dynamic> setIosAudioCategory(IosTextToSpeechAudioCategory category,
List<IosTextToSpeechAudioCategoryOptions> options,
[IosTextToSpeechAudioMode mode =
IosTextToSpeechAudioMode.defaultMode]) async {
Future<dynamic> setIosAudioCategory(
IosTextToSpeechAudioCategory category,
List<IosTextToSpeechAudioCategoryOptions> options, [
IosTextToSpeechAudioMode mode = IosTextToSpeechAudioMode.defaultMode,
]) async {
const categoryToString = <IosTextToSpeechAudioCategory, String>{
IosTextToSpeechAudioCategory.ambientSolo: iosAudioCategoryAmbientSolo,
IosTextToSpeechAudioCategory.ambient: iosAudioCategoryAmbient,
IosTextToSpeechAudioCategory.playback: iosAudioCategoryPlayback
IosTextToSpeechAudioCategory.playback: iosAudioCategoryPlayback,
};
const optionsToString = {
IosTextToSpeechAudioCategoryOptions.mixWithOthers:
Expand Down Expand Up @@ -448,14 +451,15 @@ class FlutterTts {
try {
return await _channel
.invokeMethod<dynamic>('setIosAudioCategory', <String, dynamic>{
iosAudioCategoryKey: categoryToString[category],
iosAudioCategoryOptionsKey:
options.map((o) => optionsToString[o]).toList(),
iosAudioModeKey: modeToString[mode],
});
iosAudioCategoryKey: categoryToString[category],
iosAudioCategoryOptionsKey:
options.map((o) => optionsToString[o]).toList(),
iosAudioModeKey: modeToString[mode],
});
} on PlatformException catch (e) {
print(
'setIosAudioCategory error, category: $category, mode: $mode, error: ${e.message}');
'setIosAudioCategory error, category: $category, mode: $mode, error: ${e.message}',
);
}
}

Expand Down Expand Up @@ -493,8 +497,10 @@ class FlutterTts {
/// [Future] which invokes the platform specific method for getEngines
/// Returns a list of installed TTS engines
/// ***Android supported only***
Future<dynamic> get getEngines async {
final engines = await _channel.invokeMethod('getEngines');
Future<List<Map<String, String>>> get getEngines async {
final List<dynamic> enginesRaw = await _channel.invokeMethod('getEngines');
final List<Map<String, String>> engines =
enginesRaw.map((e) => Map<String, String>.from(e as Map)).toList();
return engines;
}

Expand Down Expand Up @@ -541,14 +547,16 @@ class FlutterTts {
await _channel.invokeMethod('areLanguagesInstalled', languages);

Future<SpeechRateValidRange> get getSpeechRateValidRange async {
final validRange = await _channel.invokeMethod('getSpeechRateValidRange')
as Map<dynamic, dynamic>;
final validRange =
await _channel.invokeMethod('getSpeechRateValidRange')
as Map<dynamic, dynamic>;
final min = double.parse(validRange['min'].toString());
final normal = double.parse(validRange['normal'].toString());
final max = double.parse(validRange['max'].toString());
final platformStr = validRange['platform'].toString();
final platform =
TextToSpeechPlatform.values.firstWhere((e) => e.name == platformStr);
final platform = TextToSpeechPlatform.values.firstWhere(
(e) => e.name == platformStr,
);

return SpeechRateValidRange(min, normal, max, platform);
}
Expand Down