diff options
author | Joshua Minor <j@lux.vu> | 2008-01-10 09:34:26 (GMT) |
---|---|---|
committer | Joshua Minor <j@lux.vu> | 2008-01-10 09:34:26 (GMT) |
commit | 824aa0a89e0d424e44f5dbb18124eb8101bf12eb (patch) | |
tree | 175a27b0b6e8ab00b05e9cccfbb9aca4b4b560f0 /Speak.activity/audio.py | |
parent | 36c2ab9023493c3cf38651006f587ba0b9b009ce (diff) |
Speak v3
Lots of major performance enhancements.
Diffstat (limited to 'Speak.activity/audio.py')
-rw-r--r-- | Speak.activity/audio.py | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/Speak.activity/audio.py b/Speak.activity/audio.py index 484285d..e29ac80 100644 --- a/Speak.activity/audio.py +++ b/Speak.activity/audio.py @@ -1,3 +1,27 @@ +# Speak.activity +# A simple front end to the espeak text-to-speech engine on the XO laptop +# +# Copyright (C) 2008 Joshua Minor +# This file is part of Speak.activity +# +# Parts of Speak.activity are based on code from Measure.activity +# Copyright (C) 2007 Arjun Sarwal - arjun@laptop.org +# +# Speak.activity is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Foobar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Foobar. If not, see <http://www.gnu.org/licenses/>. + +# This code is a stripped down version of the audio grabber from Measure + import pygst pygst.require("0.10") import gst @@ -19,6 +43,8 @@ class AudioGrab(gobject.GObject): self.pipeline = None def playfile(self, filename): + self.stop_sound_device() + # build a pipeline that reads the given file # and sends it to both the real audio output # and a fake one that we use to draw from @@ -44,6 +70,36 @@ class AudioGrab(gobject.GObject): # how do we detect when the sample has finished playing? # we should stop the sound device and stop emitting buffers # to save on CPU and battery usage when there is no audio playing + + def playfd(self, fd): + self.stop_sound_device() + + # build a pipeline that reads the given file + # and sends it to both the real audio output + # and a fake one that we use to draw from + if self.pipeline is None: + p = 'fdsrc name=fd-source ! wavparse ! tee name=tee tee.! audioconvert ! alsasink tee.! queue ! audioconvert name=conv' + self.pipeline = gst.parse_launch(p) + + # make a fakesink to capture audio + fakesink = gst.element_factory_make("fakesink", "fakesink") + fakesink.connect("handoff",self.on_buffer) + fakesink.set_property("signal-handoffs",True) + self.pipeline.add(fakesink) + + # attach it to the pipeline + conv = self.pipeline.get_by_name("conv") + gst.element_link_many(conv, fakesink) + + # set the source file + self.pipeline.get_by_name("fd-source").set_property('fd', fd) + + # play + self.restart_sound_device() + + # how do we detect when the sample has finished playing? + # we should stop the sound device and stop emitting buffers + # to save on CPU and battery usage when there is no audio playing def on_quit(self): self.pipeline.set_state(gst.STATE_NULL) @@ -59,7 +115,8 @@ class AudioGrab(gobject.GObject): return True def stop_sound_device(self): - self.pipeline.set_state(gst.STATE_NULL) + if self.pipeline is not None: + self.pipeline.set_state(gst.STATE_NULL) def restart_sound_device(self): self.pipeline.set_state(gst.STATE_PLAYING) |