[LINUX] Simple net radio-like

Simple net radio-like

This is a test in which PCM data is sent from the server and played back on the client at hand. It may be used when you want to listen to music on a PC with no capacity (?)

Preparation

The audio file is 〆. Convert to wav with ffmpeg and strip it with sox. For the time being, for CD sound quality.

$ ffmpeg -i hoge.m4a hoge.wav
$ sox hoge.wav -r44100 -c2 -b16 hoge.raw

Create FIFO

I still don't know how to use FIFO well. We will write .raw to this FIFO later.

$ mkfifo queue

server

Use nc to listen for a connection. Send the contents of the FIFO you created earlier (with a little work).

This person will not come back without Ctrl-C. Those who came from the top of this article will not be able to use this terminal here. Launch the next virtual terminal.

$ tail -n99999999 -f queue | cat | base64 | nc -l 50000

Use tail -f to monitor the addition to the FIFO (described later). -n99999999 is a spell to get all the contents of the first time spit out.

The following cat is a relaxing magic. I'm going to imitate the buffer.

Make the data look like 7-bit with base64. The recipient doesn't know if he can receive 8-bit data, so I'm just making it 7-bit.

Listen to port 50000 with nc -l 50000. I'm not sure because I use nc in the atmosphere.

client

Point the server with telnet. Use aplay for audio playback.

$telnet server address 50000 2>/dev/null | sed '1,3d' | base64 -d | aplay -f cd

telnet connects to the server. Discard the error.

sed truncates the log“ Connecting ... ”spitted by telnet. Please change if necessary.

Decode with base64 -d.

Play the audio with aplay. -f cd means CD sound quality. If you are interested in speaker aging, you can hear white noise by doing cat/dev/urandom | aplay -f cd.

Playing a song

First, start the server. Then start the client. To play the song, write (additionally) a .raw file to the created FIFO.

$ cat hoge.raw >> queue &

This operation may not come back soon, so I decided to add & to make it work in the background. If you want to continue adding songs, you can execute as follows.

$ wait; cat fuga.raw >> queue &

This command line will probably return when the previous song has finished playing.


in conclusion

The end.

Recommended Posts

Simple net radio-like