我想更改本地计算机麦克风的声级。我研究了很多,我找到了这个链接
- >它是代码项目链接,但它是混合项目,我想只改变麦克风声级
- >这再次给了一个项目,它是如此编译而且无法建立项目。
和ı试试这个。
它只适用于exe的语音级别,如lync,skype。它需要进程名称。麦克风exe可以经常更改。所以我不能给出稳定的名字。我想尝试win32更改那么如何更改麦克风声级呢? ı想要增加和降低声级
public static void SetMicrophoneVolume(string name,float level)
完整代码
private static List<ISimpleAudioVolume> getAppVol(string name, EDataFlow eDataFlow)
{
List<ISimpleAudioVolume> simpleAudioVolList = new System.Collections.Generic.List<ISimpleAudioVolume>();
// get the speakers (1st render + multimedia) device
IMMDeviceEnumerator deviceEnumerator = (IMMDeviceEnumerator)(new MMDeviceEnumerator());
IMMDevice speakers;
deviceEnumerator.GetDefaultAudioEndpoint(eDataFlow, ERole.eMultimedia, out speakers);
// activate the session manager. we need the enumerator
Guid IID_IAudioSessionManager2 = typeof(IAudioSessionManager2).GUID;
object o;
speakers.Activate(ref IID_IAudioSessionManager2, 0, IntPtr.Zero, out o);
IAudioSessionManager2 mgr = (IAudioSessionManager2)o;
// enumerate sessions for on this device
IAudioSessionEnumerator sessionEnumerator;
mgr.GetSessionEnumerator(out sessionEnumerator);
int count;
sessionEnumerator.GetCount(out count);
for(int i = 0; i < count; i++)
{
IAudioSessionControl ctl;
sessionEnumerator.GetSession(i, out ctl);
IAudioSessionControl2 sessionCtl = ctl as IAudioSessionControl2;
uint processId;
string displayName;
string iconPath;
string sessionIdentifier;
string sessionInstanceIdentifier;
sessionCtl.GetProcessId(out processId);
sessionCtl.GetDisplayName(out displayName);
sessionCtl.GetIconPath(out iconPath);
sessionCtl.GetSessionIdentifier(out sessionIdentifier);
sessionCtl.GetSessionInstanceIdentifier(out sessionInstanceIdentifier);
Debug.WriteLine("process id:" + processId + " name:" + displayName + " icon:" + iconPath + " sessionIdentifier:" + sessionIdentifier + " sessionInstanceIdentifier:" + sessionInstanceIdentifier);
//Process process = Process.GetProcessesByName(name).FirstOrDefault<Process>(delegate(Process item) { return processId == item.Id; });
if(sessionIdentifier.Contains(name))
{
simpleAudioVolList.Add((ISimpleAudioVolume)sessionCtl);
}
}
Marshal.ReleaseComObject(sessionEnumerator);
Marshal.ReleaseComObject(mgr);
Marshal.ReleaseComObject(speakers);
Marshal.ReleaseComObject(deviceEnumerator);
return simpleAudioVolList;
}
private static void releasesimpleAudioVolList(List<ISimpleAudioVolume> volumeControlList)
{
foreach(ISimpleAudioVolume item in volumeControlList)
{
Marshal.ReleaseComObject(item);
}
}
public static void SetMicrophoneVolume(string name, float level)
{
List<ISimpleAudioVolume> volumeList = getAppVol(name, EDataFlow.eCapture);
Guid guid = Guid.Empty;
foreach(ISimpleAudioVolume item in volumeList)
{
try
{
item.SetMasterVolume(level / 100, ref guid);
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
releasesimpleAudioVolList(volumeList);
return;
}