Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text to speech model returning mpeg file, not mp3 #181

Open
Lazizbek97 opened this issue Jun 9, 2024 · 3 comments
Open

text to speech model returning mpeg file, not mp3 #181

Lazizbek97 opened this issue Jun 9, 2024 · 3 comments

Comments

@Lazizbek97
Copy link

Lazizbek97 commented Jun 9, 2024

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;

}
`

@Padi142
Copy link

Padi142 commented Jun 20, 2024

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.

@dustinpham235
Copy link

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

@Padi142
Copy link

Padi142 commented Jun 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants