from optparse import OptionParser from time import sleep import sys, os import pygtk, gtk, gobject import dbus import gst import pygst import sys import time import gtk import hildon class Record(): mic = None def __init__(self, sink): """ @summary: The Constructor class, that searches for the microphone on initialization """ bus = dbus.SystemBus() hal_manager = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager") hal_manager = dbus.Interface(hal_manager, "org.freedesktop.Hal.Manager") print hal_manager devices = hal_manager.FindDeviceStringMatch("alsa.type", "capture") identifiers = [] for dev in devices: device = bus.get_object("org.freedesktop.Hal", dev) card = device.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device") if card["alsa.card"] not in identifiers: print "%d. %s" % (card["alsa.card"], card["alsa.card_id"]) identifiers.append(card["alsa.card"]) self.mic = identifiers[0] """ @attention: this is important it initializes softfare playtrought (audioconvert is not nesesity) @summary: takes stream from mic to autosink """ self.pipeline = gst.parse_launch("""alsasrc device=hw:%d ! audioconvert ! autoaudiosink location=%s""" % (self.mic, sink)) def rec(self): """ @summary: sets recording on """ self.pipeline.set_state(gst.STATE_PLAYING) print "" print "recording started" def stoprec(self): """ @summary: sets recording off """ self.pipeline.set_state(gst.STATE_NULL) print "" print "recording, stoped" class Prosesor(): """ @summary: Takes care of prossesing the sound """ def __init__(self): volume=0 gain =0 CutThereshold=0 def proses(self,volume, gain, comp): a=1 class player(): def __init__(self): """ @summary: player part """ self.player = gst.element_factory_make("playbin2", "player") fakesink = gst.element_factory_make("fakesink", "fakesink") self.player.set_property("video-sink", fakesink) audiosink = gst.element_factory_make("autoaudiosink", "audio-output") self.recorder=Record(audiosink) """ @attention: next links raw data from mic to player mekanism of gstreamer """ self.player.set_property("audio-sink",audiosink) self.playmode = True bus = self.player.get_bus() bus.add_signal_watch() bus.connect("message", self.on_message) def on_message(self, bus, message): t = message.type if t == gst.MESSAGE_EOS: self.player.set_state(gst.STATE_NULL) self.playmode = False elif t == gst.MESSAGE_ERROR: self.player.set_state(gst.STATE_NULL) err, debug = message.parse_error() print "Error: %s" % err, debug self.playmode = False def play(self): self.recorder.rec() self.player.set_state(gst.STATE_PLAYING) print "playing" def stop(self): #self.playmode = False self.player.set_state(gst.STATE_NULL) self.recorder.stoprec() print "stoped" class MeHear(hildon.Program): def __init__(self): self.pl= player() def amplify_button_clicked(self,button, label): buttontext = button.get_label() text = buttontext if text == "AMPlify" : label.set_text("") button.set_label("Stop") self.pl.play() print "play button pressed" if text == "Stop" : label.set_text("Stopped") button.set_label("AMPlify") self.pl.stop() print "stop button pressed" def main(self): win = hildon.StackableWindow() # Create and pack labels vbox = gtk.VBox(False, 10) hbox = gtk.HBox(False, 10) #interface.. buttons, labels ,... etc labelHeader = gtk.Label("Application header") labelSubHeader = gtk.Label("-") # buttonGTK1 = gtk.Button("Record") # buttonGTK1.connect("clicked", self.record_button_clicked, labelSubHeader) buttonGTK = gtk.Button("AMPlify") buttonGTK.connect("clicked", self.amplify_button_clicked, labelSubHeader) # hbox.pack_start(buttonGTK1, True, True, 0) hbox.pack_start(buttonGTK, True, True, 0) vbox.pack_start(labelHeader, True, True, 0) vbox.pack_start(labelSubHeader, True, True, 0) vbox.pack_start(hbox, True, True, 0) # Add label's box to window win.add(vbox) win.connect("delete_event", gtk.main_quit) win.show_all() gtk.main() if __name__ == "__main__": app = MeHear() app.main()