textToSpeech method
Implementation
Future<File> textToSpeech(
{required String text,
String voiceName = 'de-DE-Wavenet-D',
String audioEncoding = 'MP3',
String languageCode = 'de-DE'}) async {
const endpoint = 'text:synthesize';
String body =
'{"input": {"text":"$text"},"voice": {"languageCode": "$languageCode", "name": "$voiceName"},"audioConfig": {"audioEncoding": "$audioEncoding"}}';
Future request = http.post(_getApiUrl(endpoint), body: body);
try {
var response =
await _getResponse(request.then((value) => value as http.Response));
AudioResponse audioResponse = AudioResponse.fromJson(response);
return _createMp3File(audioResponse);
} catch (e) {
throw (e);
}
}