0

I am a beginner trying to find a way to stream audio on a local server. I have a Python script that creates some binary data from a robot's microphone, and I want to send this data to be displayed on a local Go server I created.

I read somewhere that web sockets could be a solution. But what's the simplest way to upload the audio buffers from the Python script? And how would I retrieve this raw binary data so that it can be streamed from the web app?

Many many thanks.

stucklen
  • 33
  • 5

1 Answers1

0

There is no single "Best" way. If the protocol has to go over ports 80/443 on the open internet, you could use web-sockets. You could also POST base64 encoded chunks of data from python back to your server.

If the robot and server are on the same network, you could send UDP packets from the robot to your server. (Usually a missing packet or two on audio is not a problem). Even if you have a web based Go server, you can still fire off a go routine to listen on UDP for incoming packets.

If you could be more specific, maybe I or someone else could give a better answer?

ipaul
  • 374
  • 1
  • 10
  • Ah yes the robot and server are on the same network, here's my Go script: [link](https://play.golang.org/p/l_1E-TYSbB) and my python script is basically the answer to this Q [link](https://stackoverflow.com/questions/24243757/nao-robot-remote-audio-problems). So you're saying I need to create UDP packets in my Python script out of the binary data (saved as a .raw) and listen for them in my Go script. Do I convert the data into HEX? How would I then convert this data into a .WAV or some other playable music format? Thanks. – stucklen Jul 11 '17 at 09:18
  • Normally audio is 8-bit PCM. Numpy looks like it's taking the data an translating it to numbers (they should be between 0 and 255) with one column for each channel. You should be able to base64 1000 bytes at a time (why 1000? because ethernet is 1500 bytes by default). Encode that as base64, which should be about 1300 bytes. Send that as a UDP packet to your Go server, then maybe something like https://github.com/cryptix/wav to re-encode that as a WAV file. Hopefully you can just write that WAV file to your mixer or audio device. But I've never tried that last part. – ipaul Jul 11 '17 at 14:40
  • Thanks but still having difficulties.Here's the processRemote method of my Python code [link](https://trinket.io/python/ca15d63ae6) I managed to send test data (PACKETDATA) over UDP and managed to get Go to receive it. However my skill level is beginner and I am unsure what exactly I need to be sending. I have a variable called 'aSoundData' which could be the audio but when I print it, it shows numbers beyond 255, so what kind of data could this be and how do I convert it to hex? It looks like this: [[ 408 -283 -962 ..., 1546 1784 1946] (there are 3 rows like this) – stucklen Jul 11 '17 at 15:15
  • It looks like naoqi does not send data as PCM, but something related to the Linux ALSA sound driver. It's using a 16 bit audio signal. (I suspect it's actually intended to be unsigned). I'm afraid I don't know much about that specific sound protocol. You could still encode it as base64 and ship 500 samples at a time across the network. Then decode it and send it to your sound device and see what happens. If it's ALSA encoded something and you are sending it to an ALSA device - maybe it just works? – ipaul Jul 11 '17 at 15:36