google/xb-sound
>- Play and capture audio in an XR Blocks app via `xb.sound` — spatial (positional) audio anchored to scene objects, master volume control, microphone recording and playback, plus speech recognition and synthesis. Use to add sound effects, 3D-positioned audio, voice recording, or text-to-speech / speech-to-text. Covers `xb.core.sound` (`startRecording`/`stopRecording`/`playRecordedAudio`, `getAudioListener`, `setMasterVolume`) and the exported `SpeechRecognizer` / `SpeechSynthesizer` / `SoundSynthesizer` classes. See samples/sound.
npx skills add https://github.com/google/xrblocks --skill xb-sound
xb.sound (a.k.a. xb.core.sound) manages audio. See samples/sound, demos/sound_detector,
and src/sound/ (which has its own README).
Attach a THREE.PositionalAudio to any object so it pans/attenuates with the listener:
const listener = xb.core.sound.getAudioListener();
const audio = new THREE.PositionalAudio(listener);
audio.setBuffer(audioBuffer); // a decoded AudioBuffer
audio.setRefDistance(0.5);
audio.setVolume(1.0);
ball.add(audio); // parented to the object → 3D positioned
audio.play();
await xb.core.sound.startRecording();
// …later…
const pcm = xb.core.sound.stopRecording(); // ArrayBuffer of Int16 PCM
const rate = xb.core.sound.getRecordingSampleRate();
await xb.core.sound.playRecordedAudio(pcm, rate);
xb.core.sound.setMasterVolume(0.8); // 0..1
The SDK exports xb.SpeechRecognizer and xb.SpeechSynthesizer (plus xb.SoundSynthesizer
and xb.BackgroundMusic). Use them for speech-to-text and text-to-speech; see
src/sound/SpeechRecognizer.ts and
src/sound/SpeechSynthesizer.ts for their APIs.
options.permissions.microphone = true (oruse a feature that requests it) before relying on recording.
THREE AudioBuffer for positional playback(see the conversion in samples/sound/main.js).
xb.core.sound.disableAudio() to tear down capture when done.Take google/xb-sound from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.