speak method

  1. @override
Future<void> speak(
  1. String text,
  2. VoiceConfig config
)
override

Implementation

@override
Future<void> speak(String text, VoiceConfig config) async {
  final audio = await synthesize(text, config);

  // Save to temp file and play.
  final tempFile = File(
    '${Directory.systemTemp.path}/neomage_speech_${DateTime.now().millisecondsSinceEpoch}.mp3',
  );
  await tempFile.writeAsBytes(audio);

  try {
    if (Platform.isMacOS) {
      _playProcess = await Process.start('afplay', [tempFile.path]);
    } else if (Platform.isLinux) {
      _playProcess = await Process.start('mpv', [
        '--no-video',
        tempFile.path,
      ]);
    }
    await _playProcess?.exitCode;
  } finally {
    if (await tempFile.exists()) await tempFile.delete();
    _playProcess = null;
  }
}