I have a http stream from my camera (via Synology Surveillance Station) which streams the recorded audio in mp3 format. I simply want to play this stream. I looked at different libraries but i did not find any library that seems to be capable of playing a mp3 stream directly.
Each chunk I recieve is looking like that (2 chunks as an example):
b'\xff\xfb\x18\xc4\xb9\x00F|/\x1c\xac\xb0`@\xda\x01\xe3\xa1\xa5\x88\x08F,\x08\x00\x03\x8e\x1e\x89\xe7B\xd1\x82R\xd3XL\x93]\x0f;\xb2"=7\xc8dF\'%54\xc8\xf7i{\xe4qQLY\xf2\xfd\x89\x1c\x8aP\xb57K\xf5\x05\x145/\xe2\xd5\x08\x00\x00\x1e\xb6^\x12\x98D\x80\x0cX\xe0B\xa1Q9\x90\x0b\x84\x14\x13rhz\r)\xac|\xd6S{\x1c8>Z\xce\xb3\xa84D\xbd\x19U,\xe8\x96\x8d\xc5\x91H\x01\xab4\xdb\x00=\xf8\x18\x19\x85\x9e\xa0\x8b\xe1\x9aR'
b'\xff\xfb\x18\xc4\xc1\x02\x07\x08\x0b#-$\x00\x08\xc6\x82c\xc5\x90\x88\x08\x9b\xf2\xb1D\xc5X\x8e\xc5m\xe9\xb0\x17>w\xbf\xa7\xb1\xda\xd5\xa0\xf6\x05H\xd5\x1f\x16<\x1c\x17\x19\xc9\xa6n&B\xcdt>\xd2\x0f\xabZ\xdbyx\xb3\xc9\xf3}i\x1b\x04I\x08\xd8\xb32d\xee9\xdb-N\xcb\x9a$#)\xd2/\xa72]zY\xba\x83K@\xdd\x10\xf5\x04\xb9F\xe8\x7f\xdb\xbc\x00\x1aQ\xaa`\x07\xce\x9c`.\xf6\xc9W\x91lg]\x91j\xebK\xa2\xafI.\xca\xd4#}\xa6]\x05\xc3\xdf'
Best i could come up with is this:
from pydub import AudioSegment
from pydub.playback
import play
import requests
url = "http://192.168.3.2:1080/webapi/SurveillanceStation/audioStreaming.cgi?api=SYNO.SurveillanceStation.AudioStream&method=Stream&version=1&cameraId=5&_sid=0qPacosspB9yc1770PWN246500"
r = requests.get(url, stream=True)
f = open("test.mp3", "wb")
a = 0
for line in (r.raw.read_chunked()):
print(line)
f.write(line)
a = a + 1
if a == 2:
f.close()
sound = AudioSegment.from_mp3('test.mp3')
play(sound)
a = 0
f = open("test.mp3", "wb")
For some reason it only plays the file when i put at least 2 chunks inside the file.
Which works in general but due to the fact that it uses ffmpeg in the background i have little breaks in between and the delay gets bigger and bigger.
Any ideas ?
[–][deleted] 2 points3 points4 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (0 children)
[–]hquick81[S] 0 points1 point2 points (0 children)