Node.js bindings to libgroove - generic music player backend library.
Live discussion in #libgroove
on freenode.
Here are the main interfaces. See API Documentation below for more details.
- GrooveFile - represents an open audio file.
- GroovePlaylist - put files in the playlist, and the playlist decodes the files and fills up the attached sinks.
- GroovePlayer - attach this sink to a playlist to play the decoded audio over the system's speakers.
- GrooveEncoder - attach this sink to a playlist to obtain encoded audio buffers, such as an mp3 stream.
- GrooveLoudnessDetector - attach this sink to a playlist to compute how loud files sound to the human ear, along with the "true peak" value. You can use this to implement ReplayGain.
- GrooveFingerprinter - attach this sink to a playlist to compute an acoustid fingerprint. This can be used to look up a file by its audio content and figure out which tags should be applied.
- GrooveWaveformBuilder - attach this sink to a playlist to compute a JSON representation of an audio file. This can be used to display a visualization of the audio file.
- Install libgroove to your system. libgroove is a set of 4 libraries; node-groove depends on all of them. So for example on ubuntu, make sure to install libgroove-dev, libgrooveplayer-dev, libgrooveloudness-dev, and libgroovefingerprinter-dev.
npm install --save groove
- node-groove >=3.0.0 depends on libgroove >=5.0.0
- node-groove >=2.4.0 <3.0.0 depends on libgroove >=4.3.0 <5.0.0
- node-groove 2.3.4 depends on libgroove <4.3.0
See CHANGELOG.md for release notes and upgrade guide.
var groove = require('groove');
groove.open("danse-macabre.ogg", function(err, file) {
if (err) throw err;
console.log(file.metadata());
console.log("duration:", file.duration());
file.close(function(err) {
if (err) throw err;
});
});
- example/metadata.js - read or update metadata in a media file
- example/playlist.js - play several files in a row and then exit
- example/replaygain.js - compute replaygain values for media files
- example/transcode.js - convert and splice several files together
- example/fingerprint.js - create an acoustid fingerprint for media files
- example/devices.js - list the playback devices on the system
- example/waveform.js - calculate a waveformjs compatible representation of a media file
level
can be:
groove.LOG_QUIET
groove.LOG_ERROR
groove.LOG_WARNING
groove.LOG_INFO
Converts a loudness value which is in LUFS to the ReplayGain-suggested dB adjustment.
Converts dB format volume adjustment to a floating point gain format.
Returns an object with these properties:
major
minor
patch
callback(err, file)
callback(err)
In seconds.
A comma-separated list of short names for the format.
Flags:
groove.TAG_MATCH_CASE
groove.TAG_DONT_OVERWRITE
groove.TAG_APPEND
See getMetadata
for flags.
Pass null
for value
to delete a key.
This returns an object populated with all the metadata.
Updating the object does nothing. Use setMetadata
to
update metadata and then save
to write changes to disk.
Boolean whether save
will do anything.
The string that was passed to groove.open
If you know for sure the actual duration of the file, call this function
to set the actual duration in seconds of the file. GrooveWaveformBuilder
will use this value instead of file.duration()
.
This must only be called when no GroovePlaylistItem
references to this file.
callback(err)
A playlist managers keeping an audio buffer full. To send the buffer
to your speakers, use playlist.createPlayer()
.
Note: you probably only want one playlist. In node-groove, a playlist is a low-level audio processing concept, not to be confused with user-facing playlists where users might add, remove, and re-order songs.
When finished with your playlist you must destroy it.
Returns a read-only array of playlist items.
Use playlist.insert
and playlist.remove
to modify.
[playlistItem1, playlistItem2, ...]
Seek to playlistItem
, position
seconds into the song.
Creates a new playlist item with file and puts it in the playlist before
nextPlaylistItem
. If nextPlaylistItem
is null
, appends the new
item to the playlist.
gain
is a float format volume adjustment that applies only to this item.
defaults to 1.0
peak
is float format, see item.peak
.
defaults to 1.0
Returns the newly added playlist item.
Once you add a file to the playlist, you must not file.close()
it until
you first remove it from the playlist.
Remove playlistItem
from the playlist.
Note that you are responsible for calling file.close()
on every file
that you open with groove.open
. playlist.remove
will not close files.
Returns {item, pos}
where item
is the playlist item currently being
decoded and pos
is how many seconds into the song the decode head is.
Note that typically you are more interested in the position of the play head,
not the decode head. Example methods which return the play head are
player.position()
and encoder.position()
.
Returns true
or false
.
Remove all playlist items.
How many items are on the playlist.
Between 0.0 and 1.0. You probably want to leave this at 1.0, since using replaygain will typically lower your volume a significant amount.
gain
is a float that affects the volume of the specified playlist item only.
To convert from dB to float, use exp(log(10) * 0.05 * dBValue).
See item.peak
mode
can be:
-
groove.EVERY_SINK_FULL
The playlist will decode audio if any sinks are not full. If any sinks do not drain fast enough the data will buffer up in the playlist.
-
groove.ANY_SINK_FULL
This is the default behavior. With this behavior, the playlist will stop decoding audio when any attached sink is full, and then resume decoding audio every sink is not full.
Defaults to groove.EVERY_SINK_FULL
.
These are not instantiated directly; instead they are returned from
playlist.items()
.
A GroovePlaylistItem
is merely a pointer into a GroovePlaylist
. If you
remove a playlist item from a playlist, any playlist item references you
have lying around become dangling pointers.
Read-only.
A volume adjustment in float format to apply to the file when it plays.
This is typically used for loudness compensation, for example ReplayGain.
To convert from dB to float, use groove.dBToFloat
Read-only. Use playlist.setItemGain
to modify.
The sample peak of this playlist item is assumed to be 1.0 in float format. If you know for certain that the peak is less than 1.0, you may set this value which may allow the volume adjustment to use a pure amplifier rather than a compressor. This results in slightly better audio quality.
Read-only. Use playlist.setItemPeak
to modify.
Every time you obtain a playlist item from groove, you will get a fresh
JavaScript object, but it might point to the same underlying libgroove pointer
as another. The id
field is a way to check if two playlist items reference
the same one.
Read-only.
Before you can call this function, you must call
groove.connectSoundBackend()
.
Returns an object like this:
{
list: [
{
name: "User-Friendly Device Name",
id: "unique device ID that persists across plugs and unplugs",
isRaw: false, // true if this device would claim exclusive access
probeError: 3, // non zero if scanning this device did not work
},
//...
],
defaultIndex: 0,
}
backend
is optional. If left blank the best backend is automatically
selected. Otherwise it can be one of these:
groove.BACKEND_JACK
groove.BACKEND_PULSEAUDIO
groove.BACKEND_ALSA
groove.BACKEND_COREAUDIO
groove.BACKEND_WASAPI
groove.BACKEND_DUMMY
Creates a GroovePlayer instance which you can then configure by setting properties.
Before calling attach()
, set this to one of the devices
returned from groove.getDevices()
.
Sends audio to sound device.
callback(err)
callback(err)
Returns {item, pos}
where item
is the playlist item currently being
played and pos
is how many seconds into the song the play head is.
Fires when the item that is now playing changes. It can be null
.
handler()
Fires when a buffer underrun occurs. Ideally you'll never see this.
handler()
Fires when you have set useExactAudioFormat
to true
and the audio device
has been closed and re-opened to match incoming audio data.
handler()
select encoding quality by choosing a target bit rate
optional - help libgroove guess which format to use.
avconv -formats
to get a list of possibilities.
optional - help libgroove guess which codec to use.
avconv-codecs
to get a list of possibilities.
optional - provide an example filename to help libgroove guess which format/codec to use.
optional - provide a mime type string to help libgrooove guess which format/codec to use.
The desired audio format settings with which to encode.
groove.createEncoder()
defaults these to 44100 Hz,
signed 16-bit int, stereo.
These are preferences; if a setting cannot be used, a substitute will
be used instead. In this case, actualAudioFormat will be updated to reflect
the substituted values.
Properties:
sampleRate
channelLayout
- array of channel idssampleFormat
groove sets this to the actual format you get when you attach the encoder. Ideally will be the same as targetAudioFormat but might not be.
Properties:
sampleRate
channelLayout
- array of channel idssampleFormat
How big the sink buffer should be, in sample frames.
createEncoder
defaults this to 8192
How big the encoded audio buffer should be, in bytes.
createEncoder
defaults this to 16384
callback(err)
callback(err)
Returns null
if no buffer available, or an object with these properties:
buffer
- a nodeBuffer
instance which is the encoded data for this chunk this can benull
in which case this buffer is actually the end of playlist sentinel.item
- the GroovePlaylistItem of which this buffer is encoded data forpos
- position in seconds that this buffer represents in into the item
handler()
Emitted when there is a buffer available to get. You still need to get the
buffer with getBuffer()
.
Returns {item, pos}
where item
is the playlist item currently being
encoded and pos
is how many seconds into the song the encode head is.
returns a GrooveLoudnessDetector
Set this to determine how far ahead into the playlist to look.
Set to true
to only compute track loudness. This is faster and requires less
memory than computing both.
callback(err)
callback(err)
Returns null
if no info available, or an object with these properties:
loudness
- loudness in LUFSpeak
- sample peak in float format of the fileduration
- duration in seconds of the trackitem
- the GroovePlaylistItem that this applies to, ornull
if it applies to the entire album.
Returns {item, pos}
where item
is the playlist item currently being
detected and pos
is how many seconds into the song the detect head is.
handler()
Emitted when there is info available to get. You still need to get the info
with getInfo()
.
returns a GrooveFingerprinter
Given an Array of integers which is the raw fingerprint, encode it into a string which can be submitted to acoustid.org.
Given the fingerprint string, returns a list of integers which is the raw fingerprint data.
Set this to determine how far ahead into the playlist to look.
callback(err)
callback(err)
Returns null
if no info available, or an object with these properties:
fingerprint
- integer array which is the raw fingerprintduration
- duration in seconds of the trackitem
- the GroovePlaylistItem that this applies to, ornull
if it applies to the entire album.
Returns {item, pos}
where item
is the playlist item currently being
fingerprinted and pos
is how many seconds into the song the printer head is.
handler()
Emitted when there is info available to get. You still need to get the info
with getInfo()
.
returns a GrooveWaveformBuilder
How many frames wide the waveform data will be. Defaults to 1920.
If you have a song with 100 frames and widthInFrames
is 50, then each
waveform data frame will correspond to 2 frames of the original song.
Set this to determine how far ahead into the playlist to look.
callback(err)
callback(err)
Returns null
if no info available, or an object with these properties:
buffer
- ABuffer
of the waveform data, one unsigned 8 bit integer perwidthInFrames
.expectedDuration
- This is the duration in seconds that was used to create the waveform data. If this is different thanactualDuration
then the data is invalid and must be re-calculated, this time usingfile.overrideDuration()
actualDuration
- This is the correct duration in seconds for the track, known only after waveform calculation is complete.item
- the GroovePlaylistItem that this applies to, ornull
if this info signals the end of playlist.
Returns {item, pos}
where item
is the playlist item currently being
calculated and pos
is how many seconds into the song the waveform head is.
handler()
Emitted when there is info available to get. You still need to get the info
with getInfo()
.