anasfik / openai

Dart/Flutter SDK for ChatGPT and all OpenAI APIs (GPT, Dall-e..)
https://pub.dev/packages/dart_openai
MIT License
591 stars 184 forks source link

Example of getting bytes instead of saving directly to file for speech #177

Open dylandhall opened 5 months ago

dylandhall commented 5 months ago

This modifies the speech API to allow getting the bytes directly to play.

This will allow platforms like web which cannot write files to play the audio, and will allow other platforms to play the audio without adding file system permissions to write the temporary files.

tests as working with code:


    var audio = await OpenAI.instance.audio.createSpeechBytes(
        model: "tts-1",
        input: "message",
        voice: "fable",
        responseFormat: OpenAIAudioSpeechResponseFormat.mp3);

  var audioPlayer = AudioPlayer();

  await audioPlayer.play(BytesSource(audio, mimeType: 'audio/mpeg'));