From 43962aceb0670ccf9994f1dd3f56db87aa683a70 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 1 Aug 2026 00:18:06 +0800 Subject: [PATCH] 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. --- station_broadcast.lua | 49 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index 6d82f80..8c7fc2f 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -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 = {}