add internal/audio_input module
This commit is contained in:
@@ -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
|
||||||
+8
-2
@@ -134,6 +134,10 @@ function on_hud_open()
|
|||||||
audio.play_sound_2d("test-sound", 2.0, 1.0, "ui")
|
audio.play_sound_2d("test-sound", 2.0, 1.0, "ui")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
audio.input.request_open(function(token)
|
||||||
|
input_access_token = token
|
||||||
|
end)
|
||||||
|
|
||||||
function on_hud_render()
|
function on_hud_render()
|
||||||
if hud.hand_controller then
|
if hud.hand_controller then
|
||||||
hud.hand_controller()
|
hud.hand_controller()
|
||||||
@@ -141,6 +145,8 @@ function on_hud_render()
|
|||||||
update_hand()
|
update_hand()
|
||||||
end
|
end
|
||||||
|
|
||||||
local bytes = audio.fetch_input()
|
if input_access_token then
|
||||||
stream:feed(bytes)
|
local bytes = audio.fetch_input(input_access_token)
|
||||||
|
stream:feed(bytes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ end
|
|||||||
|
|
||||||
require "core:internal/maths_inline"
|
require "core:internal/maths_inline"
|
||||||
require "core:internal/debugging"
|
require "core:internal/debugging"
|
||||||
|
require "core:internal/audio_input"
|
||||||
asserts = require "core:internal/asserts"
|
asserts = require "core:internal/asserts"
|
||||||
events = require "core:internal/events"
|
events = require "core:internal/events"
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local _ffi = ffi
|
|||||||
local _debug_getinfo = debug.getinfo
|
local _debug_getinfo = debug.getinfo
|
||||||
|
|
||||||
function crc32(bytes, chksum)
|
function crc32(bytes, chksum)
|
||||||
local chksum = chksum or 0
|
chksum = chksum or 0
|
||||||
|
|
||||||
local length = #bytes
|
local length = #bytes
|
||||||
if type(bytes) == "table" then
|
if type(bytes) == "table" then
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Error at line %{0}=Ошибка на строке %{0}
|
|||||||
Run=Запустить
|
Run=Запустить
|
||||||
Filter=Фильтр
|
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 - Повторить
|
editor.info.tooltip=CTRL+S - Сохранить\nCTRL+R - Запустить\nCTRL+Z - Отменить\nCTRL+Y - Повторить
|
||||||
devtools.traceback=Стек вызовов (от последнего)
|
devtools.traceback=Стек вызовов (от последнего)
|
||||||
|
|||||||
Reference in New Issue
Block a user