Loading...
Loading...
Read real-time amplitude and 8-band frequency data from any AudioSource, AudioStream, or VideoPlayer entity in a Decentraland SDK7 scene with the AudioAnalysis component. Use when the user asks for music visualizers, beat reactivity, equalizers, or audio-reactive scenes. Do NOT use to play sound (see audio-video) or to detect player-emitted audio (this reads only entity-attached AudioSource/AudioStream/VideoPlayer audio).
npx skill4agent add decentraland/sdk-skills audio-analysisAudioSourceAudioStreamVideoPlayerAudioAnalysisAudioSourceAudioStreamVideoPlayerAudioAnalysisamplitudebands[]00AudioAnalysisamplitudereadIntoViewreadIntoViewtryReadIntoViewAudioAnalysisView = { amplitude: number, bands: number[] }newbandscreateAudioAnalysiscreateAudioAnalysis.createAudioAnalysis(entity, mode?, amplitudeGain?, bandsGain?)AudioAnalysis.create(entity, {...})createOrReplaceAudioAnalysisimport {
AudioAnalysis,
AudioAnalysisView,
PBAudioAnalysisMode,
AudioSource, // or AudioStream / VideoPlayer
engine,
Transform,
} from "@dcl/sdk/ecs";
import { Vector3 } from "@dcl/sdk/math";AudioAnalysisView@dcl/sdk/ecs| Field | Type | Range | Notes |
|---|---|---|---|
| | | Aggregate signal strength of the current audio frame. |
| | | Lowest frequency bin (sub-bass). |
| | | Increasing frequency bins, log-spaced under MODE_LOGARITHMIC. |
| | | Highest frequency bin (treble/air). |
| Field | Type | Default | Notes |
|---|---|---|---|
| | | |
| | | Multiplier applied to |
| | | Multiplier applied to all 8 bands. Only used in MODE_LOGARITHMIC. |
Values are unbounded floats — gains can push them above. Clamp or scale in your system if the visual you drive needs1. For typical music at default gains, expect peaks roughly in0..1with normal content sitting0..1.0..0.5
readIntoViewtryReadIntoViewtype AudioAnalysisView = {
amplitude: number;
bands: number[]; // length 8 — bands[0] = lowest freq, bands[7] = highest
};const view: AudioAnalysisView = { amplitude: 0, bands: new Array<number>(8) };
engine.addSystem(() => {
// Throws if the entity has no AudioAnalysis
AudioAnalysis.readIntoView(audioEntity, view);
// Or, defensive variant — returns false if missing, no throw
// if (!AudioAnalysis.tryReadIntoView(audioEntity, view)) return
// view.amplitude and view.bands[0..7] are now populated
});readIntoView(entity, out)outAudioAnalysistryReadIntoView(entity, out): booleanfalse// 1. Pulse an entity's scale to overall amplitude
const view: AudioAnalysisView = { amplitude: 0, bands: new Array<number>(8) };
engine.addSystem(() => {
AudioAnalysis.readIntoView(audioEntity, view);
const t = Transform.getMutable(pulseEntity);
const s = 1 + view.amplitude * 10; // base 1, gain to taste
t.scale = Vector3.create(s, s, s);
});
// 2. 8-bar equalizer (one entity per band, scale Y by bands[i])
for (const [entity, _] of engine.getEntitiesWith(VisualBar, Transform)) {
const i = VisualBar.get(entity).index; // 0..7
Transform.getMutable(entity).scale = Vector3.create(
1,
view.bands[i] * BAR_HEIGHT,
1
);
}
// 3. Bass-only kick — react to the lowest band
const bass = view.bands[0] + view.bands[1]; // sub + low
if (bass > 0.7) {
/* trigger flash */
}
// 4. Custom gains (less sensitive amplitude, punchier bands)
AudioAnalysis.createAudioAnalysis(
audioEntity,
PBAudioAnalysisMode.MODE_LOGARITHMIC,
2.0,
0.1
);{baseDir}/references/audio-analysis-example.mdMODE_LOGARITHMIC0..1amplitudeGainbandsGainMODE_RAWamplitudeGainbandsGain1212amplitudeGainbandsGain1.00..1dtAudioAnalysisVideoPlayerAudioAnalysis.createAudioAnalysis(videoEntity)VideoPlayerAudioSource88,-10-audio-visualizationpitchAudioSource.pitchreadIntoViewcreateAudioAnalysistryReadIntoViewAudioSourceAudioStreamVideoPlayerALLOW_MEDIA_HOSTNAMESscene.jsonaudio-videoAudioSourceAudioAnalysis.createAudioAnalysis()VideoPlayerAudioAnalysis.createAudioAnalysis()AudioAnalysisViewreadIntoView{baseDir}/references/audio-analysis-example.mdsdk7-goerli-plaza/audio-visualization