|- AudioRecorder 在体验中录制音频流,固定时间限制为60秒。录制的结果可以加载到 AudioPlayer 进行播放。
目前,无法录制 `Class.AudioDeviceInput`。可以使用 `Class.AudioRecorder:GetUnrecordableInstancesAsync()|GetUnrecordableInstancesAsync()` 方法具体检查哪些实例是不可录制的。
代码示例
音频录制器
local Workspace = game:GetService("Workspace")
local audioRecorder = Instance.new("AudioRecorder")
audioRecorder.Parent = Workspace
local audioPlayer = Instance.new("AudioPlayer")
audioPlayer.Asset = "rbxassetid://1839825437"
audioPlayer.Volume = 0.8
audioPlayer.Parent = Workspace
-- 将 AudioPlayer 连接到 AudioRecorder
local wire1 = Instance.new("Wire")
wire1.SourceInstance = audioPlayer
wire1.TargetInstance = audioRecorder
wire1.Parent = audioRecorder
-- 没有确切的方法来确定音频缓冲区何时进入以正确触发录音
-- 录音会与原始资产相比有前置空白静音
audioPlayer:Play()
audioRecorder:RecordAsync() -- 开始录制 AudioPlayer
print("录音...")
task.wait(5)
audioRecorder:Stop() -- 停止录制
print("停止录音!")
audioPlayer:Stop()
audioPlayer.TimePosition = 0
-- 创建输出以收听结果
local audioOutput = Instance.new("AudioDeviceOutput")
audioOutput.Parent = Workspace
local wire2 = Instance.new("Wire")
wire2.SourceInstance = audioPlayer
wire2.TargetInstance = audioOutput
wire2.Parent = audioOutput
-- 获取录制的内容并在 AudioPlayer 中播放
local resultUri = audioRecorder:GetTemporaryContent().Uri
audioPlayer.Asset = resultUri
if not audioPlayer.IsReady then
audioPlayer:GetPropertyChangedSignal("IsReady"):Wait()
end
audioPlayer:Play()
概要
方法
活动
属性
方法
Clear
()
|- 清除 AudioRecorder 中的录音。
返回
()
GetUnrecordableInstancesAsync
Instances
|- 遍历音频图,从此录音机的输入开始,查找不可录制的实例。目前,AudioDeviceInput 是不可录制的。
返回
Instances
Stop
()
|- 停止录音。
返回
()