textToSpeech method
Implementation
Future<File> textToSpeech({
required String text,
String voiceName = 'de-DE-Wavenet-D',
String audioEncoding = 'MP3',
String languageCode = 'de-DE',
double pitch = 0.00,
double speakingRate = 1.00,
}) async {
const endpoint = 'text:synthesize';
final bodyMap = <String, dynamic>{
"input": {
"text": text,
},
"voice": {
"languageCode": languageCode,
"name": voiceName,
},
"audioConfig": {
"audioEncoding": audioEncoding,
"pitch": pitch,
"speakingRate": speakingRate,
},
};
String body = jsonEncode(bodyMap);
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);
}
}