Native Node.js Libshout bindings for libshout 2.4.1 (latest).
Libshout is a C library for streaming audio to icecast or shoutcast-compatible servers. It supports four audio formats and four protocols. It handles the networking and communication to the server, allowing users to focus on programmatic control.
More information: http://icecast.org
To use libshout-js, you must first install the libshout library. Consult your OS documentation on how to install libshout, for example:
yum install libshout apt-get install libshout brew install libshout
Install nodeshout with yarn or npm:
yarn install libshout-js
Use as follows:
// Importconst Libshout =// Create the instance. Specify path to the .so/.dll/.dylib file.// If no path is set, it will attempt to load the standard dll locations.const ls = 'path/to/libshout.so'// Configure the connectionconst ls = '/usr/local/lib/libls'lslslslsls// Set stream metadatals// Some constants are defined for you.ls// ls.setAudioInfo('bitrate', '192')// ls.setAudioInfo('samplerate', '44100')// ls.setAudioInfo('channels', '2')ls
Open the connection.
If connection is successful,
.open() will return string
SHOUT_ERR_SUCCESS, otherwise it will throw an error. After successful connection, you can pipe audio data through the provided
writeStream stream, or manually send data.
const fileStream = 'song.mp3'fileStreamlswriteStream// or,ls
If sending data manually, there are two ways to synchronize it.
.sync() will block the thread until ready.
.getDelay() will return the time in ms you should wait before sending the next chunk.
Icecast only supports track metadata for MP3 streams. Vorbis streams are expected to embed metadata as vorbis comments in the audio stream.
// Create a metadata instanceconst metadata = Libshout// Set the metadata within the object. Supported values are defined in constants.metadata// Then, you must apply the metadata to the server connection object.ls;
The C code is heavily documented in the comments for
bindings.js. Look there for more Libshout specific information.