getAudio method

  1. @override
Stream<Uint8List> getAudio({
  1. required String voice,
  2. required String input,
  3. bool highQuality = true,
  4. AudioFormat? format,
})
override

Implementation

@override
Stream<Uint8List> getAudio({
  required String voice,
  required String input,
  bool highQuality = true,
  AudioFormat? format,
}) async* {
  var path = 'https://api.openai.com/v1/audio/speech';
  var response = await httpClient.post(
    path,
    data: {
      'model': highQuality ? 'tts-1-hd' : 'tts-1',
      'input': input,
      'voice': voice,
      if (format != null) 'response_format': format.name,
    },
    options: Options(
      responseType: ResponseType.stream,
    ),
  );
  var data = response.data;
  Stream<Uint8List> stream = data.stream;
  yield* stream;
}