Playing sound in linux

How to play mp3 files from the command line?

I have installed Ubuntu 11.10 server.. so command line only. I need to be able to play audio (.mp3 & .wav) files via the command line! I’ve installed the MPD & Audacious packages. and copied some files to a location specified in the .conf file. But what do I do to acutally play the .mp3 files?? Also, how can I confirm the AUDIO is working correctly?

You want to play it from the ‘server’ speakers or you want to play it across the network? Two very different things.

You could try installing sox, then at the commandline it would be «play thisorthat.mp3» or «play ~/music/thisfolder/thisorthat.mp3»

12 Answers 12

If you already have ffmpeg installed (you should have ffmpeg installed default with ubuntu), try:

or (without text output, window opening and looping):

ffplay -v 0 -nodisp -autoexit example.mp3 

or reading from stdin, piped from a command:

cat example.mp3 | ffplay -v 0 -nodisp -autoexit - 

For wav you can use aplay . For mp3 you can use mpg123 .

Perfect, works great with sudo pip install gTTS (Google Text to Speech/github.com/pndurette/gTTS) then gtts-cli «The good of mankind far outweighs the bad» | mpg123 — .

I usually just do mplayer foo.mp3 to play audio from the command line.

The play command from the sox package will play any file format supported by sox

To install sox open terminal and run:

sudo apt-get install sox libsox-fmt-all 

Use man sox for more information

Not sure if your server will support it, but VLC also has a command line version that can play (with the right packages) MP3 files:

The ‘n’ in front of ‘vlc’ invokes the ncurses interface which is for the command line. This allows you to play multiple files, pause and control the files being played.

And additionally you can use nvlc —random /path/to/your/music/folder to play random songs from a Music folder.

Or use cvlc instead of nvlc , for even minimal interaction.

Источник

The 5 Best Command Line Music Players for Linux

The terminal is usually used to accomplish administrative tasks on a Linux system such as installing packages, configuring services, updating, and upgrading packages to mention a few.

But did you also know you can enjoy playing your favourite audio files straight from the terminal? Yes, you can, thanks to some cool and innovative console-based music players.

Читайте также:  Дайте определение ос linux

In this guide, we shine the spotlight on the best command-line music players for Linux.

1. CMUS – Console Music Player

Written in C programming language, CMUS is a light-weight yet powerful console-based music player designed for Unix/Linux systems. It supports a wide range of audio formats and is quite easy to navigate once you have mastered some basic commands.

Let’s take a look at some of the main features in brief:

CMUS Console Music Player

  • Support for an array of popular music formats including mp3, aac, wave, and flac to mention a few.
  • Output sound in ALSA and JACK format.
  • Ability to organize your music in playlists and create queues for your songs. With CMUS, you can also create your custom music library.
  • Plenty of keyboard shortcuts that you can use to make your user experience fun.
  • Support for gapless playback that lets you play music without interruption.
  • You can find extensions and other handy scripts from CMUS’s wiki.

Install CMUS on Linux

$ sudo apt-get install cmus [On Debian, Ubuntu & Miny] $ sudo dnf install cmus [On CentOS, RHEL & Fedora] $ sudo pacman -S cmus [On Arch Linux & Manjaro]

2. MOC – Music On Console

Short for Music On Console, MOC is a light and easy-to-use command-line music player. MOC allows you to select a directory and play audio files contained in the directory beginning with the first on the list.

Let’s take a look at some of the key features:

Moc - Music On Console

  • Support for gapless playback.
  • Support for audio files such as wav, mp3, mp4, flac, oog, aac and MIDI.
  • User defined-keys or keyboard shortcuts.
  • ALSA, JACK & OSS audio output.
  • A collection of customizable colour themes.

Install MOC on Linux

$ sudo apt-get install moc [On Debian, Ubuntu & Miny] $ sudo dnf install moc [On CentOS, RHEL & Fedora] $ sudo pacman -S moc [On Arch Linux & Manjaro]

3. Musikcube

Musikcube is another free and opensource terminal-based music player that leverages a collection of plugins written in C++ to provide functionality such as data streaming, digital signal processing, output handling and so much more.

Musikcube is a cross-platform music player that can even run on Raspberry Pi. It uses the SQLite database for storing playlist and track metadata. It runs purely on a text-based UI built with ncurses.

Let’s take a look at some of the key features:

Musikcube - Terminal Based Music Player

  • Can deliver an output of 24bit/192k audio with ease.
  • The music player offers both playlists and play queue management.
  • Can act as a streaming audio client on a headless server.
  • Support for libraries with over 100,000 tracks.
  • It provides gapless playback with cross-fading effect along with index tagging.

For installation, head over to the releases page and grab the .deb or .rpm for your version of Linux and install it using the installation guide to get up and running.

4. mpg123 – Audio Player and Decoder

The mpg123 player is a free and opensource fast console-based audio player and decoder written in C language. It is tailored for both Windows & Unix/Linux systems.

Читайте также:  Linux rdp server debian

Let’s take a look at some of the key features:

Mpg123 - Audio Player and Decoder

  • Gapless playback of mp3 audio files.
  • Built-in terminal shortcuts.
  • Supports many platforms ( Windows, Linux, BSD and macOS ).
  • Multiple Audio options.
  • Support a vast variety of audio output including ALSA, JACK and OSS.

Install mpg123 on Linux

