
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
A simple utility to play sounds from Node.js programs, useful for (but not limited to) CLI apps.
It can also be used directly as a terminal command:
npm i -g cli-sound
cli-sound path/to/sound.mp3
# or
npx cli-sound path/to/sound.mp3
It works by executing a locally installed audio program without a graphical interface.
This package is inspired by play-sound, but it goes to greater lengths to ensure good cross-operative-system support, provide volume control, customization, TypeScript types, ESM and CommonJS compatibility, and better reliability overall.
npm install cli-sound
import { Player } from "cli-sound";
const player = new Player();
await player.play("path/to/sound.mp3");
This package will go through a list of programs, find the first one available, and attempt to use it to play the sound. It uses the exec
function from the node:child_process
module internally.
The default list of programs is as follows:
ffplay
- Linux, Windows, macOSmpv
- Linux, Windows, macOSmpg123
- Linux, Windows, macOSmpg321
- Linux, macOSmplayer
- Linux, Windows, macOSafplay
- macOS - untested, volume control not supportedplay
- Linux, macOS (SoX package) - untestedomxplayer
- Linux (specifically Raspberry Pi OS) - untested, volume control not supportedaplay
- Linux (ALSA sound system) - untested, volume control not supportedcmdmp3
- Windows - untested, volume control not supportedcvlc
- Linux, Windows, macOS - untestedpowershell
- Windows - untested, volume control not supportedimport { Player } from "cli-sound";
const player = new Player();
When the player is created, the first available program is found and stored.
The Player
constructor accepts an optional options
object as an argument with the following properties:
commands
- string[]
A list of commands that will be used to play the audio file.
The first executable found will be used. Commands can be specified using one of the following formats:
command
command <arguments>
where arguments must contain %filepath%
and
optionally %volume%
extendCommands
- (defaultCommands: string[]) => string[]
A function that will be called with the built-in commands and should return a list of commands that will be used to play the audio file.
The first executable found will be used. Commands can be specified using one of the following formats:
command
command <arguments>
where arguments must contain %filepath%
and
optionally %volume%
volume
- number
(default: 1
)
A volume value between 0 and 1, where 1 is the loudest and 0 is the quietest. Only supported by some players.
Values higher than 1 are supported by some players.
arguments
- Record<string, string>
Additional arguments to pass to the audio player. Keys are the names of the audio player and values are the arguments.
The passed arguments will be prepended to the rest of the arguments.
argumentValueTransformers
- ArgumentValueTransformersMap
Transformer functions for the values passed to the arguments of each audio player.
The top-level keys are the names of the audio players. The corresponding values are objects that map arguments (by name) to transformer functions.
The transformer functions will be called with the value of the argument and should return the transformed value.
The all
special key can be used instead of the name of an audio player to
apply its transformers to all audio players.
await player.play("path/to/sound.mp3");
The play
method accepts the path to the sound file as a string and returns a promise that resolves when the sound is finished playing. The resolved value is an object containing the stdout
and stderr
from the command's output.
The play
method also accepts an optional options
object as the second argument. It accepts the volume
, arguments
and argumentValueTransformers
properties described above.
There are two points at which an error can occur:
new Player()
): happens if none of the programs are available.player.play()
): happens if the program command fails for some reason, including but not limited to the file not existing or being in the wrong format.If succeeding in playing the sound is not critical, you can wrap the code in a try/catch block to prevent the failure from crashing your app.
[!WARNING] Note that, since the package doesn't have a lot of control over the spawned programs, they may fail silently or behave in unexpected ways.
If you want to obtain the command that will be used to play the sound, you can use the createPlayCommand
method:
console.log(player.createPlayCommand("path/to/sound.mp3"));
It takes the same arguments as the `play`` method, but it doesn't execute the command: it just returns it synchronously instead.
This can be useful for debugging or logging purposes, or if you want to use the command differently.
Install bun and install dependencies with bun i
.
You can run bun run test
to test each of the commands on your machine, and get a report after it is done, along with success/error logs.
Contributions are welcome, especially those that add support for more programs/platforms. Bug fixes and feature additions are also highly appreciated.
cli-sound
was built by Dani Guardiola
FAQs
Play a sound from your CLI app
We found that cli-sound demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.