Here is a good sample project for reading and writing WAV files in C #:
http://www.codeproject.com/KB/audio-video/Concatenation%5FWave%5FFiles.aspx
Assuming your raw sound is an array of short (2 byte) integers, this is a simple task. The header of the WAV file is 44 bytes (see Note), so first write out the header (using the code in the sample), followed by the data.
Note. not all WAV files are "canonical", which means that they do not have all the 44-byte header followed by the data. The WAV format is actually a RIFF format, which means that they can contain all kinds of different data, and the header is not necessarily at the beginning. However, none of this matters, since you are just writing WAV files.
Update: If a speech recognition program expects a stream (as opposed to a file path), it is easy to create a MemoryStream as follows:
byte[] bytes = System.IO.File.ReadAllBytes("c:\whatever.wav"); System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
Or you can avoid file I / O altogether and create your WAV file as an array of bytes in memory and create a MemoryStream from that.
source share