Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing byte[] in C# [closed]

The concept behind this program I am trying to make is a novelty audio encryption application. I have very little experience in using the audio libraries within C#. I am trying to record sound which will then be converted to a byte[] in order to undergo some encryption. This will then be saved in a .wav format. I will then need to read in the encrypted audio file and convert this to a byte array to decrypt and then play the decrypted byte array. I know it would be easier to save the file first before performing the encryption/decryption but I don't want an unencrypted version to be saved.

What is the best way/libraries in order to firstly convert the recorded audio to the byte[] and then save. Finally what is the best way to go about playing the decrypted byte[]. Any code / pseudo code would be appreciated.

Thanks

like image 453
AndrewBennett Avatar asked Dec 20 '22 17:12

AndrewBennett


1 Answers

You can use SoundPlayer class to play audio, and you can provide the data to it using a stream. For your case a MemoryStream would be appropriate solution.

I'll write this by heart:

// Get your sound buffer
byte[] sound = GetMySounds();
// Place the data into a stream
using (MemoryStream ms = new MemoryStream(sound))
{
    // Construct the sound player
    SoundPlayer player = new SoundPlayer(ms);
    player.Play();
}
like image 93
Nikola Radosavljević Avatar answered Dec 28 '22 07:12

Nikola Radosavljević