LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script to Mute Windows' Volume (https://www.linuxquestions.org/questions/programming-9/script-to-mute-windows-volume-266343/)

mijenks 12-14-2004 12:32 PM

Script to Mute Windows' Volume
 
I want to write something that will mute the sound (on a Windows machine) after a certain period of time, either pre-set or user-defined. Basically it will work as a sleep timer. I am pretty familiar with Python, but not too much else. So I would prefer to use Python. I couldn't find any modules in the docs, however, that would allow this type of interfacing with Windows' audio control.

Any suggestions on how to do this would be good. Or if you know of an mp3 playing program that has 'sleep timer' functionality built in, let me know. Thanks.

Dodgeram01 12-14-2004 05:30 PM

I'm not aware of any "easy" way to truly mute the device. However, following is a script with will set the volume for the windows Wave device to 0, which for me will essentially "mute" the audio output. To use the below script, just call the Mute() function with either True or False. You will also need to have tkSnack installed. It is available here. If anyone else has any better methods as to acheiving this goal, I'd be very interested to see them. Also, I believe pyGame has got some sound functions, but I did not look at them indepth.

Code:

import Tkinter
import tkSnack

root = Tkinter.Tk()
tkSnack.initializeSnack(root)
root.withdraw()




def Mute(boolean):
    global original
    if boolean is True:
        original = tkSnack.audio.play_gain()
        print "the original before mute is:", original
        tkSnack.audio.play_gain(0)
       
    elif boolean is False:
        g = globals()
        if (tkSnack.audio.play_gain() == 0) and (g.has_key('orignal')):
            tkSnack.audio.play_gain(original)
        elif tkSnack.audio.play_gain() == 0:
            tkSnack.audio.play_gain(100)
        else:
            pass

Below is a small driver program:
Code:

import mute

quit = 0
while quit == 0:
    print "(1) Mute Sound"
    print "(2) Unmute Sound"
    print "(3) Quit"
    choice = input("Choice: ")

    if choice == 1:
        mute.Mute(True)
    elif choice == 2:
        mute.Mute(False)
    elif choice == 3:
        break
    else:
        print "You have made an invalid selection"



All times are GMT -5. The time now is 01:23 AM.