nicogb

Untitled

Jul 11th, 2023 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.65 KB | None | 0 0
  1. local aukit = require "aukit"
  2. -- assume we stored the song in "wxp.wav"
  3.  
  4. -- read the data
  5. local file = fs.open("wxp.wav", "rb") -- read binary mode is important.
  6. if not file then
  7.   error("Music file doesn't exist.", 0)
  8. end
  9. local data = file.readAll() -- actually read data
  10. file.close() -- important to close file handles.
  11.  
  12. -- Now, for aukit stuff.
  13. local iterator, length = aukit.stream.wav(data)
  14. aukit.play(
  15.   iterator,
  16.   function(pos)
  17.     -- do something with the current position
  18.     -- Do not infinite loop in this function!
  19.   end,
  20.   1, -- audio volume
  21.   peripheral.find("speaker") -- speakers to play the audio on, in this case all speakers
  22. )
Advertisement
Add Comment
Please, Sign In to add comment