Play byte [] in C #

The concept of this program that I am trying to do is an novelty audio encryption application. I have very little experience using audio libraries in C #. I am trying to record a sound which will then be converted to byte [] in order to go through some encryption. This will be saved in .wav format. Then I will need to read in the encrypted sound file and convert it to an array of bytes in order to decrypt and then play the decrypted array of bytes. I know that at first it would be easier to save the file before performing encryption / decryption, but I do not want the unencrypted version to be saved.

What is the best way / libraries to convert the recorded sound to byte [] first and then save. Finally, what is the best way to play with the decrypted byte []. Any code / pseudo code will be appreciated.

thank

+3
source share
1 answer

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

I will write it 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();
}
+5
source

All Articles