Sound Recording

Must Read

Using the IronPython Windowed Environment

IronPython also provides access to a windowed environment, but you can’t access it from the start menu. Instead, you ...

Nikon D7000, A: Aperture Priority Mode

Probably the mode most widely used by professional photographers, Aperture Priority is one of my personal favorites, and I...

Government Debt Consolidation Loans

There are loans that are offered through various government programs to help people pay off multiple loans. These loans...

First-Time Home Buyers With Poor Credit Have Options

If you have poor credit and you are looking at the prospect of home ownership, you are probably worried...

Student Loan Deferment – 7 Things to Keep Straight

Know what student loan deferment means? In case you just started with financial aid, I'm going to tell you...

All About Extortion

The act of extortion occurs when a person obtains property, money, or some other valuable asset from another person...

All Windows Phone 7 physical devices include a microphone. You can access this using the methods of the XNA Framework. This is more complex than using some other features of the phone because you must initiate an asynchronous dispatcher to raise the microphone events.

To record sounds from the microphone, you must do the following:

  • Add a reference to the assembly Microsoft.Xna.Framework to your project.
  • Create an XNA asynchronous dispatcher “pump” class and initialize it in the constructor or startup event in your App.xaml. cs file.
  • Get a reference to a microphone.
  • Specify a function or lambda expression that will receive the sound data.
  • Start the microphone.

Note: An XNA asynchronous event dispatcher is an application service that allows Silverlight to detect events raised by XNA components. Usually, these events are propagated by the XNA game loop mechanism, but this is not present in a Silverlight application. The dispatcher service collects these events and raises them through the Silverlight event mechanism.

In your application, declare variables to hold the microphone instance and a stream that will receive the sound data bytes. This example uses the default microphone and an isolated storage file stream. To use this code, you must reference the namespaces Microsoft.Xna. Framework.Audio and System.IO.IsolatedStorage.

Microphone mic = Microphone.Default;
IsolatedStorageFileStream myFileStream;

Specify the callback for the BufferReady event and the size of the recording buffer. The maximum size is one second, though lower values tend to give better performance.

mic.BufferReady += Mic_BufferReady;
mic.BufferDuration = TimeSpan.FromMilliseconds(500);

Open the file stream that will receive the recorded data (in this case, an isolated storage file), and then start the microphone to begin recording.

// Create a virtual store and file stream.
// Check for an existing duplicate name.
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
String fileName = “MyAudio.dat”;
if (myStore.FileExists(fileName))
myFileStream = myStore.CreateFile(fileName);

The callback for the BufferReady event must capture the data from the microphone and store it in your target location.

void Mic_BufferReady(object sender, EventArgs e)
Microphone mic = sender as Microphone;
byte[] content = new byte[mic.GetSampleSizeInBytes
myFileStream.Write(content, 0, content.Length);

To stop recording, call the Stop method of the Microphone class and close the stream you are writing to.


You can check the status of the microphone at any time by querying the State property of the Microphone class. This returns a value from the MicrophoneState enumeration. Possible values are Started and Stopped.

For more information, see “Microphone Class” on MSDN (

Note: The files created from the byte stream returned by the Microphone class are not valid sound files. If you want to convert a saved byte stream as a .wav or .wmv file, you must use an auxiliary class or library to add the appropriate headers to the file and save it is the appropriate format. For a description of the .wav file format, see “Wave File Format” on The Sonic Spot website (

The following series of posts by Microsoft academic developer evangelist Dan Waters describe the techniques of audio programming and provide code you can reuse:

“Intro to Audio Programming, Part 1: How Audio Data is Represented” at

“Intro to Audio Programming, Part 2: Demystifying the WAV Format” at

“Intro to Audio Programming, Part 3: Synthesizing Simple Wave Audio using C#” at

“Intro to Audio Programming Part 4: Algorithms for Different Sound Waves in C#” at



Previous articleSearch
Next articleSound Playback


Please enter your comment!
Please enter your name here

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost...

More Articles Like This