1
0
Fork 0
cc-stuff/stream.lua

48 lines
853 B
Lua
Raw Normal View History

2023-10-05 02:06:32 +03:00
local args = { ... }
2023-12-18 18:23:11 +03:00
local dfpwm = require("cc.audio.dfpwm")
2023-10-05 02:06:32 +03:00
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
2023-12-18 18:23:11 +03:00
local decoder = dfpwm.make_decoder()
2023-10-05 02:06:32 +03:00
while true do
local chunk = req.read(buffer_size)
if not chunk then
break
end
2023-12-18 18:23:11 +03:00
--local buffer = {}
--for i = 1, #chunk do
-- buffer[i] = string.byte(chunk, i) - 128
--end
local buffer = decoder.decode(chunk)
2023-10-05 02:06:32 +03:00
while not speaker.playAudio(buffer) do
os.pullEvent("speaker_audio_empty")
end
end