$ sudo apt-get install mpg123 [On Debian, Ubuntu & Miny] $ sudo dnf install mpg123 [On CentOS, RHEL & Fedora] $ sudo pacman -S mpg123 [On Arch Linux & Manjaro]

5. Mp3blaster – Audio Player for Console

Mp3blaster has been around since 1997. Sadly it hasn’t been in active development since 2017. Nevertheless, it’s still a decent terminal-based audio player that lets you enjoy your audio tracks. You can find the official repo hosted on GitHub.

Let’s take a look at some of the key features:

Mp3blaster - Audio Player for Linux Console

  • Support for shortcut keys which makes it relatively easy to use.
  • Commendable playlist support.
  • Great sound quality.

Install Mp3blaster on Linux

$ sudo apt-get install mp3blaster [On Debian, Ubuntu & Miny] $ sudo dnf install mp3blaster [On CentOS, RHEL & Fedora] $ sudo pacman -S mp3blaster [On Arch Linux & Manjaro]

That was a round-up of some of the most popular command-line players available for Linux, and even for Windows. Is there any you feel we have left out? Give us a shout.

Источник

Play MP3 or WAV file via the Linux command line

I would like to make an alarm system backed by a Ubuntu (no graphical interface) box, which plays various announcement and alarm audio tracks (.mp3 or .wav) via the command line. For example:

The audio should come from the PC audio jack. I might also wrap it with another socket listener (for example, Ruby Sinatra). How can I do this?

10 Answers 10

mpg123 is a command-line utility which plays mp3 files. You can install it in Ubuntu with:

sudo apt-get install mpg123 

The play command from the sox package will play any file format supported by sox using the default audio device, e.g

$ play something.mp3 $ play something.wav 

You may need to install extra packages to gain support for all formats, for example on Ubuntu 11.04 the MP3 support is not available until you install libsox-fmt-mp3 .

The most standard way to play a WAV file in Linux is using the aplay command, which is part of the ALSA system.

aplay [flags] [filename [filename]] . aplay a.wav 

(Both in Fedora and in Ubuntu/Mint it is part of the alsa-utils package)

This does not require any additional packages to your Linux installation like sox or mplayer or vlc, just the basic ALSA which is a part of any system nowadays.

Thanks for the tip! I added this alias to my shell config: alias beep=»aplay —quiet /usr/share/sounds/pop.wav» . That way I can get a notification when long running commands finish. For example: compile && run && beep

Читайте также:  Чтение log файлов linux

Yes, Jesse! I do exactly the same with compiling (long file conversions, etc). I use sounds from here: «Opilki sounds» (they are under the Creatve Commons license) forgive me this minor advertisement, i’m not related to the project in any way 🙂

sudo apt-get install vlc vlc-plugin-pulse mozilla-plugin-vlc 

Make sure that you have all repositories open. Also run the following before you install:

VLC has a command-line operation method invoked by cvlc . The next part would be to write a .sh that will call the command. I am no good at writing bash scripts. The end-result would be something like:

cvlc xyz.mp3 cvlc --play-and-exit done.mp3 

cvlc —play-and-exit —no-loop done.mp3 . I need the extra option —no-loop , so that the sound file is not repeated over and over. (vlc 2.2.2, xubuntu 16.04.4)

note that vlc usually depends on qt5 and X on some distribution, but mpg123 depends on only alsa-lib.

You can simply pipe your sound data to the pc speaker device:

On Ubuntu 16.04 (Xenial Xerus), there is no need to install anything. You can play a sound using paplay with is part of the PulseAudio sound server:

I would think this works only if paplay —list-file-formats includes MP3 in the format list, which it does not on my machine (which, admittedly, is not Ubuntu). Does paplay ever really include MP3?

Correct. WAV seems to be on that list but not MP3. You might need to install proprietary codecs. On Ubuntu that would be sudo apt-get install ubuntu-restricted-extras .

MPlayer is another player which can play pretty much any audio/video format from command line. To install it in Ubuntu just execute this command:

sudo apt-get install mplayer 

You can then play the file using this syntax:

FFmpeg is installed on my Ubuntu 19.04 (Disco Dingo)

$ ffplay music.mp3 -nodisp hide spectrum analyzer -nostats hide cursor/file information -hide_banner hide build information Hide all (no output): $ ffplay music.mp3 -nodisp -nostats -hide_banner 

canberra-gtk-play

For simple Bash scripts MPlayer is probably a bit too heavy and too verbose in terms of output. A built-in option is canberra-gtk-play which comes preinstalled on Ubuntu:

canberra-gtk-play --file=/usr/share/sounds/gnome/default/alerts/drip.ogg 

Note: it uses the alerts volume, and you must pass —file= in order to play a file from a path.

It can also play a sound by id which represents the file name without extension of media files under /usr/share/sounds (apparently this only works for sounds that are registered as part of a sound theme):

canberra-gtk-play --id="desktop-login" canberra-gtk-play --id="message" 

gst-launch-1.0/gst-launch-0.10

Another option is using the gstreamer command-line tools which are present on most modern Linux boxes:

gst-launch-1.0 playbin uri=file:///usr/share/sounds/ubuntu/stereo/message.ogg 

To suppress all output redirect it to /dev/null :

gst-launch-1.0 playbin uri=file:///usr/share/sounds/ubuntu/stereo/message.ogg > /dev/null 2>&1 

Both gst-launch-1.0 and gst-launch-0.10 might be present on your system.

Источник

Оцените статью
Adblock
detector