views:

963

answers:

4

My machine has two audio inputs: a mic in that I use for gaming, and a line in that I use for guitar. When using one it's important that the other be muted to remove hiss/static, so I was hoping to write a small script that would toggle which one was muted (it's fairly inconvenient to click through the tray icon, switch to my input device, mute and unmute).

I thought perhaps I could do this with pywin32, but everything I could find seemed specific to setting the output volume rather than input, and I'm not familiar enough with win32 to even know where to look for better info.

Could anybody point me in the right direction?

+3  A: 
tgray
+1  A: 

You are probably better off using ctypes - pywin32 is good if you are using one of the already included APIs, but I think you'll be out of luck with the sound APIs. Together with the example code from the C# link provided by tgray, use ctypes and winmm.dll, or alternatively, use SWIG to wrap winmm.dll. This may well be quicker as you won't have to build C structure mapping types in ctypes for the types such as MIXERCONTROLDETAILS which are used in the API calls.

Vinay Sajip
A: 

tgray seems to have pointed you in the right direction, but once you find out the right Win32 APIs to deal with, you have a couple of options:

1) Try using pywin32...but it may or may not wrap the functionality you need (it probably doesn't). So you probably only want to do this if you need to use COM to get at the functionality you need.

2) Use ctypes. It's generally pretty easy to wrap just about any C functionality with ctypes.

3) If the C# example looks like what you need, you should be able to translate it to IronPython with fairly little effort. Might be easier than using the C API. YMMV, of course.

Kevin Horn
+1  A: 

I had a similar problem and couldn't figure out how to use Windows API's to do what I wanted. I ended up just automating the GUI with AutoIt. I think that will be the fastest and easiest solution (albeit a "hacky" one). As I answered earlier today, you can use AutoIT from within Python.

Therms
I tried to get into the Windows API, but unfortunately found it impenetrable. I'm satisfied with my AutoIt solution though; if anyone's interested the script is at http://bitbucket.org/kiv/scripts/src/tip/muteit.au3
Kiv