roblox-audio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRoblox audio
Roblox 音频
Two systems coexist:
- Audio API (modular, current): →
AudioPlayer→ (Wire…AudioEmitter) →AudioListener→Wire, with effect objects inserted in the chain. Required for voice-chat processing, mixing graphs, analyzers, text-to-speech/speech-to-text.AudioDeviceOutput - (classic, still supported): one object, parented to a part for 3D or to
Sound/UI for 2D; routed throughSoundServices withSoundGroupchildren. Fine for simple games and existing code.SoundEffect
Don't mix both for the same feature; follow what the project uses.
两套系统并存:
- Audio API(模块化,当前系统):→
AudioPlayer→ (Wire…AudioEmitter) →AudioListener→Wire,并在链路中插入 effect 对象。语音聊天处理、混音图、分析器以及 text-to-speech/speech-to-text 都需要使用该系统。AudioDeviceOutput - (经典系统,仍受支持):单个对象;进行 3D 播放时父级设为 part,进行 2D 播放时父级设为
Sound/UI;通过带有SoundService子对象的SoundEffect进行路由。适用于简单游戏和现有代码。SoundGroup
不要为同一功能混用这两套系统;应遵循项目所使用的系统。
2D audio (music, UI) with the Audio API
使用 Audio API 播放 2D 音频(音乐、UI)
luau
--!strict
-- Client: build a music player once.
local SoundService = game:GetService("SoundService")
local player = Instance.new("AudioPlayer")
player.Name = "Music"
player.Asset = "rbxassetid://1843463175" -- AudioPlayer.AssetId is deprecated; use Asset
player.Looping = true
player.Volume = 0.5
player.Parent = SoundService
local fader = Instance.new("AudioFader") -- one place to control music volume (settings menu)
fader.Name = "MusicVolume"
fader.Parent = SoundService
local output = Instance.new("AudioDeviceOutput")
output.Parent = SoundService
local function wire(source: Instance, target: Instance)
local w = Instance.new("Wire")
w.SourceInstance = source
w.TargetInstance = target
w.Parent = target
end
wire(player, fader)
wire(fader, output)
player:Play()luau
--!strict
-- Client: build a music player once.
local SoundService = game:GetService("SoundService")
local player = Instance.new("AudioPlayer")
player.Name = "Music"
player.Asset = "rbxassetid://1843463175" -- AudioPlayer.AssetId is deprecated; use Asset
player.Looping = true
player.Volume = 0.5
player.Parent = SoundService
local fader = Instance.new("AudioFader") -- one place to control music volume (settings menu)
fader.Name = "MusicVolume"
fader.Parent = SoundService
local output = Instance.new("AudioDeviceOutput")
output.Parent = SoundService
local function wire(source: Instance, target: Instance)
local w = Instance.new("Wire")
w.SourceInstance = source
w.TargetInstance = target
w.Parent = target
end
wire(player, fader)
wire(fader, output)
player:Play()3D audio with the Audio API
使用 Audio API 播放 3D 音频
- Put an on the sound's part/attachment; wire
AudioEmitter.AudioPlayer → AudioEmitter - Listening: controls the default
SoundService.ListenerLocation(camera or character); wireAudioListener(done automatically in default setups).AudioListener → AudioDeviceOutput - Distance falloff and directionality are set on the emitter/listener (, the
AudioEmitter:SetDistanceAttenuationstring property on emitters and listeners scopes who hears what).AudioInteractionGroup
- 将 放在声音的 part/attachment 上;连接
AudioEmitter。AudioPlayer → AudioEmitter - 监听:控制默认的
SoundService.ListenerLocation(摄像机或角色); 连接AudioListener(默认配置会自动完成此操作)。AudioListener → AudioDeviceOutput - 距离衰减和方向性在 emitter/listener 上设置(); emitter 和 listener 上的
AudioEmitter:SetDistanceAttenuation字符串属性用于限定谁能听到哪些声音。AudioInteractionGroup
Classic Sound quick reference
经典 Sound 快速参考
luau
--!strict
local SoundService = game:GetService("SoundService")
local sfxGroup = Instance.new("SoundGroup")
sfxGroup.Name = "SFX"
sfxGroup.Volume = 0.8
sfxGroup.Parent = SoundService
local function playAt(part: BasePart, soundId: string)
local sound = Instance.new("Sound")
sound.SoundId = soundId
sound.SoundGroup = sfxGroup
sound.RollOffMaxDistance = 80
sound.Parent = part -- 3D: plays from the part; parent to SoundService/UI for 2D
sound:Play()
sound.Ended:Once(function()
sound:Destroy()
end)
end
return playAt- for client-only UI clicks.
SoundService:PlayLocalSound(sound) - Preload critical sounds: (not everything — slows joins).
ContentProvider:PreloadAsync({ sound }) - Pool frequently played sounds instead of creating one per shot.
luau
--!strict
local SoundService = game:GetService("SoundService")
local sfxGroup = Instance.new("SoundGroup")
sfxGroup.Name = "SFX"
sfxGroup.Volume = 0.8
sfxGroup.Parent = SoundService
local function playAt(part: BasePart, soundId: string)
local sound = Instance.new("Sound")
sound.SoundId = soundId
sound.SoundGroup = sfxGroup
sound.RollOffMaxDistance = 80
sound.Parent = part -- 3D: plays from the part; parent to SoundService/UI for 2D
sound:Play()
sound.Ended:Once(function()
sound:Destroy()
end)
end
return playAt- 用于仅在客户端播放的 UI 点击音效。
SoundService:PlayLocalSound(sound) - 预加载关键声音:(不要预加载所有声音——会拖慢玩家加入速度)。
ContentProvider:PreloadAsync({ sound }) - 对频繁播放的声音使用对象池,而不是每次触发都创建一个新对象。
Where to play
播放位置
- Sounds started on the client are heard only by that client (UI, local feedback, music tracks the player chose). Sounds started on the server replicate to everyone (use sparingly; prefer a remote telling clients to play locally, which also lets each client apply its own volume settings).
- With (default), client-played sounds don't replicate.
SoundService.RespectFilteringEnabled = true - Streaming: a sound or emitter in a part that streams out stops. Keep ambient audio in persistent
models or .
SoundService
- 在客户端启动的声音只有该客户端能听到(UI、本地反馈、玩家选择的音乐曲目)。在服务端启动的声音会同步给所有玩家(应谨慎使用;更适合通过 Remote 通知客户端在本地播放,这样每个客户端还可以应用自己的音量设置)。
- 当 时(默认值),客户端播放的声音不会同步。
SoundService.RespectFilteringEnabled = true - Streaming:声音或 emitter 所在的 part 一旦被流出,播放就会停止。应将环境音频放在持久化 model 或 中。
SoundService
Assets and permissions
资产与权限
- Use audio you own, uploaded to the same owner (user/group) as the experience, or Creator Store audio marked free-to-use. Private audio from other creators won't play unless shared with your experience (asset permissions). Check the Output for "failed to load" / permission errors.
- Uploads are auto-classified as sound effects or songs; eligible songs can show on the game page.
- 使用你拥有且以与 experience 相同的 owner(user/group)身份上传的音频,或 Creator Store 中标记为可免费使用的音频。其他创作者的私有音频,除非已共享给你的 experience(资产权限),否则无法播放。检查 中是否有“failed to load”/权限错误。
Output - 上传的音频会被自动分类为 sound effects 或 songs;符合条件的歌曲可以显示在游戏页面中。
Extras
附加功能
- Effects: ,
AudioEqualizer,AudioCompressor,AudioReverb,AudioEcho,AudioChorus,AudioDistortion,AudioFlanger,AudioPitchShifter,AudioTremolo,AudioFilter,AudioLimiter(read loudness/spectrum for visualizers).AudioAnalyzer - (artificial voices) and
AudioTextToSpeech(transcription).AudioSpeechToText - Voice chat: each player's can be wired through effects (radios, walkie-talkies, proximity) — see the voice chat docs; respect players' voice settings.
AudioDeviceInput - Give players separate Music/SFX volume sliders (faders or SoundGroups) and a mute option.
- Effects:、
AudioEqualizer、AudioCompressor、AudioReverb、AudioEcho、AudioChorus、AudioDistortion、AudioFlanger、AudioPitchShifter、AudioTremolo、AudioFilter、AudioLimiter(读取 响度/频谱以制作可视化效果)。AudioAnalyzer - (人工合成语音)和
AudioTextToSpeech(转录)。AudioSpeechToText - 语音聊天:每位玩家的 都可以通过 effects 进行连接(无线电、对讲机、邻近通信)——请参阅语音聊天文档,并尊重玩家的语音设置。
AudioDeviceInput - 为玩家提供独立的 Music/SFX 音量滑块(faders 或 SoundGroups)以及静音选项。
Related skills
相关 skill
roblox-uiroblox-architectureroblox-performanceroblox-uiroblox-architectureroblox-performance