Linux play sound console

Play a WAV through /dev/console

It’s sounding like you might want to play a sound file located on one system remotely on another system, is this the case?

2 Answers 2

TL; DR

No, it’s not possible. Use aplay or mplayer .

Why not?

There are two problems with your idea. The first is that writing to /dev/console results in the written characters showing up in the system console, which is commonly used for showing error notifications to the user (I believe), and not for playing sounds. If you somehow got sound from writing to it, I would guess it is due to the 1/256 chance of every character being , which should make a short beep.

The second problem is that a .wav is not a raw, unambiguous audio stream, even if it is less complex and (generally) not compressed like many other formats. In fact (iirc) there can never be such a thing as a raw, unambiguous audio stream. You will always (at the very least) need a header specifying sample resolution and rate in order to do anything useful with the data. I would be very surprised if it was decided that one of the responsibilities of the Linux kernel was to decode various audio formats. It is typically a thing best done by a program in userspace.

Digression:

The Windows 9x line (at least part of it) did image decoding in the kernel for icons. That turned out to be a less-than-stellar idea, and caused many, many bluescreens.

Proposed solution

If you wanted to play your wav from the command line, there are a range of programs that will decode the file for you and communicate it to the kernel, generally using the ALSA interface. I suggest aplay, which is available on most systems and is rather simplistic, or mplayer which is also widely distributed, but with far larger complexity. If your system supports sound, chances are at least one of those are installed.

it should be possible but wether you’d agree to the quality produced is another story.

first of all a wav is pulse code modulated (pcm), the pc speaker is pretty much an on-or-off story so there are 2 options. analyze the frequency the wav aims to archieve (gonna be hard if there are multiple frequencies at once) then make the speaker reproduce that frequency, or live with the fact that it can only be ‘on’ or ‘off’ and just ‘turn it on or off’ if the data in the wav reaches a certain pre-set volume/pcm threshold.

Читайте также:  Linux switch to bash

also the wav would have a much higher samplerate than the speaker hardware probably can handle (not sure on that, but not being able to set other amplitudes than just ‘as much voltage as the thing can handle’ or ‘zero’ with nothing in between is the bigger problem here.

now. the things you want to look into for method 1 is ioctl(x,KIOCSOUND,1193180/desired-freq-in-hz); with 0 obviously being off. KDMKTONE ioctl on an fd on /dev/console seems to be supposed to produce specified tones for a period specified in jiffies.

but if you want to do it properly i’d pick up the datasheet of the chip the speaker is connected to and just address the thing directly without even bothering with /dev/console or any of the linux stuff. so you can indeed, just turn on the voltage, or turn it off. which would give a pcm modulated sound. just without any amplitude variation between ‘loud’ and ‘nothing’.

probably all methods sound like crap anyway. but analyzing the frequency first and then playing back a frequency won’t work for music which usually contains multiple frequencies at the same time.

the whole ioctl KIOCSOUND/KDMKTONE seem to rely on the clocktick settings in the kernel, as well as the being present of a /dev/console and a file descriptor to that being open as well. they don’t seem to ‘just address the i/o pin of the chip the pc beeper is connected to’.

programmable interrupt timer (PIT) intel 8259 i/o port $0042 r/w PIT counter 2, cassette & speaker (XT, AT, PS/2)

basically the usual approach would be to program it with a desired frequency and then it would produce beeps but what you’d want is just ‘on’ or ‘off’ so basically 0hz or very low hz, then reprogram the PIT when the data from the wav goes from ‘1’ to 0 to turn it off again. and so on. handling the sample rate of the wav file is up to software like anything else. (take the average or just skip samples if it’s too high — it’s analog anyway, and you can only produce digital output 😉

Источник

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.

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.

Читайте также:  Основные командные оболочки linux

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.

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.

Читайте также:  Astra linux узнать версию debian

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.

Источник

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.

Источник

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