fix(station): prefer native speaker.playAudio for decoded chunks

Bump the station build to v1.0.3 and send decoded WAV samples through each speaker's native playAudio path before falling back to controller.playAudioAll, with logs to show which output path was used.
This commit is contained in:
2026-08-01 00:18:06 +08:00
parent e6fa681339
commit 43962aceb0
+31 -18
View File
@@ -2,7 +2,7 @@
-- ============================================================================
-- 1. Configuration & Constants
-- ============================================================================
local APP_VERSION_TEXT = "v1.0.2"
local APP_VERSION_TEXT = "v1.0.3"
local CONFIG = {
CLOUD_URL = "ws://stabadmin.fse-media.group",
@@ -593,35 +593,26 @@ end
local function playChunkOnSpeakers(samples, volume, playSeq)
if not Peripherals.speakers or #Peripherals.speakers == 0 then return false end
local controller = Peripherals.speakers[1]
if controller and type(controller.playAudioAll) == "function" then
while true do
if shouldStop(playSeq) then return false end
local ok = false
pcall(function()
ok = controller.playAudioAll(samples, volume)
end)
if ok then break end
local ev = { os.pullEvent() }
if ev[1] == "audio_interrupt" and tonumber(ev[2]) and tonumber(ev[2]) >= playSeq then
return false
end
end
else
local pending = {}
for _, sp in ipairs(Peripherals.speakers) do
local name = peripheral.getName(sp)
if name then pending[name] = sp end
end
local usedNativePath = false
while next(pending) do
if shouldStop(playSeq) then return false end
for name, sp in pairs(pending) do
local ok = false
pcall(function()
ok = sp.playAudio(samples, volume)
if type(sp.playAudio) == "function" then
ok = sp.playAudio(samples, volume)
end
end)
if ok then pending[name] = nil end
if ok then
usedNativePath = true
pending[name] = nil
end
end
if next(pending) then
local ev = { os.pullEvent() }
@@ -630,6 +621,28 @@ local function playChunkOnSpeakers(samples, volume, playSeq)
end
end
end
if usedNativePath then
Utils.log("INFO", string.format("Audio samples queued via native speaker.playAudio: samples=%d", #samples))
else
local controller = Peripherals.speakers[1]
if controller and type(controller.playAudioAll) == "function" then
Utils.log("WARN", "Falling back to controller.playAudioAll for decoded samples")
while true do
if shouldStop(playSeq) then return false end
local ok = false
pcall(function()
ok = controller.playAudioAll(samples, volume)
end)
if ok then break end
local ev = { os.pullEvent() }
if ev[1] == "audio_interrupt" and tonumber(ev[2]) and tonumber(ev[2]) >= playSeq then
return false
end
end
else
return false
end
end
local waiting = {}