Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dfpwm = require("cc.audio.dfpwm")
- local speaker = peripheral.find("speaker")
- --[[ chinese tips:
- step:
- 1 让设备连上一个 扬声器
- 2 让设备上有此程序
- 3 运行此程序,需要一个 dfpwm 格式文件直链
- 4 听歌
- dfpwm : 一种音频格式编码可以参考这里去做 https://tweaked.cc/library/cc.audio.dfpwm.html 或者直接用现成的codec工具
- 文件直链: 可以使用网盘之类的来获得,比如 cowtransfer
- codec 工具: 网页: https://music.madefor.cc/
- java: https://github.com/gamax92/LionRay/
- 跨平台: ffmpeg
- 当然理想状态就是自己挂个http服务器 然后直接通过http服务来直接一步到位 mp3 解码 pcm, 然后传到设备上, 不过速度有待验证
- ]]--
- if(speaker == nil) then
- print("you should attach or insert a speaker in this device")
- elseif (arg[1] == nil) then
- print("you need to input the URL behind this program")
- end
- local decoder = dfpwm.make_decoder()
- local data = http.get(arg[1], nil , true)
- while 1 do
- local cksize = 16*1024
- local chunk = data.read(cksize)
- local decoded = decoder(chunk)
- while not speaker.playAudio(decoded) do
- os.pullEvent("speaker_audio_empty")
- end
- if(string.len(chunk) < cksize ) then
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement