I'm wondering if there's a command I can install to play an audio file from the terminal, or if I can do it with Python or a different code? I just want to type a command, have it play a sound until the sound is finished, then return to the prompt. I don't want a GUI.
Asked
Active
Viewed 7.5k times
38
-
Looking at the answers under https://askubuntu.com/questions/44443/command-line-audio-players this doesn't seem like a duplicate. The `sox` solution under here is not present under the linked question, and that is the answer: here, but not there. – cipricus Nov 24 '19 at 17:26
-
1nvlc doesn't just return to a prompt (although the hotkeys for volume are handier than my next suggestion). mpv --no-audio-display will play in the terminal and return to a prompt when it's done playing. If you specify a folder instead of a file, it will play all the songs in the folder. – oksage Dec 13 '20 at 07:08
-
Why not post that as an answer? – cheesits456 Dec 19 '20 at 01:24
2 Answers
55
Yes you can do it with many commandline tools like mpg123, aplay , cvlc and mplayer, but I suggest the play command. To install it:
sudo apt install sox
And for playing special formats like mp3 you must install its libraries:
sudo apt install libsox-fmt-mp3
And to use it:
play music.mp3
If you want to use it with full libraries, you must install libsox-fmt-all package:
sudo apt install libsox-fmt-all
Mike Pierce
- 282
- 3
- 17
Ali Razmdideh
- 5,710
- 2
- 34
- 51
-
When I run `play` on a short bell sound, it tends to only play part of the sound, for some reason. Didn't occur when I used `mpg123`. – Andrew Apr 18 '23 at 23:52
-
1
You can do the same with another tool called mpg123, to install it,
sudo apt install mpg123
and then use it by,
mpg123 file.mp3
Pavel Sayekat
- 527
- 3
- 9
- 23