main
dart 17 lines 648 Bytes
Raw
1 import 'package:flutter_tts/flutter_tts.dart';
2
3 /// Keeps the app aligned with Android's chosen TTS engine. Each engine owns
4 /// its default voice/language; forcing en-US can disable third-party voices.
5 class SystemTtsConfiguration {
6 String? _engine;
7
8 Future<void> prepare(FlutterTts tts, {required bool isAndroid}) async {
9 if (!isAndroid) return;
10 final selected = await tts.getDefaultEngine;
11 if (selected is! String || selected.trim().isEmpty) return;
12 if (selected == _engine) return;
13 // setEngine completes after native initialization and reports failures.
14 await tts.setEngine(selected);
15 _engine = selected;
16 }
17 }