赞
踩
winmm实现调整windows系统的音量大小的python方法,比较有意思,可以试试。
#! /usr/bin/env python
#coding=utf-8
import ctypes
import struct
#winmm = ctypes.windll.winmm
waveOutGetVolume = (
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-100
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"
#按公式处理音量数值
volume = volume * MAXIMUM_VOLUME/100;
#设置音量
ret = waveOutSetVolume(0, volume)
if ret != 0:
print WindowsError, "Error %d while setting volume" % ret
return
if __name__ == '__main__':
#最大音量
SetVolume(100)
#中等音量
SetVolume(50)
#静音
SetVolume(0)
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/code/other/o2404.html
相关文章 Recommend
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。