.. This file is part of TimeSide
- @author: Guillaume Pellerin
+ @author: Guillaume Pellerin, Thomas Fillon
Streaming out encoded audio
============================
>>> from timeside.tools.test_samples import samples
>>> import numpy as np
>>> audio_file = samples['sweep.wav']
->>> decoder = get_processor('file_decoder')
+>>> decoder = get_processor('file_decoder')(audio_file, duration=1)
>>> output = '/tmp/test.mp3'
->>> encoder = get_processor('mp3_encoder')(output, streaming=True)
+>>> encoder = get_processor('mp3_encoder')(output, streaming=True, overwrite=True)
>>> pipe = decoder | encoder
Create a process callback method so that you can retrieve end send the chunks:
>>> def streaming_callback():
->>> for chunk in pipe.stream():
->>> # Do something with chunk
->>> yield chunk
+... for chunk in pipe.stream():
+... # Do something with chunk
+... print chunk.timestamp
Now you can use the callback to stream the audio data outside TimeSide!
+
+>>> streaming_callback() # doctest: +SKIP
+
.. doctest:: test_2
>>> import timeside
+ >>> from timeside.tools.test_samples import samples
>>> from timeside.core import get_processor
- >>> decoder = get_processor('gst-dec')('sweep.wav') # doctest: +SKIP
+ >>> decoder = get_processor('file_decoder')(samples["sweep.wav"])
>>> spectrogram = get_processor('spectrogram_lin')(width=400, height=150)
>>> (decoder | spectrogram).run()
>>> spectrogram.render('graph.png')
.. doctest:: test_3
>>> import timeside
+ >>> from timeside.tools.test_samples import samples
>>> from timeside.core import get_processor
- >>> decoder = get_processor('gst-dec')('sweep.wav') # doctest: +SKIP
+ >>> decoder = get_processor('file_decoder')(samples["sweep.wav"])
>>> levels = get_processor('level')()
>>> encoders = get_processor('mp3_encoder')('sweep.mp3') | get_processor('flac_encoder')('sweep.flac')
>>> (decoder | levels | encoders).run()