Skip to main content

mod_shell_stream

About

Mod shell stream is a module to allow you to stream audio from an arbitrary shell command. You could use it to read audio from a database, from a soundcard, etc.

Usage

To use it, you call it from the dialplan like this:

<action application="playback" data="shell_stream:///tmp/moh"/>

Now, when this application is triggered, the command /tmp/moh is called with 2 arguments -r <rate> and -c <channelcount>, which in the usual case are 8000 and 1 respectively.

The contents of my sample /tmp/moh script is as follows:

#!/bin/sh

cat /tmp/tt-weasels.wav | sox -t wav - $@ -t raw -

Which cats an audio file into sox on stdin and tells sox to output raw audio at 8000hz, 1 channel to stdout. You could of course replace the cat command with anything that outputs audio and use sox to process it into the requested raw output.

Arguments

You can also pass arguments to the command, by doing something like this:

<action application="playback" data="shell_stream:///tmp/moh /tmp/tt-weasels.wav wav"/>

And the corresponding script becomes:

#!/bin/sh

AUDIO=$1
TYPE=$2
shift 2
cat $AUDIO | sox -t $TYPE - $@ -t raw -

Basically the sky is the limit, if you're willing to write the script or program to do what you need.

See Also