ThatGravyBoat

Untitled

Jan 31st, 2022 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. peripheral.find("modem", rednet.open)
  2. local dfpwm = require("cc.audio.dfpwm")
  3. local speaker = peripheral.find("speaker")
  4.  
  5. local decoder = dfpwm.make_decoder()
  6.  
  7. string.startswith = function(self, str)
  8. return self:find('^' .. str) ~= nil
  9. end
  10.  
  11. while true do
  12. id, message = rednet.receive()
  13.  
  14. if message:startswith("play_song") then
  15.  
  16. for chunk in io.lines(string.sub(message, 10, string.len(message)) .. ".dfpwm", 16 * 1024) do
  17. local buffer = decoder(chunk)
  18.  
  19. while not speaker.playAudio(buffer) do
  20. os.pullEvent("speaker_audio_empty")
  21. end
  22.  
  23. end
  24. end
  25. end
  26.  
Add Comment
Please, Sign In to add comment