Linux play wav file

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

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)

Читайте также:  Devops linux или windows

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.

Источник

How to Listen to WAV Files on Ubuntu

There are a number of available media file types all over the internet, each of them having their own features and disadvantages. Thanks to the community that powers the Linux platform, there are a number of available apps that are able to play the majority of them for you.

What is WAV?

WAV (Waveform Audio File Format) is an audio file format. WAV is an IBM and Microsoft standard file format for storing an audio bitstream on the PC platform. There are a lot of available unpopular file formats and WAV is one of them.

Using WAV files hold a few disadvantages. For example, WAV file format has a size limitation – up to 4GB. Some programs even lower the limit – up to 2GB. Uncompressed WAV files also tend to be larger, making them not suitable for sharing over the internet. However, for retaining the sound quality, WAV is very powerful. That’s why it’s only used when disk space isn’t a bottleneck.

Читайте также:  Tracker extract linux что это

However, there are a number of media players you can use to play a WAV file.

Playing WAV file

For playing a WAV file, there are a number of available players. Check out the best media players for Ubuntu. Almost all the media players are available for other Linux distros as well. WAV, despite not being used as widely as MP3 or others, all the players in the list supports the file format. You won’t have any trouble listening to WAV files.

In the following demo, I’ll be using Rhythmbox – one of the most popular music players for Linux distros. Start Rhythmbox –

Now, go to File >> Add Music. You can also use the keyboard shortcut “Ctrl + O”.

Search for the WAV music file you need to listen to.

The music is there! Select the music and click the “Play” button.

Voila! Enjoy your favorite music!

Источник

Play MP3 or WAV file via the Linux command line

Solution 1: If you want to use the App set as preferred, from the directory containing the MP3 file, use : From : If you know the application you want the MP3 file to be opened with, for example, : or VLC media player: Solution 2: means «change directory». You can install it in Ubuntu with: Solution 2: The command from the package will play any file format supported by using the default audio device, e.g 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 .

Play MP3 or WAV file via the Linux command line

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 

Links: (Wikipedia) (aplay man page)

(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.

Читайте также:  Создать свой iso образ linux

Batch convert mp3 files to wav using sox, It sounds like you’re running into a problem with spaces in the filename. If you have a file named «My Greatest Hits.mp3», your command will

Play MP3 or WAV file via the Linux command line (10 Solutions!!)

Convert mp3 file to wav? using the command line?

Using ffmpeg — installed by default
ffmpeg -i input.mp3 output.wav 
Alternative — mpg123
sudo apt-get install mpg123 
mpg123 -w output.wav input.mp3 

Playing Audio Files From the Linux Command Line, Learn to play audio files from the Linux command line. MP3, Ogg Vorbis, Musepack, MPEG-4/AAC, FLAC, ALAC, WavPack, Wav, and WMA.

Play sound in someone else’s session from command line

make sure the target computer is on, or you are able wake it from the LAN, log in via SSH, and run the command. You might have to scp those executables necessary to invoke the command.

Or, show him how laptops have sleep settings.

Log in to his computer by ssh. In his computer, do the following commands.

sudo apt-get update sudo apt-get install festival echo "Wake up, anvil brain. Turn off the computer. Now!" | festival --tts 

Read audio file — MATLAB audioread, load handel.mat filename = ‘handel.flac’; audiowrite(filename,y,Fs);. Read only the first 2 seconds and specify the data and

Which command should I use to open an MP3 file?

If you want to use the App set as preferred, from the directory containing the MP3 file, use xdg-open :

xdg-open - opens a file or URL in the user's preferred application 

If you know the application you want the MP3 file to be opened with, for example, rhythmbox :

cd means «change directory». A file is not a directory so a cd will not work on your mp3. To open a `.mp3 you need to start a music or video player. The method @heemayl uses will open the player you have set as the default.

If you want you can also use aplay . The command

will play the mp3 from command line and stop when it is done playing. «aplay» is probably the lightest music player around since it does not have a GUI (and can also work on a server >:-D )

If you want to run an MP3 file with a particular application, then run it like:

 application_name audio_file_name 

For example, if you want to run in the MPlayer application then install it using:

 sudo apt-get install mplayer 

Then run the audio file using the command:

 sudo apt-get install mpg123 mpg123 abcd.mp3 
 sudo apt-get install sox play abcd.mp3 
sudo apt-get install vlc vlc abcd.mp3 

How can I play a sound from the command line in macOS?, There is a built-in tool: afplay . The man page does not document all of its options, which can be found via afplay -h :

Источник

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