Windows 7 gives programmer a lots of API’s which with he/she can control hardware and software. One of these API’s are Core Audio API. This API allows programmer to develop apps that use Audio in Windows Vista and latest. This API was not included in previous versions of windows such as Windows XP, Windows 98 etc.
A programmer can easily use this API to do many things with the Audio Mixer. But as far as this post is concerned we are looking for muting the Microphone only with click of a button in C# Winforms. To read more about Core Audio API click here.
To mute the Microphone we just need to follow the simple steps given below.
Step 1:
Download the dll’s included in a zip folder by clicking here. Make a new Winform project in C# and add reference to all three of them namely CoreAudioApi.dll, MixerNativeLibrary.dll, WindowsMicrophoneMuteLibrary.dll.
Step 2:
After doing that add a Button from Toolbox to the form. Right click the form and click “View Code” Under the “Public Partial Class” initialize a boolean variable(To check the state of button i.e whether clicked or not) also intialize a WindowsMicMute Object under it by writing this
public partial class Form1 : Form
{
WindowsMicrophoneMuteLibrary.WindowsMicMute micMute = new WindowsMicrophoneMuteLibrary.WindowsMicMute();
bool press = false;
Go to the form design view and double click the button to go to the coding of click event of that button and there add these lines of code.
private void button1_Click(object sender, EventArgs e)
{
press = !press; // this is just a bool variable initialized to False under the Public Partial Class
if (press)
{
micMute.MuteMic();
}
else
{
micMute.UnMuteMic();
}
}
Step 3:
Run the app and click the button to toggle the mute/un mute of microphone.
For a complete working app click here to download. The finished app that I made looks like this.
If you come across any difficulty feel free to comment below. Thanks!
Reference: http://www.computercabal.com/2010/11/mute-microphone-from-c-on-windows.html