text to speech model returning mpeg file, not mp3
Lazizbek97 opened this issue · 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 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
.