Mute (only) the main speaker
I wanted to get started with VoIP. When someone calls, I would like to hear the ring from the main speakers but when I am talking, I would like to hear the other’s voice only in the headset.
My computer has two audio connections: A microphone and speaker at the front side of the chassis, and microphone, speaker and line-in at the back side. I can set the volume for them independently (the one at the front being called “Headset” and the one at the back “Front”). I connected the headset to “Headset” and the main speakers to “Front”.
You can now open the Volume Control each time you recieve a call and mute “Front” as soon as you pick up, but that involves a lot of klicking whereas you would like to concentrate on the phone call (and it won’t be very fast).
Therefore, I wrote a little script based on ggmail which displays a small tray icon. When you click on it, it mutes the “Front” speaker. It also changes the icon so that you can see if “Front” is muted or not in the moment.
ggmail does not work on 64bit operating systems (as mine is), but I found that Richard Côté solved that issue. Otherwise, it’s a quite simple reduction of ggmail.
I added one more feature though, that is a small box that pops up when you right-click on the icon telling you what this thing is about.
As icons, I took two of Mark James’ silk icons set.
~/mute4phone/mute4phone.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #!/usr/bin/env python #=================================================# # # # mute4phone # # based on ggmail # # Version: 1.3.0 [beta] # # by solarwind # # by Sebastian Busch # # # #=================================================# import pygtk, gtk, gobject import sys, os, time, warnings, string import egg # http://www.flubu.com/blog/2008/03/ import egg.trayicon import pynotify from string import split import mute4phone_config pygtk.require("2.0") class mute4phone: #Fields: current = None #Current status: True = on (not muted), False = off (muted). maintimer = None #Main check timer. def __init__(self): #Initiate the configuration: self.conf = mute4phone_config.Config() #Create objects: self.tray = egg.trayicon.TrayIcon("mute4phone"); self.eventbox = gtk.EventBox() self.hb = gtk.HBox(False, 0) self.tooltip = gtk.Tooltips() #Set the image for the tray icon: self.imageicon = gtk.Image() self.imageicon.set_from_file(self.conf.icondir + "/on.png") #Add objects: self.hb.add(self.eventbox); self.tray.add(self.hb) self.eventbox.add(self.imageicon) #Create notifications: if not pynotify.init(" mute4phone "): sys.exit(1) self.n = pynotify.Notification("mute4phone", "mute4phone", self.conf.uri, self.eventbox) self.n.update("mute4phone", "mute4phone has started...") #Set connections: self.eventbox.connect("button_press_event", self.ButtonPress, self.n) #Show objects: self.tray.show_all() #Check mute initially: self.CheckMute() #Add a gobject loop to check mute: self.maintimer = gobject.timeout_add(self.conf.CheckInterval * 1000, self.CheckMute) #Main mute check function: def CheckMute(self): cmd = "amixer -c "+str(self.conf.cardnum)+" cget numid="+str(self.conf.numid) msg = os.popen(cmd).read() onoff = split(msg.split()[-1],sep=",")[-1] if onoff == "on": self.current = True self.UpdateIcon() elif onoff == "off": self.current = False self.UpdateIcon() else: sys.exit() #Update icon: def UpdateIcon(self): if self.current: self.imageicon.set_from_file(self.conf.icondir + "/on.png") else: self.imageicon.set_from_file(self.conf.icondir + "/off.png") #Toggle mute function: def ToggleMute(self): if self.current: goto = "off" else: goto = "on" cmd = "amixer -c "+str(self.conf.cardnum)+" cset numid="+str(self.conf.numid)+" "+goto os.system(cmd) self.CheckMute() #Show help: def ShowHelp(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) #window.connect("destroy", lambda w: gtk.main_quit()) window.set_title("mute4phone") vbox = gtk.VBox(False, 5) hbox = gtk.HBox(False, 5) window.add(hbox) hbox.pack_start(vbox, False, False, 0) frame = gtk.Frame("mute4phone") label = gtk.Label("Mutes and unmutes the Front speaker\nwhile not touching the headphones") frame.add(label) vbox.pack_start(frame, False, False, 0) frame = gtk.Frame("Mouse Buttons") label = gtk.Label("Left: Mute / Unmute (Toggle)\nMiddle: exit\nRight: This help") frame.add(label) vbox.pack_start(frame, False, False, 0) window.show_all() #Handle icon button events: def ButtonPress(self, signal, event, n): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: self.ToggleMute() if event.type == gtk.gdk.BUTTON_PRESS and event.button == 2: sys.exit() if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: self.ShowHelp() #GTK mainloop: def main(self): gtk.main() #Main: if __name__ == "__main__": warnings.filterwarnings(action = "ignore", category = DeprecationWarning) mutenotifier = mute4phone() mutenotifier.main() |
~/mute4phone/mute4phone_config.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # File: config.py # Class: Config # This is the main user configuration file for mnute4phone. import sys, os class Config: #How often to check for mute status, in seconds: CheckInterval = 60 #The absolute path to the program's directory: icondir = "/home/toftof/sbusch/mute4phone/" #Select the card number to control. The device name created from this parameter has syntax 'hw:N' where N is specified card number. cardnum = 0 #Select the numid to control numid = 2 #Do not modify below this level. #icondir = os.path.abspath(os.path.curdir) uri = "file://" + icondir + "/mail.png" def __init__(self): pass |