feat: multiple audio fetchers support

This commit is contained in:
MihailRis
2025-11-01 23:06:26 +03:00
parent 5a65cbe071
commit 86a4060a68
5 changed files with 47 additions and 12 deletions
+17 -4
View File
@@ -5,21 +5,34 @@ local _gui_confirm = gui.confirm
local _base64_encode_urlsafe = base64.encode_urlsafe
local _random_bytes = random.bytes
local _debug_pack_by_frame = debug.get_pack_by_frame
local _audio_fetch_input = audio.fetch_input
local _audio_fetch_input = audio.__fetch_input
audio.__fetch_input = nil
local MAX_FETCH = 44100 * 4
local total_fetch = Bytearray()
function audio.__reset_fetch_buffer()
total_fetch:clear()
end
function audio.fetch_input(token, size)
size = size or MAX_FETCH
if audio_input_tokens_store[token] then
return _audio_fetch_input(size)
if #total_fetch >= size then
return total_fetch:sub(1, size)
end
total_fetch:append(_audio_fetch_input(size - #total_fetch))
return total_fetch:sub()
end
error("access denied")
end
local GRAND_PERMISSION_MSG = "Grant '%{0}' pack audio recording permission?"
local GRANT_PERMISSION_MSG = "Grant '%{0}' pack audio recording permission?"
function audio.input.request_open(callback)
local token = _base64_encode_urlsafe(_random_bytes(18))
local caller = _debug_pack_by_frame(1)
_gui_confirm(gui.str(GRAND_PERMISSION_MSG):gsub("%%{0}", caller), function()
_gui_confirm(gui.str(GRANT_PERMISSION_MSG):gsub("%%{0}", caller), function()
audio_input_tokens_store[token] = caller
callback(token)
menu:reset()