Looking for a app similar to the Dog Whistle for the iPhone
Stuart Pullinger
s.pullinger at elec.gla.ac.uk
Fri Apr 24 17:20:39 CEST 2009
Adam Jimerson wrote:
> Thanks that is what I was looking for,
No probs.
> to bad there isn't a UI or anything for it.
>
Tadaaa! Hope pasting it into an email doesn't ruin the formatting. This
is my first pygtk/pygst program and it has been cobbled together from
various code examples on the web. I hope you like it.
Stuart
#!/usr/bin/env python
##
# testtone.py
# Hacked together by Stuart Pullinger (s dot pullinger at elec dot gla
dot ac dot uk) from the following sources:
# http://www.pygtk.org/pygtk2tutorial/index.html
# http://pygstdocs.berlios.de/pygst-tutorial/index.html
#
http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
##
import pygtk
pygtk.require('2.0')
import gtk
import pygst
pygst.require("0.10")
import gst
class TestTone:
def startstop(self, widget, data=None):
if self.playing:
#we are playing so stop
self.pipeline.set_state(gst.STATE_NULL)
self.playing = False
else:
#we are stopped so start playing
self.pipeline.set_state(gst.STATE_PLAYING)
self.playing = True
def change_freq(self, adj):
self.audiotestsrc.set_property('freq', adj.value)
def change_vol(self, adj):
self.audiotestsrc.set_property('volume', adj.value)
def delete_event(self, widget, event, data=None):
print "delete event occurred"
return False
def destroy(self, widget, data=None):
print "destroy signal occurred"
gtk.main_quit()
def __init__(self):
# create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.set_border_width(10)
self.button = gtk.Button("Start / Stop")
self.button.connect("clicked", self.startstop, None)
self.adjustfreq = gtk.Adjustment(440, 20, 20000, 10, 100, 0)
self.freq_button = gtk.SpinButton(adjustment=self.adjustfreq,
climb_rate=0.5, digits=2)
self.adjustfreq.connect('value_changed', self.change_freq)
self.adjustvol = gtk.Adjustment(0.4, 0, 1, 0.01, 0.1, 0)
self.vol_button = gtk.SpinButton(adjustment=self.adjustvol,
climb_rate=0.5, digits=2)
self.adjustvol.connect('value_changed', self.change_vol)
self.pipeline = gst.Pipeline("mypipeline")
self.audiotestsrc = gst.element_factory_make("audiotestsrc",
"audio")
self.audiotestsrc.set_property('freq', 440)
self.audiotestsrc.set_property('volume', 0.4)
self.pipeline.add(self.audiotestsrc)
self.sink = gst.element_factory_make("alsasink", "sink")
self.pipeline.add(self.sink)
self.audiotestsrc.link(self.sink)
self.playing = False
self.vbox = gtk.VBox(False, 0)
self.vbox.pack_start(self.freq_button)
self.vbox.pack_start(self.vol_button)
self.vbox.pack_start(self.button)
self.window.add(self.vbox)
self.button.show()
self.freq_button.show()
self.vol_button.show()
self.vbox.show()
self.window.show()
def main(self):
# All PyGTK applications must have a gtk.main(). Control ends here
# and waits for an event to occur (like a key press or mouse event).
gtk.main()
# If the program is run directly or passed as an argument to the python
# interpreter then create a HelloWorld instance and show it
if __name__ == "__main__":
testtone = TestTone()
testtone.main()
More information about the community
mailing list