如何使用Python更改音量? [英] How to change volume with Python?
问题描述
我正在编写一个程序来唤醒我,但是我希望我的程序播放尽可能大的警报声音.因此需要将音量提高到100%.但我不知道怎么做我在macOS Sierra上使用python3
.
I'm writing a program to wake me up mornings, but I want my program to play alarm sound as loud as its possible. so it needs to raise up volume to 100%. but I don't know how. I'm using python3
on macOS Sierra.
推荐答案
您可以使用Applescript控制计算机的音量:
You can control the volume of your computer with Applescript:
set volume output volume 100
要从python执行Applescript,可以使用py-applescript
,该软件可以与sudo easy_install py-applescript
一起安装.以下脚本将设置音量:
To execute Applescript from python you can use py-applescript
which can be installed with sudo easy_install py-applescript
. The following script will set the volume:
import applescript
applescript.AppleScript("set volume output volume 100").run()
对于Python3.6,您可以使用osascript
代替:pip3.6 install osascript
和:
For Python3.6 you can use osascript
instead: pip3.6 install osascript
and:
import osascript
osascript.osascript("set volume output volume 100")
这篇关于如何使用Python更改音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!