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