LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 12-14-2004, 01:32 PM   #1
mijenks
Member
 
Registered: Mar 2004
Location: NY
Distribution: Gentoo
Posts: 112

Rep: Reputation: 15
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.
 
Old 12-14-2004, 06:30 PM   #2
Dodgeram01
Member
 
Registered: Jun 2003
Distribution: Gentoo and Ubuntu
Posts: 95

Rep: Reputation: 15
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"

Last edited by Dodgeram01; 12-14-2004 at 07:31 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mute/volume buttons to work? microsoft/linux Linux - Laptop and Netbook 7 08-20-2005 03:35 PM
Dell Inspiron 9200 Volume, Play, Mute Quick Buttons and Sound with Suse 9.3 elliotfuller Linux - Hardware 1 06-08-2005 11:38 PM
Volume Up/Down/Mute keys not working Blargity Linux - Laptop and Netbook 10 06-02-2005 11:56 AM
How to add another drive volume to Windows? mrgrieves General 4 04-25-2004 12:37 PM
Setting volume in a startup script Twigathy Mandriva 3 08-25-2003 08:25 AM


All times are GMT -5. The time now is 09:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration