0

我正在编写一个程序来控制我的系统音量增加或减少语音命令。但我不知道应该如何安装所有软件包以及应该安装哪些软件包?我在 pycharm 中使用 python 3.7.0

4

2 回答 2

0

我不确定,但你可能可以使用 tkinter。我创建了一个复制 GUI 文件,所以只需复制此代码并粘贴到 python 中:

from tkinter import  *

try:
    root=Tk()
    root.title("file copier")

    fname=mystring=StringVar()

    root.geometry = Canvas(root, width = 3000, height = 3000)
    label=Label(root,text="enter the file name with file extension", fg="black") .grid(row=0, column=0,sticky=W)
    entry=Entry(root, textvariable=fname) .grid(row=0, column=1)


#specifying the function going to be assigned to the button
    def duplicatefunction():
        print(fname.get())
        with open(fname.get(),"rb") as f:
            data = f.read()
        with open("copy file(rename this file and copy info inside).exe","wb") as f:
            f.write(data)

    
    button1=Button(text="duplicate file", command=duplicatefunction) .grid(row=0, column=2)

    root.mainloop()
except FileNotFoundError:
    print("no such file found named", entry)

因此,如果您看到我在函数中的文件名后键入了 exe 扩展名。尝试在记事本中输入您的所有代码,然后从此文件转换为 exe(粘贴代码后保存文件并运行它),您可以通过更改扩展名来做到这一点,但您也应该复制,无论如何这个文件的代码仅用于您的参考和顺便说一句,复制文件将仅在 pycharm 中,如果您像我一样将它用于 python IDLE,它将出现在文件资源管理器中。通过复制文件来转换记事本文件,然后返回,输入您的音量代码,并在最后使用此代码作为控制音量的代码:

fname=StringVar()
print(fname.get())
        with open(fname.get(),"rb") as f:
            data = f.read()

所以数据应该被读取和工作,我希望它对我有用,在其他项目中。

于 2020-12-23T10:06:49.680 回答
0

我在https://techoverflow.net/2020/04/04/how-to-set-windows-audio-volume-using-python/上发现了一些有趣的东西, 但这仅适用于 Windows。

他们使用的包是pycaw. 您可以使用
pip install pycaw.

那是网站上的脚本:

from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
import math
# Get default audio device using PyCAW
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
    IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
# Get current volume 
currentVolumeDb = volume.GetMasterVolumeLevel()
volume.SetMasterVolumeLevel(currentVolumeDb - 6.0, None)
# NOTE: -6.0 dB = half volume !

如果我使用

volume.SetMasterVolumeLevel(-65.25, None)

我的系统音量设置为 0

volume.SetMasterVolumeLevel(0, None)

我可以将系统音量设置为100

于 2021-12-18T12:39:49.273 回答