0

I am new in Python programming and I need your help to advice me.

I want to transfer audio from RPI3 to my PC by writing a python program. I found a good tutorial on audio client/server using udp but I confused about the functionality of UDP of sending audio.

Does anyone can explain how the audio transferred using UDP and where is the functionality of RTP which is using for streaming.

I used this python program for sending audio:

import pyaudio
import socket
from threading import Thread

frames = []

def udpStream():
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)    

while True:
    if len(frames) > 0:
        udp.sendto(frames.pop(0), ('127.0.0.1', 42345))

udp.close()

def record(stream, CHUNK):    
while True:
    frames.append(stream.read(CHUNK))

if __name__ == "__main__":
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100

p = pyaudio.PyAudio()

stream = p.open(format = FORMAT,
                channels = CHANNELS,
                rate = RATE,
                input = True,
                frames_per_buffer = CHUNK,
                )

Tr = Thread(target = record, args = (stream, CHUNK,))
Ts = Thread(target = udpStream)
Tr.setDaemon(True)
Ts.setDaemon(True)
Tr.start()
Ts.start()
Tr.join()
Ts.join()
Gholamali Irani
  • 4,391
  • 6
  • 28
  • 59
inaam
  • 1
  • 1
  • 1
  • you mention its a client / server approach ... fine ... looks like above might be the client side ... so for above to work the server side would need to get launched prior to running above ... if so what is your question ? – Scott Stensland Jan 12 '18 at 18:46
  • My question is: when we send audio as above using UDP, what is the protocol used to do streaming? How to send audio data using UDP? Is a protocol is used implicitly RTP or the audio data is sent as data any text data? also the server program is: – inaam Jan 12 '18 at 19:49
  • have you seen this ... its relevant to streaming audio as well https://stackoverflow.com/questions/13040752/websockets-udp-and-benchmarks – Scott Stensland Jan 12 '18 at 22:23

0 Answers0