Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dfpwm = require("cc.audio.dfpwm")
- local speaker = peripheral.find("speaker")
- print("Please enter the full URL of the .dfpwm file:")
- local input = read()
- print("Do you want to be in repeat mode? Y/N")
- local repeatMode = false
- while true do
- local inputYN = read()
- if inputYN == "Y" or inputYN == "y" then
- repeatMode = true
- break
- elseif inputYN == "N" or inputYN == "n" then
- break
- else
- print("Please type Y or N")
- end
- end
- repeat
- local response = http.get(input)
- if not response then
- print("Failed to download audio from URL.")
- break
- end
- local decoder = dfpwm.make_decoder()
- while true do
- local chunk = response.read(16 * 1024)
- if not chunk then break end
- local buffer = decoder(chunk)
- while not speaker.playAudio(buffer) do
- os.pullEvent("speaker_audio_empty")
- end
- end
- response.close()
- until not repeatMode
Add Comment
Please, Sign In to add comment