Python的更改主/应用卷 [英] Python Change Master/Application Volume

查看:176
本文介绍了Python的更改主/应用卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何改变呢?

我在寻找类似:

SetMasterVolume(0.5)
SetAppVolume('FooBar',0.5)

我试着用ctypes.windll.winmm,但我无法找到如何使用它多文档。

I tried using ctypes.windll.winmm, but I can't find much documentation on how to use it.

先谢谢了。

推荐答案

首先导入子
    导入子

然后让主音量

def get_master_volume(self):
    proc = subprocess.Popen('/usr/bin/amixer sget Master', shell=True, stdout=subprocess.PIPE)
    amixer_stdout = proc.communicate()[0].split('\n')[4]
    proc.wait()

    find_start = amixer_stdout.find('[') + 1
    find_end = amixer_stdout.find('%]', find_start)

    return float(amixer_stdout[find_start:find_end])

和设置主音量

def set_master_volume(self, widget):
    val = self.volume
    val = float(int(val))
    proc = subprocess.Popen('/usr/bin/amixer sset Master ' + str(val) + '%', shell=True, stdout=subprocess.PIPE)
    proc.wait()

这篇关于Python的更改主/应用卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