textToSpeech method
Implementation
Future<Uint8List> textToSpeech(String text, String language,String? voice) async {
final Map<String, dynamic> body = {
'language': language,
'text': text,
};
if (voice != null) {
body['voice'] = voice;
}
final response = await http.post(
Uri.parse(baseUrl),
headers: {'Content-Type': 'application/json'},
body: jsonEncode(body),
);
if (response.statusCode == 200) {
return response.bodyBytes; // This returns the audio data as bytes.
} else {
throw Exception('Failed to convert text to speech');
}
}