fix: remove 3.0 fallback and strictly apply AUDIO_VOLUME=100 directly to HQ speaker APIs

This commit is contained in:
2026-08-02 09:07:12 +08:00
parent faa25bbb3c
commit 805aba9f37
+5 -71
View File
@@ -1127,15 +1127,9 @@ local function queueSamplesSynchronized(samples, volume, playSeq)
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
local success, err = pcall(function() pcall(function()
ok = sp.playAudio(samples, volume) ok = sp.playAudio(samples, volume)
end) end)
if not success then
-- Fallback for vanilla speakers which throw an error if volume > 3.0
pcall(function()
ok = sp.playAudio(samples, 3.0)
end)
end
if ok then if ok then
pending[name] = nil pending[name] = nil
end end
@@ -1166,18 +1160,11 @@ local function playChunkOnSpeakers(samples, volume, playSeq, waitForDrain)
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
local success, err = pcall(function() pcall(function()
if type(sp.playAudio) == "function" then if type(sp.playAudio) == "function" then
ok = sp.playAudio(samples, volume) ok = sp.playAudio(samples, volume)
end end
end) end)
if not success then
pcall(function()
if type(sp.playAudio) == "function" then
ok = sp.playAudio(samples, 3.0)
end
end)
end
if ok then if ok then
usedNativePath = true usedNativePath = true
pending[name] = nil pending[name] = nil
@@ -1200,14 +1187,9 @@ local function playChunkOnSpeakers(samples, volume, playSeq, waitForDrain)
while true do while true do
if shouldStop(playSeq) then return false end if shouldStop(playSeq) then return false end
local ok = false local ok = false
local success, err = pcall(function() pcall(function()
ok = controller.playAudioAll(samples, volume) ok = controller.playAudioAll(samples, volume)
end) end)
if not success then
pcall(function()
ok = controller.playAudioAll(samples, 3.0)
end)
end
if ok then break end if ok then break end
local ev = { os.pullEvent() } local ev = { os.pullEvent() }
if ev[1] == "audio_interrupt" and tonumber(ev[2]) and tonumber(ev[2]) >= playSeq then if ev[1] == "audio_interrupt" and tonumber(ev[2]) and tonumber(ev[2]) >= playSeq then
@@ -1432,21 +1414,6 @@ local function playHqAudioItem(item)
return controller.speakFileAll(payload, CONFIG.AUDIO_VOLUME) return controller.speakFileAll(payload, CONFIG.AUDIO_VOLUME)
end end
end) end)
if not ok then
ok, result = pcall(function()
if format == "hls" and type(controller.speakHLSAll) == "function" then
return controller.speakHLSAll(payload, 3.0)
elseif format == "wav" and type(controller.speakWavAll) == "function" then
return controller.speakWavAll(payload, 3.0)
elseif format == "mp3" and type(controller.speakMp3All) == "function" then
return controller.speakMp3All(payload, 3.0)
elseif format == "ogg" and type(controller.speakOggAll) == "function" then
return controller.speakOggAll(payload, 3.0)
elseif type(controller.speakFileAll) == "function" then
return controller.speakFileAll(payload, 3.0)
end
end)
end
if ok and result then if ok and result then
called = true called = true
end end
@@ -1472,21 +1439,6 @@ local function playHqAudioItem(item)
return sp.speakFile(payload, CONFIG.AUDIO_VOLUME) return sp.speakFile(payload, CONFIG.AUDIO_VOLUME)
end end
end) end)
if not ok then
ok, result = pcall(function()
if format == "hls" and type(sp.speakHLS) == "function" then
return sp.speakHLS(payload, 3.0)
elseif format == "wav" and type(sp.speakWav) == "function" then
return sp.speakWav(payload, 3.0)
elseif format == "mp3" and type(sp.speakMp3) == "function" then
return sp.speakMp3(payload, 3.0)
elseif format == "ogg" and type(sp.speakOgg) == "function" then
return sp.speakOgg(payload, 3.0)
elseif type(sp.speakFile) == "function" then
return sp.speakFile(payload, 3.0)
end
end)
end
if ok and result then if ok and result then
called = true called = true
end end
@@ -1519,7 +1471,7 @@ local function pushWavChunkToSpeakers(payload, playSeq)
local ok = false local ok = false
local queueSize = -1 local queueSize = -1
local isPlaying = false local isPlaying = false
local success, err = pcall(function() pcall(function()
ok = controller.speakWavAll(payload, CONFIG.AUDIO_VOLUME) ok = controller.speakWavAll(payload, CONFIG.AUDIO_VOLUME)
if type(controller.speakQueueSize) == "function" then if type(controller.speakQueueSize) == "function" then
queueSize = tonumber(controller.speakQueueSize()) or -1 queueSize = tonumber(controller.speakQueueSize()) or -1
@@ -1528,17 +1480,6 @@ local function pushWavChunkToSpeakers(payload, playSeq)
isPlaying = controller.speakIsPlaying() and true or false isPlaying = controller.speakIsPlaying() and true or false
end end
end) end)
if not success then
pcall(function()
ok = controller.speakWavAll(payload, 3.0)
if type(controller.speakQueueSize) == "function" then
queueSize = tonumber(controller.speakQueueSize()) or -1
end
if type(controller.speakIsPlaying) == "function" then
isPlaying = controller.speakIsPlaying() and true or false
end
end)
end
if ok then if ok then
Utils.log("INFO", string.format("WAV chunk accepted: bytes=%d queue=%d playing=%s", #payload, queueSize, tostring(isPlaying))) Utils.log("INFO", string.format("WAV chunk accepted: bytes=%d queue=%d playing=%s", #payload, queueSize, tostring(isPlaying)))
return true return true
@@ -1564,18 +1505,11 @@ local function pushWavChunkToSpeakers(payload, playSeq)
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
local success, err = pcall(function() pcall(function()
if type(sp.speakWav) == "function" then if type(sp.speakWav) == "function" then
ok = sp.speakWav(payload, CONFIG.AUDIO_VOLUME) ok = sp.speakWav(payload, CONFIG.AUDIO_VOLUME)
end end
end) end)
if not success then
pcall(function()
if type(sp.speakWav) == "function" then
ok = sp.speakWav(payload, 3.0)
end
end)
end
if ok then pending[name] = nil end if ok then pending[name] = nil end
end end
if next(pending) then if next(pending) then