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:
+31
-18
@@ -2,7 +2,7 @@
|
|||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
-- 1. Configuration & Constants
|
-- 1. Configuration & Constants
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
local APP_VERSION_TEXT = "v1.0.2"
|
local APP_VERSION_TEXT = "v1.0.3"
|
||||||
|
|
||||||
local CONFIG = {
|
local CONFIG = {
|
||||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||||
@@ -593,35 +593,26 @@ end
|
|||||||
|
|
||||||
local function playChunkOnSpeakers(samples, volume, playSeq)
|
local function playChunkOnSpeakers(samples, volume, playSeq)
|
||||||
if not Peripherals.speakers or #Peripherals.speakers == 0 then return false end
|
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 = {}
|
local pending = {}
|
||||||
for _, sp in ipairs(Peripherals.speakers) do
|
for _, sp in ipairs(Peripherals.speakers) do
|
||||||
local name = peripheral.getName(sp)
|
local name = peripheral.getName(sp)
|
||||||
if name then pending[name] = sp end
|
if name then pending[name] = sp end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local usedNativePath = false
|
||||||
while next(pending) do
|
while next(pending) do
|
||||||
if shouldStop(playSeq) then return false end
|
if shouldStop(playSeq) then return false end
|
||||||
for name, sp in pairs(pending) do
|
for name, sp in pairs(pending) do
|
||||||
local ok = false
|
local ok = false
|
||||||
pcall(function()
|
pcall(function()
|
||||||
ok = sp.playAudio(samples, volume)
|
if type(sp.playAudio) == "function" then
|
||||||
|
ok = sp.playAudio(samples, volume)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
if ok then pending[name] = nil end
|
if ok then
|
||||||
|
usedNativePath = true
|
||||||
|
pending[name] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if next(pending) then
|
if next(pending) then
|
||||||
local ev = { os.pullEvent() }
|
local ev = { os.pullEvent() }
|
||||||
@@ -630,6 +621,28 @@ local function playChunkOnSpeakers(samples, volume, playSeq)
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
local waiting = {}
|
local waiting = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user