feat: 重构音频系统,移除外部依赖并新增WAV格式支持

- 移除install和update脚本中的aukit/austream下载配置与目标,不再部署辅助脚本
- 替换station_broadcast.lua的aukit库为CC内置dfpwm模块,重写音频播放逻辑
- 添加原生扬声器API支持,支持WAV格式音频播放
- 重写云端服务器音频处理逻辑,支持直接传输WAV文件无需预转换
- 新增WAV文件时长解析、音频序列合成等辅助功能
This commit is contained in:
2026-07-31 19:29:38 +08:00
parent e4b4fa5cdb
commit c73bceaec7
5 changed files with 320 additions and 120 deletions
+49 -1
View File
@@ -10,6 +10,8 @@ local COLORS = {
SUCCESS = colors.green
}
local dfpwm = require "cc.audio.dfpwm"
-- Debug output function
local function debugPrint(level, message)
local timestamp = os.date("%H:%M:%S")
@@ -21,6 +23,52 @@ local function debugPrint(level, message)
term.setTextColor(oldColor)
end
local function playDfpwmFile(path, volume)
local speakers = { peripheral.find("speaker") }
if #speakers == 0 then
debugPrint("ERROR", "No speakers found")
return false
end
local file = fs.open(path, "rb")
if not file then
debugPrint("ERROR", "Cannot open audio file: " .. path)
return false
end
local decoder = dfpwm.make_decoder()
local controller = speakers[1]
while true do
local chunk = file.read(16 * 1024)
if not chunk then break end
local samples = decoder(chunk)
if controller and type(controller.playAudioAll) == "function" then
while not controller.playAudioAll(samples, volume) do
os.pullEvent("speaker_audio_empty")
end
else
local pending = {}
for _, sp in ipairs(speakers) do
pending[peripheral.getName(sp)] = sp
end
while next(pending) do
for name, sp in pairs(pending) do
if sp.playAudio(samples, volume) then
pending[name] = nil
end
end
if next(pending) then
os.pullEvent("speaker_audio_empty")
end
end
end
end
file.close()
return true
end
-- Add random audio playback function
local function playRandomAudio()
local audioFiles = {"aqtx", "jzxy"}
@@ -29,7 +77,7 @@ local function playRandomAudio()
if fs.exists(path) then
debugPrint("INFO", "Attempting to play: "..path)
shell.run("austream "..path.." volume=3.0")
playDfpwmFile(path, 3.0)
debugPrint("INFO", "Finished playing: "..randomFile)
else
debugPrint("ERROR", "Audio file not found: "..path)