forked from hkc/cc-stuff
1
0
Fork 0

Raw audio streaming

This commit is contained in:
Casey 2023-10-05 02:06:32 +03:00
parent 842a8c4250
commit e61fa4023b
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 41 additions and 0 deletions

41
stream.lua Normal file
View File

@ -0,0 +1,41 @@
local args = { ... }
local buffer_size = 8192
if not http then
print("no http, check config")
return
end
local speaker = peripheral.find("speaker")
if not speaker then
print("no speaker")
return
end
local req, err = http.get(args[1], {}, true)
if not req then
print("failed to perform HTTP request")
print(err)
return
end
local buffer = { }
for i = 1, buffer_size do
buffer[i] = 0
end
while true do
local chunk = req.read(buffer_size)
if not chunk then
break
end
buffer = {}
for i = 1, #chunk do
buffer[i] = string.byte(chunk, i) - 128
end
while not speaker.playAudio(buffer) do
os.pullEvent("speaker_audio_empty")
end
end