openai icon indicating copy to clipboard operation
openai copied to clipboard

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

Open dylandhall opened this issue 9 months ago • 0 comments

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'));

dylandhall avatar May 29 '24 08:05 dylandhall