August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
Cookbook Example
How can I...?
Example 12 : Simple TCP based streamer that repeatedly streams (3 times) the same audio file. The reason it's the same file is because it's configured with a playlist that is created: [ shortfile, shortfile, shortfile ]. If this was [ song_one, song_two, song_three ], then this would be a simple streamer that had a playlist of 3 songs played repeatedly. Something that does this is often referred to as a carousel. Components used:SimpleServer, JoinChooserToCarousel, FixedRateControlledReusableFileReader, ForwardIteratingChooser, pipeline
#!/usr/bin/python
from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Chassis.Prefab import JoinChooserToCarousel
from Kamaelia.File.Reading import FixedRateControlledReusableFileReader
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.Util.Graphline import Graphline
from Kamaelia.Util.Chooser import ForwardIteratingChooser
= "/opt/kde3/share/sounds/KDE_Startup_2.ogg"
shortfile
= [ shortfile, shortfile, shortfile ]# [ file_to_stream, file_to_stream2 ]
FILES_TO_STREAM = 800000 # 38000
BITRATE = 512
CHUNKSIZEBYTES = 1500
SERVERPORT
def MultiFileReaderProtocol(filenames, bitrate, chunksizebytes):
def protocolFactory(*argv, **argd):
return JoinChooserToCarousel(
ForwardIteratingChooser(filenames),="bytes",
FixedRateControlledReusableFileReader(readmode=bitrate/8,
rate=chunksizebytes)
chunksize
)return protocolFactory
if __name__ == '__main__':
= MultiFileReaderProtocol( FILES_TO_STREAM, BITRATE, CHUNKSIZEBYTES)
filereader = SimpleServer( protocol = filereader, port = SERVERPORT ).run() server
Source: Examples/example12/SimpleMultiFileStreamer.py