gpt4 book ai didi

python - 在 Python 中静音/取消静音扬声器

转载 作者:行者123 更新时间:2023-12-05 07:35:01 34 4
gpt4 key购买 nike

我正在尝试创建一个播放音频文件并且不允许用户轻易取消文件播放的恶意软件。我测试了来自 https://python-forum.io/Thread-How-to-change-the-sound-volume-with-python 的一些代码遇到了一个问题。以下代码确实会更改计算机的音量级别,但不会取消静音。例如:

from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume

devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))

# Control volume
volume.SetMasterVolumeLevel(-0.0, None) #max
volume.SetMasterVolumeLevel(-5.0, None) #72%
volume.SetMasterVolumeLevel(-10.0, None) #51%

我正在将此恶意软件创建为一个学生项目,因此希望得到一些帮助(除了一些非常基本的 Python 库之外,我对库也不是非常熟悉。)

最佳答案

0表示取消静音

volume.SetMute(0, None)

关于python - 在 Python 中静音/取消静音扬声器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49805800/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com