[gst-devel] Python: playing several sounds using adder and mix

Stefan Kost ensonic at hora-obscura.de
Sun Nov 9 17:18:36 CET 2008


hi,

Nicolas Rougier schrieb:
> Hello everybody,
> 
> I'm pretty new to gstreamer and I've been playing with python tutorials
> to play a simple sound file. From what I've understood and if I want to
> play several sounds simultaneously, I have to use the adder and mix
> plugins but it is not yet clear to me how to do that in python.
> 
> What I would like to do indeed is to read a (typewriter) sound each time
> the user press a key as in the example below. Currently, each time the
> user press a key, I check whether a sound is being played and play the
> new one, but this does not sound nice since I may miss some keystrokes.
> I would prefer to mix the sounds with whatever is being played at the
> time I stroke a key. Does anybody know how to do that ?
> 
you could try playing a audiotestsrc (using silence) ! adder ! autoaudiosink all
the time and add filesrc ! decodebin ! adder when playing a typewriter sound.

Ideal we would have a highlevel api for doing this. I once put some ideas to the
 wiki under http://gstreamer.freedesktop.org/wiki/SampleBin but don'T have time
right now to work on it.

Stefan

> 
> 
> Nicolas
> 
> 
> -----
> You need a short sound file named 'key.wav' to run the example
> 
> 
> #!/usr/bin/env python
> 
> import sys, os
> import pygtk, gtk, gobject
> import pygst
> pygst.require("0.10")
> import gst
> 
> class GTK_Main:
>     def __init__(self):
>         window = gtk.Window(gtk.WINDOW_TOPLEVEL)
>         window.connect("destroy", gtk.main_quit, "WM destroy")
>         vbox = gtk.VBox()
>         window.add(vbox)
>         vbox.pack_start(gtk.Label("Please type text"))
>         entry = gtk.Entry()
>         vbox.pack_start(entry)
>         entry.connect("key-press-event", self.key_press_event)
>         window.show_all()
> 
>         self.player = gst.element_factory_make("playbin", "player")
>         fakesink = gst.element_factory_make("fakesink", "fakesink")
>         self.player.set_property("video-sink", fakesink)
>         bus = self.player.get_bus()
>         bus.add_signal_watch()
>         bus.connect("message", self.on_message)
> 
>     def key_press_event (self,widget, event):
>         filepath = os.path.abspath("./key.wav")
>         self.player.set_property("uri", "file://" + filepath)
>         if self.player.get_state() and gst.STATE_NULL:
>             self.player.set_state(gst.STATE_PLAYING)
> 						
>     def on_message(self, bus, message):
>         t = message.type
>         if t == gst.MESSAGE_EOS:
>             self.player.set_state(gst.STATE_NULL)
>         elif t == gst.MESSAGE_ERROR:
>             self.player.set_state(gst.STATE_NULL)
>             err, debug = message.parse_error()
>             print "Error: %s" % err, debug
> 
> GTK_Main()
> gtk.gdk.threads_init()
> gtk.main()
> 
> 
> 
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel





More information about the gstreamer-devel mailing list