text to speech model returning mpeg file, not mp3
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;
} `
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 would you mind sharing the code, I've tried what you suggested but none of it works. Thank you
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 Are you sure it is working? i tried the same code, and it is not working.
@Abdelrhman-Azab Hello, it's been a while since I did this but it worked for me. Do you get any specific errors ?
Resolved, your request should return mp3 file, see examples/ if you need any other examples regarding this.