openai icon indicating copy to clipboard operation
openai copied to clipboard

text to speech model returning mpeg file, not mp3

Open Lazizbek97 opened this issue 1 year ago • 3 comments

When we use text to speech model: model: "tts-1"; it is returning .mpeg file, and i cannot listen it on app. it should return mp3, so that i can listen it on app.

` // create speech from text Future<File> createSpeech(String prompt) async { final appDir = await getApplicationDocumentsDirectory(); // The speech request. File speechFile = await OpenAI.instance.audio.createSpeech( model: "tts-1", input: prompt, voice: "nova", responseFormat: OpenAIAudioSpeechResponseFormat.mp3, outputFileName: "speech", outputDirectory: appDir, );

return speechFile;

} `

Lazizbek97 avatar Jun 09 '24 07:06 Lazizbek97

Hey! I've been able to play the mpeg file using the just_audio library and it works fine! I also tried just changing the file name to .mp3 and it worked as well.

Padi142 avatar Jun 20 '24 16:06 Padi142

@Padi142 would you mind sharing the code, I've tried what you suggested but none of it works. Thank you

dustinpham235 avatar Jun 23 '24 06:06 dustinpham235

Of course! I used the path_provider package to get a writable directory in my android app.

    final File speechFile = await OpenAI.instance.audio.createSpeech(
      model: 'tts-1-hd',
      input: 'Why do mice like cheese?',
      voice: 'nova',
      responseFormat: OpenAIAudioSpeechResponseFormat.mp3,
      outputDirectory: await getApplicationDocumentsDirectory(),
      outputFileName: 'output'
    );

This will create an audio file and returns its path with a file extension included. You can then use just_audio package like this:

final AudioPlayer player = AudioPlayer();
await player.setFilePath(speechFile.path);

The audio should start playing even tho the file extension is mpeg.

Padi142 avatar Jun 23 '24 10:06 Padi142

@Padi142 Are you sure it is working? i tried the same code, and it is not working.

Abdelrhman-Azab avatar Oct 17 '25 15:10 Abdelrhman-Azab

@Abdelrhman-Azab Hello, it's been a while since I did this but it worked for me. Do you get any specific errors ?

Padi142 avatar Oct 17 '25 19:10 Padi142

Resolved, your request should return mp3 file, see examples/ if you need any other examples regarding this.

anasfik avatar Nov 08 '25 23:11 anasfik