winmm实现调整windows系统音量大小的python方法,winmmpython,winmm实现调整win


winmm实现调整windows系统的音量大小的python方法,比较有意思,可以试试。

#! /usr/bin/env python#coding=utf-8import ctypesimport struct#winmm = ctypes.windll.winmmwaveOutGetVolume = (  ctypes.windll.winmm.waveOutGetVolume)waveOutSetVolume = (  ctypes.windll.winmm.waveOutSetVolume)# 最小/最大音量的常量设定MINIMUM_VOLUME = 0     # fader control (MSDN Library)MAXIMUM_VOLUME = 4294967295 # fader control (MSDN Library)#调节音量 volue范围 0-100def SetVolume(volume):    """Set the speaker volume on the 'Volume Control' mixer"""    if not (MINIMUM_VOLUME <= volume <= MAXIMUM_VOLUME):        raise ValueError, "Volume out of range"    #按公式处理音量数值    volume = volume * MAXIMUM_VOLUME/100;    #设置音量    ret = waveOutSetVolume(0, volume)    if ret != 0:        print WindowsError, "Error %d while setting volume" % ret    returnif __name__ == '__main__':    #最大音量    SetVolume(100)    #中等音量    SetVolume(50)    #静音    SetVolume(0)

编橙之家文章,

评论关闭