I wrote a little ditty to set Win volume, which will also check for what you want (attached)
On my system, just running it prints: C:\projects\sound>PYTHON VOL.PY cbStruct 24 dwControlID 1 cChannels 1 cMultipleItems 0 cbDetails 4 paDetails c_ulong(32639) waveOutGetNumDevs= 1 mixerGetNumDevs 1 res: 0 wMid= 131133 wPid= 821793 vDriverVersion= 1852729687 szPname= ov Videum Wave Playback 4Ä ¤ dwFormats= 2162690 wChannels= 4 res 0 l: 0 r: 0 Ray At 04:51 PM 3/13/2006, Roger Upole wrote: >Trent Mick wrote: >> Does anybody know of a way to programmatically check if a particular >> Windows box has a soundcard installed and configured? >> >> Background: >> I'm running a Windows buildbot for Python and the test suite fails on >> test_winsound.py because the box doesn't have a sound card setup. (The >> "Sound" Control Panel items says there are "No Playback Devices" for >> Sound Playback.) > >WMI can list sound devices. > >import win32com.client >wmi=win32com.client.GetObject('winmgmts:') >scs=wmi.InstancesOf('win32_sounddevice') >for sc in scs: > print sc.Properties_('Name'), sc.Properties_('Status') > > >You might also have to check one of the other properties >to make sure the device is actually operating, I don't >have a non-functional device to test with. > > Roger > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32
#!/usr/bin/env python #Boa:PyApp:main modules = {} import ctypes mixerSetControlDetails = ( ctypes.windll.winmm.mixerSetControlDetails) mixerGetControlDetails = ( ctypes.windll.winmm.mixerGetControlDetailsA) # Some constants MIXER_OBJECTF_MIXER = 0 # mmsystem.h VOLUME_CONTROL_ID = 0 # Same on all machines? SPEAKER_LINE_FADER_ID = 1 # "Identifier <identifier> in OID value does not resolve to a positive integer" MINIMUM_VOLUME = 0 # fader control (MSDN Library) MAXIMUM_VOLUME = 65535 # fader control (MSDN Library) class MIXERCONTROLDETAILS(ctypes.Structure): _pack_ = 1 _fields_ = [('cbStruct', ctypes.c_ulong), ('dwControlID', ctypes.c_ulong), ('cChannels', ctypes.c_ulong), ('cMultipleItems', ctypes.c_ulong), ('cbDetails', ctypes.c_ulong), ('paDetails', ctypes.POINTER(ctypes.c_ulong))] def setVolume(volume): """Set the speaker volume on the 'Volume Control' mixer""" if not (MINIMUM_VOLUME <= volume <= MAXIMUM_VOLUME): raise ValueError, "Volume out of range" cd = MIXERCONTROLDETAILS(ctypes.sizeof(MIXERCONTROLDETAILS), SPEAKER_LINE_FADER_ID, 1, 0, ctypes.sizeof(ctypes.c_ulong), ctypes.pointer(ctypes.c_ulong(volume))) ret = mixerSetControlDetails(VOLUME_CONTROL_ID, ctypes.byref(cd), MIXER_OBJECTF_MIXER) if ret != 0: print WindowsError, "Error %d while setting volume" % ret ret = mixerGetControlDetails(VOLUME_CONTROL_ID, ctypes.byref(cd), MIXER_OBJECTF_MIXER) if ret != 0: print WindowsError, "Error %d while setting volume" % ret else: print 'cbStruct', cd.cbStruct print 'dwControlID', cd.dwControlID print 'cChannels', cd.cChannels print 'cMultipleItems', cd.cMultipleItems print 'cbDetails', cd.cbDetails print 'paDetails', cd.paDetails.contents return setVolume((2**16-1)/2) from ctypes import * from struct import * winmm= windll.winmm print print 'waveOutGetNumDevs=',winmm.waveOutGetNumDevs() print 'mixerGetNumDevs', winmm.mixerGetNumDevs() wvcps= ' '*52 print 'res:', winmm.waveOutGetDevCapsA(0,wvcps,len(wvcps)) res = unpack('IIL32cLI', wvcps) wMid=res[0] wPid=res[1] vDriverVersion=res[2] szPname=''.join(res[3:35]) dwFormats=res[35] wChannels=res[36] print 'wMid=',wMid print 'wPid=',wPid print 'vDriverVersion=',vDriverVersion print 'szPname=',szPname print 'dwFormats=',dwFormats print 'wChannels=',wChannels vol=c_ulong() print 'res', winmm.waveOutGetVolume(0, byref(vol)) print 'l:', vol.value & 0xffff, 'r:',vol.value >> 16 # left, right
_______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32