1

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,

Ali
  • 67
  • 1
  • 10

2 Answers2

2

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

Community
  • 1
  • 1
  • thanks for the info. I will look into it and let you know if i succeed or need further help. have you ever tried it to work on the stream buffer because i am not transferring the mp3 file rather its just buffered sound data? – Ali Oct 25 '11 at 17:28
  • It doesn't matter that much if you're transferring a stream or a file. From what I know, mp3 data is a bunch of "frames" with headers, and it does not really matter which frame you start the playback from. –  Oct 25 '11 at 17:56
1

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 -
jørgensen
  • 10,149
  • 2
  • 20
  • 27
Phlogisto
  • 976
  • 8
  • 6