✅ How to play an MP3 from byte data array instead of writing it to a file and then playing it?

Hey, anyone know how I can play an MP3 directly from a byte array? This is what I currently have which works but I'd like to avoid writing it to an .mp3 file as there's no point in keeping it and it feels wrong to Write > Play > Delete if I can just play it directly from the byte array.
await File.WriteAllBytesAsync($"{voiceClip.Id}.mp3", voiceClip.ClipData.ToArray());
var reader = new Mp3FileReader($"{voiceClip.Id}.mp3");
var waveOut = new WaveOut(); // or WaveOutEvent()
waveOut.Init(reader);
waveOut.Play();
await File.WriteAllBytesAsync($"{voiceClip.Id}.mp3", voiceClip.ClipData.ToArray());
var reader = new Mp3FileReader($"{voiceClip.Id}.mp3");
var waveOut = new WaveOut(); // or WaveOutEvent()
waveOut.Init(reader);
waveOut.Play();
3 Replies
Keswiik
Keswiik2mo ago
What audio library are you using? Need actual details if you want help.
Delicious Cake
Delicious Cake2mo ago
NAudio, sorry
Keswiik
Keswiik2mo ago
Stack Overflow
Play audio from a stream using C#
Is there a way in C# to play audio (for example, MP3) direcly from a System.IO.Stream that for instance was returend from a WebRequest without saving the data temporarily to the disk? Solution with