c# Winform 获取麦克风音量 控制麦克风音量大小 (自用笔记未测试)

如果你要获取麦克风的音量, 你可以尝试GetVolumeInformation方法或者 waveOutGetVolume()方法. 例如:
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool GetVolumeInformation(string Volume, StringBuilder VolumeName, 
	uint VolumeNameSize, out uint SerialNumber, out uint SerialNumberLength, 
	out uint flags, StringBuilder fs, uint fs_size);

//在方法内:
uint serialNum, serialNumLength, flags;
StringBuilder volumename = new StringBuilder(256);
StringBuilder fstype = new StringBuilder(256); 

bool ok = = GetVolumeInformation(drives, volumename, 
	(uint)volumename.Capacity - 1, out serialNum, out serialNumLength, 
	out flags, fstype, (uint)fstype.Capacity - 1);

if (ok)
 {
 lblVolume.Text = lblVolume.Text + "\n Volume Information of " + drives + "\n";
 lblVolume.Text = lblVolume.Text + "\nSerialNumber of is..... " + 
	serialNum.ToString() + " \n";
  if (volumename != null)
  {
  lblVolume.Text = lblVolume.Text + "VolumeName is..... " + 
	volumename.ToString() + " \n";
  }
if (fstype != null)
 {
 lblVolume.Text = lblVolume.Text + "FileType is..... " + fstype.ToString() + " \n";
 }
如果你要雕节麦克风的音量, 你可以试试 waveOutSetVolume()方法。
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);

//在方法内
uint CurrVol = 0;
// At this point, CurrVol gets assigned the volume
 waveOutGetVolume(IntPtr.Zero, out CurrVol);
 // Calculate the volume
 ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
 // Get the volume on a scale of 1 to 10 (to fit the trackbar)
textBox1.Text = (CalcVol / (ushort.MaxValue / 10)).ToString();
 请参考一下链接:
http://www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html

你可能感兴趣的:(C#)