Lớp công cụ
AudioRecorder
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Phương Pháp
Clear():() |
GetConnectedWires(pin: string):{Wire} |
RecordAsync():() |
Stop():() |
Sự Kiện
WiringChanged(connected: boolean,pin: string,wire: Wire,instance: Instance):RBXScriptSignal |
Mẫu mã
Ghi Âm Âm Thanh
local Workspace = game:GetService("Workspace")
local audioRecorder = Instance.new("AudioRecorder")
audioRecorder.Parent = Workspace
local audioPlayer = Instance.new("AudioPlayer")
audioPlayer.Asset = "rbxassetid://5829815715"
audioPlayer.Volume = 0.8
audioPlayer.Parent = Workspace
-- Kết nối AudioPlayer vào AudioRecorder
local wire1 = Instance.new("Wire")
wire1.SourceInstance = audioPlayer
wire1.TargetInstance = audioRecorder
wire1.Parent = audioRecorder
-- Không có cách chính xác để xác định khi nào bộ đệm âm thanh vào để kích hoạt việc ghi âm một cách chính xác
-- Việc ghi âm sẽ có khoảng lặng đầu không có âm thanh so với tài sản gốc
audioPlayer:Play()
audioRecorder:RecordAsync() -- Bắt đầu ghi âm AudioPlayer
print("Đang ghi âm...")
task.wait(5)
audioRecorder:Stop() -- Dừng ghi âm
print("Đã dừng ghi âm!")
audioPlayer:Stop()
audioPlayer.TimePosition = 0
-- Tạo đầu ra để nghe kết quả
local audioOutput = Instance.new("AudioDeviceOutput")
audioOutput.Parent = Workspace
local wire2 = Instance.new("Wire")
wire2.SourceInstance = audioPlayer
wire2.TargetInstance = audioOutput
wire2.Parent = audioOutput
-- Lấy nội dung đã ghi và phát nó trong AudioPlayer
local resultUri = audioRecorder:GetTemporaryContent().Uri
audioPlayer.Asset = resultUri
if not audioPlayer.IsReady then
audioPlayer:GetPropertyChangedSignal("IsReady"):Wait()
end
audioPlayer:Play()Tài Liệu Tham Khảo API
Thuộc Tính
Phương Pháp
Clear
AudioRecorder:Clear():()
Lợi Nhuận
()
GetUnrecordableInstancesAsync
RecordAsync
AudioRecorder:RecordAsync():()
Lợi Nhuận
()
Stop
AudioRecorder:Stop():()
Lợi Nhuận
()
Sự Kiện