synthesize method

  1. @override
Future<Uint8List> synthesize(
  1. String text,
  2. VoiceConfig config
)
override

Implementation

@override
Future<Uint8List> synthesize(String text, VoiceConfig config) async {
  if (Platform.isMacOS) {
    final tempFile = File(
      '${Directory.systemTemp.path}/neomage_tts_${DateTime.now().millisecondsSinceEpoch}.aiff',
    );

    await Process.run('say', [
      '-o', tempFile.path,
      '-r', '${(175 * config.speed).round()}', // Words per minute
      text,
    ]);

    if (await tempFile.exists()) {
      final data = await tempFile.readAsBytes();
      await tempFile.delete();
      return data;
    }
  }

  return Uint8List(0);
}