markokosticdev / cloud_text_to_speech_flutter

Single interface to Google, Microsoft, and Amazon Text-To-Speech.
https://pub.dev/packages/cloud_text_to_speech
BSD 2-Clause "Simplified" License
4 stars 4 forks source link

Basic question: How to play ByteData in flutter #3

Closed Jaha96 closed 11 months ago

Jaha96 commented 1 year ago

ByteData audioBytes = ttsResponse.audio.buffer.asByteData());

Is there any suggested optimal workaround how to play this bytes in Flutter? or any library suggestions?

Thank you in advance.

markokosticdev commented 11 months ago
final String filePath = "path/to/file.mp3";
final File audioFile = File(filePath);
await audioFile.writeAsBytes(audioResponse.audio);
// OR
final base64Data = base64.encode(audioResponse.audio);
final dataUri = "data:audio/mpeg;base64,$base64Data";

And use any audio player for Flutter