From: Thomas Fillon Date: Thu, 9 Jan 2014 10:48:00 +0000 (+0100) Subject: Encoder: live AudioSink encoder, encoder that plays the audio stream through the... X-Git-Tag: 0.5.3~25 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5e7ad135588fd17271b22a7873719bcacf923a7b;p=timeside.git Encoder: live AudioSink encoder, encoder that plays the audio stream through the sounbdcard --- diff --git a/doc/source/api/encoder/index.rst b/doc/source/api/encoder/index.rst index 6ec39f3..fbe4af3 100644 --- a/doc/source/api/encoder/index.rst +++ b/doc/source/api/encoder/index.rst @@ -53,3 +53,10 @@ WebM encoder .. automodule:: timeside.encoder.webm :members: + + +AudioSink encoder +------------ + +.. automodule:: timeside.encoder.audiosink + :members: diff --git a/timeside/encoder/__init__.py b/timeside/encoder/__init__.py index 7b03354..37cd6b6 100644 --- a/timeside/encoder/__init__.py +++ b/timeside/encoder/__init__.py @@ -6,3 +6,4 @@ from mp3 import Mp3Encoder from flac import FlacEncoder from m4a import AacEncoder from webm import WebMEncoder +from audiosink import AudioSink \ No newline at end of file diff --git a/timeside/encoder/audiosink.py b/timeside/encoder/audiosink.py new file mode 100644 index 0000000..f60d128 --- /dev/null +++ b/timeside/encoder/audiosink.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2007-2014 Guillaume Pellerin +# Copyright (c) 2013-2014 Thomas Fillon + +# This file is part of TimeSide. + +# TimeSide 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 2 of the License, or +# (at your option) any later version. + +# TimeSide 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 TimeSide. If not, see . + +# Author: Thomas Fillon + +from timeside.core import implements, interfacedoc +from timeside.encoder.core import GstEncoder +from timeside.api import IEncoder +from timeside.tools import * + + +class AudioSink(GstEncoder): + """ + gstreamer-based Audio Sink + + This encoder plays the decoded audio stream to the sound card + + + >>> import timeside + >>> wavfile = 'https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav' + >>> d = timeside.decoder.FileDecoder(wavfile) + >>> e = timeside.encoder.AudioSink() + >>> (d|e).run() # doctest: +SKIP + """ + + implements(IEncoder) + + def __init__(self, output_sink='autoaudiosink'): + """ + """ + super(GstEncoder, self).__init__() + self.streaming = False + + self.output_sink = output_sink + + import threading + self.end_cond = threading.Condition(threading.Lock()) + + self.eod = False + self.metadata = None + self.num_samples = 0 + + @interfacedoc + def setup(self, channels=None, samplerate=None, blocksize=None, + totalframes=None): + super(AudioSink, self).setup(channels, samplerate, blocksize, + totalframes) + + self.pipe = ''' appsrc name=src ! audioconvert + ! %s ''' % self.output_sink + + self.start_pipeline(channels, samplerate) + + @staticmethod + @interfacedoc + def id(): + return "gst_audio_sink_enc" + + @staticmethod + @interfacedoc + def description(): + return "GStreamer based audio sink encoder" + + @staticmethod + @interfacedoc + def format(): + return "" + + @staticmethod + @interfacedoc + def file_extension(): + return "" + + @staticmethod + @interfacedoc + def mime_type(): + return 'audio/x-raw' + + @interfacedoc + def set_metadata(self, metadata): + self.metadata = metadata + + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file