how to write audio file from byte array C# code example

Example: how to write audio file from byte array C#

// to access the audio files themselves in your computer,
// you need to access the 'Name' property from the FileStream(s)

using Microsoft.VisualBasic.Devices;
using System.IO;

public class AudioFileWAV
{
  	public static FileStream Create(byte[] audio, string outputName)
    {
    	using (FileStream bytesToAudio = File.Create(outputName + ".wav"))
        {
        	bytesToAudio.Write(audio, 0, audio.Length);
          	Stream audioFile = bytesToAudio;
          	bytesToAudio.Close();
          	return audioFile;
        }
    }
  	public static void Play(string audioFile)
    {
    	new Audio().Play(audioFile);
    }
}
public class AudioFileMP3
{
  	public static FileStream Create(byte[] audio, string outputName)
    {
    	using (FileStream bytesToAudio = File.Create(outputName + ".mp3"))
        {
        	bytesToAudio.Write(audio, 0, audio.Length);
          	Stream audioFile = bytesToAudio;
          	bytesToAudio.Close();
          	return audioFile;
        }
    }
}