Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi, I've been trying to figure out how i can take the microphone data and convert it into a memorystream so I could send it over the network. I've been following this tutorial
http://www.giawa.com/tutorials/?p=70
with NAudio to get the microphone data I just don't know how I can convert into a stream and then convert it back to something useful with NAudio afterwards. I am not very experience with NAudio nor have I really worked with audio in c# before. Any help would be greatly appreciated even if it uses another platform than NAudio. Thanks.

Also I have seen the following tutorial but had trouble trying to use it
http://csharpwithmaddy.blogspot.ca/2008/01/sending-and-playing-microphone-audio.html
Posted
Updated 16-Jul-12 6:55am
v2
Comments
Sergey Alexandrovich Kryukov 16-Jul-12 13:59pm    
You cannot "convert" data to stream. You can fill the stream with data, write data to stream, etc. I understand this is only the terminology, but putting things right often helps to solve the problem (which is really easy in this case).
--SA
Member 8601135 17-Jul-12 16:48pm    
I understand that although you say my problem is easy? Can you please help me then?

I was looking at the following function I have figured out how to fill the memory stream but have not figured out how to convert it back (I know its not converting it but I don't know how else to word that).

<pre lang="c#">
private void button5_Click(object sender, EventArgs e)
{
if (sourceList.SelectedItems.Count == 0) return;

SaveFileDialog save = new SaveFileDialog();
save.Filter = "Wave File (*.wav)|*.wav;";
if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

int deviceNumber = sourceList.SelectedItems[0].Index;

sourceStream = new NAudio.Wave.WaveIn();
sourceStream.DeviceNumber = deviceNumber;
sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

sourceStream.DataAvailable += new EventHandler<naudio.wave.waveineventargs>(sourceStream_DataAvailable);
waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, sourceStream.WaveFormat);

sourceStream.StartRecording();
}
</pre>

1 solution

Please see the definition of the class NAudio.Wave.WaveFileWriter. Among others, it has this constructor:
C#
public WaveFileWriter(Stream outStream, WaveFormat format) { /*...*/ }

where outStream is a stream to be written to. So, it can be a memory stream (but why?) or, according to your purpose, better be a network stream.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900