Python play sound from a buffer

Viewed 1688

I am trying to make simple music streaming app using socket such that the client requests for a song and the server reads the song from the file and sends it part by part to the client to play. I want a way to put the parts into a buffer so that I can play it in continuation. I am using sounddevice library to play the sound. The problem is if I play the parts one after other, they sound broken. This is my code:

import socket
import soundfile as sf
import sounddevice as sd

data, samplerate = sf.read('audio.wav')

sd.play(data[:100000], samplerate)
sd.wait()
sd.play(data[100000:200000], samplerate)
sd.wait()

What is the proper way to do this?

1 Answers
Related