feat: add stream audio broadcast support

- 添加stream音频格式的客户端播放逻辑与网络消息解析
- 新增云服务端媒体静态服务端点,重构音频处理逻辑以返回流URL替代原始音频缓冲区
- 更新所有相关业务接口适配新的流音频播放流程
- 新增API基础地址环境变量配置
This commit is contained in:
2026-07-31 20:15:21 +08:00
parent cd22b1ca3e
commit 952efbc2c7
2 changed files with 75 additions and 19 deletions
+18 -4
View File
@@ -687,7 +687,9 @@ local function playHqAudioItem(item)
if controller then
local ok, result = pcall(function()
if format == "wav" and type(controller.speakWavAll) == "function" then
if format == "stream" and type(controller.speakStreamAll) == "function" then
return controller.speakStreamAll(payload, CONFIG.AUDIO_VOLUME)
elseif format == "wav" and type(controller.speakWavAll) == "function" then
return controller.speakWavAll(payload, CONFIG.AUDIO_VOLUME)
elseif type(controller.speakFileAll) == "function" then
return controller.speakFileAll(payload, CONFIG.AUDIO_VOLUME)
@@ -701,7 +703,9 @@ local function playHqAudioItem(item)
if not called then
for _, sp in ipairs(Peripherals.speakers) do
local ok, result = pcall(function()
if format == "wav" and type(sp.speakWav) == "function" then
if format == "stream" and type(sp.speakStream) == "function" then
return sp.speakStream(payload, CONFIG.AUDIO_VOLUME)
elseif format == "wav" and type(sp.speakWav) == "function" then
return sp.speakWav(payload, CONFIG.AUDIO_VOLUME)
elseif type(sp.speakFile) == "function" then
return sp.speakFile(payload, CONFIG.AUDIO_VOLUME)
@@ -769,7 +773,7 @@ end
function Audio.playItem(item)
local format = tostring(item.audioFormat or "dfpwm"):lower()
if format == "wav" or format == "file" then
if format == "wav" or format == "file" or format == "stream" then
return playHqAudioItem(item)
end
return Audio.playDfpwmItem(item)
@@ -1068,6 +1072,7 @@ function Network.messageLoop()
end
local priority = tonumber(data.priority) or 0
local audioFormat = tostring(data.audioFormat or "dfpwm"):lower()
local streamUrl = type(data.streamUrl) == "string" and data.streamUrl or nil
local interruptMode = tostring(data.interruptMode or "")
if interruptMode == "" then
if priority >= 2 then interruptMode = "all"
@@ -1090,7 +1095,16 @@ function Network.messageLoop()
audioFormat = audioFormat
}
if audioFormat == "dfpwm" then
if audioFormat == "stream" and streamUrl and streamUrl ~= "" then
Audio.enqueueItem({
audioData = streamUrl,
audioFormat = "stream",
priority = priority,
source = State.audioRx.source,
audioId = data.audioId
})
State.audioRx = nil
elseif audioFormat == "dfpwm" then
local stream = Audio.createStream()
State.audioRx.stream = stream
Audio.enqueueItem({