Ali
Ali

Reputation: 67

play mp3 sound buffers on linux

I want to be able to play an mp3 audio sound buffer on Linux which I am receiving on a specific port. This a continuous live stream. I have looked at pulseaudio, portaudio, mpg123 amongst many others but can't seem to know what to do.

The mp3 sound is received from another computer on network where it is converted using naudio and lame. If I receive the sound on a windows pc i can simply play it using naudio provided dll in C#. But I am not sure of how to get around it in Linux.

Any suggestions will be greatly appreciated.

Thanks in advance,

Upvotes: 1

Views: 1881

Answers (2)

Phlogisto
Phlogisto

Reputation: 1016

You can use mpg321 with nc (netcat) directly.

  • Send your stream to a specific port on a specific host: nc 192.168.1.55 4455 <example.mp3
  • Listen to a port with nc and redirect the stream to mpg321 that plays the stream directly: nc -l 4455 | mpg321 -

Upvotes: 1

user500944
user500944

Reputation:

Have you looked at madplay?

It can read MP3 data from standard input. You may redirect the data you read from the socket to madplay's standard input with a simple program, or even with a shell command:

netcat <hostname> <portname> | madplay - -o wave:- | aplay

The above will work if you're using alsa on the linux box.

To be more precise, on my machine I'm able to do the following:

  • Stream an mp3 file through a TCP socket using netcat:

    cat ~/Music/Linkin\ Park/06\ Demos\,\ Unreleased\ \&\ Other/1997\ -\ Xero/04\ -\ Stick\ N\ Move.mp3 | netcat -l localhost -p 8899

  • Connect to the port and read the MP3 data using netcat and route the stream to madplay:

    netcat localhost 8899 | madplay - -o wave:- | aplay

Upvotes: 2

Related Questions