add internal/audio_input module

This commit is contained in:
MihailRis 2025-10-31 23:30:29 +03:00
parent 284f24433c
commit fe8e4ba7b4
5 changed files with 39 additions and 4 deletions

View File

@ -0,0 +1,27 @@
local audio_input_tokens_store = {}
audio.input = {}
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
function audio.fetch_input(token, size)
if audio_input_tokens_store[token] then
return _audio_fetch_input(size)
end
error("access denied")
end
local GRAND_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()
audio_input_tokens_store[token] = caller
callback(token)
menu:reset()
end)
end

View File

@ -134,6 +134,10 @@ function on_hud_open()
audio.play_sound_2d("test-sound", 2.0, 1.0, "ui")
end
audio.input.request_open(function(token)
input_access_token = token
end)
function on_hud_render()
if hud.hand_controller then
hud.hand_controller()
@ -141,6 +145,8 @@ function on_hud_render()
update_hand()
end
local bytes = audio.fetch_input()
stream:feed(bytes)
if input_access_token then
local bytes = audio.fetch_input(input_access_token)
stream:feed(bytes)
end
end

View File

@ -179,6 +179,7 @@ end
require "core:internal/maths_inline"
require "core:internal/debugging"
require "core:internal/audio_input"
asserts = require "core:internal/asserts"
events = require "core:internal/events"

View File

@ -2,7 +2,7 @@ local _ffi = ffi
local _debug_getinfo = debug.getinfo
function crc32(bytes, chksum)
local chksum = chksum or 0
chksum = chksum or 0
local length = #bytes
if type(bytes) == "table" then

View File

@ -25,7 +25,8 @@ Grant %{0} pack modification permission?=Выдать разрешение на
Error at line %{0}=Ошибка на строке %{0}
Run=Запустить
Filter=Фильтр
Are you sure you want to open the link: =Вы уверены, что хотите открыть ссылку:
Are you sure you want to open the link: =Вы уверены, что хотите открыть ссылку:
Grant '%{0}' pack audio recording permission?=Выдать паку '%{0}' разрешение на запись звука?
editor.info.tooltip=CTRL+S - Сохранить\nCTRL+R - Запустить\nCTRL+Z - Отменить\nCTRL+Y - Повторить
devtools.traceback=Стек вызовов (от последнего)