initialize method

Future<void> initialize({
  1. String? modelPath,
})

Implementation

Future<void> initialize({String? modelPath}) async {
  _configuration = const TTSConfiguration();

  // Configure TTS engine
  await _flutterTts.setSharedInstance(true);

  // Get available voices
  final voices = await _flutterTts.getVoices;
  if (voices is List) {
    _availableVoicesList = voices
        .map((v) {
          if (v is Map) {
            final locale =
                v['locale']?.toString() ?? v['name']?.toString() ?? 'en-US';
            final name = v['name']?.toString() ?? 'System Voice';
            return TTSVoice(
              id: locale,
              name: name,
              language: locale,
            );
          }
          return null;
        })
        .whereType<TTSVoice>()
        .toList();
  }

  // Set up completion handlers
  _flutterTts.setCompletionHandler(() {
    _isSynthesizing = false;
  });

  _flutterTts.setErrorHandler((msg) {
    _isSynthesizing = false;
  });

  _flutterTts.setStartHandler(() {
    _isSynthesizing = true;
  });
}