textToSpeech method

Future<File> textToSpeech (
  1. {@required String text,
  2. String voiceName: 'de-DE-Wavenet-D',
  3. String audioEncoding: 'MP3',
  4. String languageCode: 'de-DE'}
)

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);
    AudioResponse audioResponse = AudioResponse.fromJson(response);
    return _createMp3File(audioResponse);
  } catch (e) {
    throw (e);
  }
}