Writing MemoryStream binary to a file

  • Thread starter Thread starter Twistfactory
  • Start date Start date
T

Twistfactory

Hi all,

I'm trying to implement a voice recording function. Basically it's
supposed to record the WAV and write it out to the file, at which
point LAME will kick in and convert it to MP3.

The only problem is that I'm having issues writing it out. I'm using
this code as a base: http://www.eggheadcafe.com/articles/20050611.asp

It records fine and I can play it back through my speakers, but when I
try to export it, Windows Media Player doesn't recognize the file and
LAME converts it into a long screeching sound. This is the code I'm
trying:

FileStream fs = File.OpenWrite("try.wav");

fs.Write(RecordStream.GetBuffer(), 0, (int)RecordStream.Position);

fs.Close();


I've also tried this with the same result:

fs.Write(RecordStream.ToArray(), 0, (int)RecordStream.Length);

Any ideas?
 
Hi,
I havent worked witht he eggheadcafe code that you mentioned.
try resetting the RecordStream Position to the beginning before writing it
out to the file.

RecordStream.Position = 0; or
RecordStream.Seek(0, SeekOrigin.Begin);

and then use Length property to write it to filestream.

HTH,
Rakesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top