add-audio by opusgamelabs/game-creator
npx skills add https://github.com/opusgamelabs/game-creator --skill add-audio为现有游戏添加程序化音乐和音效。背景音乐使用 Web Audio API 步进音序器来循环播放模式。音效直接使用 Web Audio API 实现真正的一次性播放。无需音频文件或 npm 包——所有声音均在浏览器中合成。
分析位于 $ARGUMENTS 的游戏(如果未提供路径,则分析当前目录)。
首先,加载 game-audio 技能以获取完整的 Web Audio 模式和集成指南。
src/core/EventBus.js 以了解存在哪些游戏事件(flap、score、death 等)呈现一个规划好的音频表格:
| 事件 / 场景 | 音频类型 | 风格 | 描述 |
|---|---|---|---|
| GameScene | BGM | 芯片音乐 | 欢快的方波旋律 + 贝斯 + 鼓声 |
| GameOverScene |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| BGM |
| 低沉 |
| 缓慢下降的旋律 |
| 玩家动作 | SFX | 复古 | 快速的音高扫频 |
| 得分 | SFX | 复古 | 双音叮咚声 |
| 死亡 | SFX | 复古 | 下降的破碎音符 |
用通俗易懂的英语解释:"背景音乐将在每个场景中自动循环播放。当你进行跳跃、得分或死亡等操作时,音效会播放。首次点击/轻按时,音频系统将被激活(浏览器要求在播放声音之前需要用户交互)。"
src/audio/AudioManager.js —— AudioContext 初始化、主增益节点、BGM 音序器播放/停止src/audio/AudioBridge.js —— 将 EventBus 事件连接到 AudioManager 以处理 BGM,直接调用 SFX 函数src/audio/music.js,包含每个场景的 BGM 模式(Web Audio 步进音序器 —— 持续循环的音符数组)src/audio/sfx.js,包含每个事件的音效(Web Audio API —— OscillatorNode + GainNode + BiquadFilterNode 用于真正的一次性播放)EventBus.js 中添加音频事件(AUDIO_INIT、MUSIC_GAMEPLAY、MUSIC_GAMEOVER、MUSIC_STOP、AUDIO_TOGGLE_MUTE)main.js 中连接 initAudioBridge()AUDIO_INIT(游戏立即开始,无菜单)AUDIO_TOGGLE_MUTE 事件、UI 按钮、M 键快捷键npm run build 以确认无错误/add-audio examples/flappy-bird
结果:创建 src/audio/AudioManager.js、music.js(gameplay + game-over BGM 模式)、sfx.js(flap、score、death、button SFX)→ 通过 AudioBridge 连接 → M 键静音切换。首次点击激活音频。
原因: 用户交互后 AudioContext 未恢复(浏览器自动播放策略)。修复: 确保在首次用户输入(点击/轻按/按键)时调用 AudioContext.resume()。检查 AUDIO_INIT 事件的连接。
原因: 每帧都创建新的 OscillatorNodes。修复: SFX 应是一次性的(创建、连接、开始、停止)。BGM 使用单个循环音序器。切勿在 update() 中创建节点。
告诉用户:
你的游戏现在有了音乐和音效!接下来,运行
/game-creator:qa-game来添加自动化测试,以验证你的游戏是否正确启动、场景转换正常、计分有效且视觉效果未被破坏。流水线进度:
/make-game→/design-game→/add-audio→/qa-game→/review-game
每周安装量
103
仓库
GitHub 星标
32
首次出现
2026年2月21日
安全审计
安装于
claude-code84
opencode53
kimi-cli51
gemini-cli51
amp51
github-copilot51
Add procedural music and sound effects to an existing game. BGM uses a Web Audio API step sequencer for looping patterns. SFX use the Web Audio API directly for true one-shot playback. No audio files or npm packages needed — everything is synthesized in the browser.
Analyze the game at $ARGUMENTS (or the current directory if no path given).
First, load the game-audio skill to get the full Web Audio patterns and integration guide.
src/core/EventBus.js to see what game events exist (flap, score, death, etc.)Present a table of planned audio:
| Event / Scene | Audio Type | Style | Description |
|---|---|---|---|
| GameScene | BGM | Chiptune | Upbeat square wave melody + bass + drums |
| GameOverScene | BGM | Somber | Slow descending melody |
| Player action | SFX | Retro | Quick pitch sweep |
| Score | SFX | Retro | Two-tone ding |
| Death | SFX | Retro | Descending crushed notes |
Explain in plain English: "Background music will automatically loop during each scene. Sound effects will play when you do things like jump, score, or die. The first time you click/tap, the audio system will activate (browsers require a user interaction before playing sound)."
src/audio/AudioManager.js — AudioContext init, master gain node, BGM sequencer play/stopsrc/audio/AudioBridge.js — wires EventBus events to AudioManager for BGM, calls SFX functions directlysrc/audio/music.js with BGM patterns for each scene (Web Audio step sequencer — note arrays that loop continuously)src/audio/sfx.js with SFX for each event (Web Audio API — OscillatorNode + GainNode + BiquadFilterNode for true one-shot playback)EventBus.js if not present (AUDIO_INIT, MUSIC_GAMEPLAY, MUSIC_GAMEOVER, MUSIC_STOP, )npm run build to confirm no errors/add-audio examples/flappy-bird
Result: Creates src/audio/AudioManager.js, music.js (gameplay + game-over BGM patterns), sfx.js (flap, score, death, button SFX) → wires via AudioBridge → mute toggle on M key. First click activates audio.
Cause: AudioContext not resumed after user interaction (browser autoplay policy). Fix: Ensure AudioContext.resume() is called on first user input (click/tap/keydown). Check for AUDIO_INIT event wiring.
Cause: Creating new OscillatorNodes every frame. Fix: SFX should be one-shot (create, connect, start, stop). BGM uses a single looping sequencer. Never create nodes in update().
Tell the user:
Your game now has music and sound effects! Next, run
/game-creator:qa-gameto add automated tests that verify your game boots correctly, scenes transition properly, scoring works, and visuals haven't broken.Pipeline progress:
/make-game→/design-game→/add-audio→/qa-game→/review-game
Weekly Installs
103
Repository
GitHub Stars
32
First Seen
Feb 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code84
opencode53
kimi-cli51
gemini-cli51
amp51
github-copilot51
AI播客创作工具 - 使用inference.sh CLI快速生成AI驱动播客和音频内容
7,700 周安装
AUDIO_TOGGLE_MUTEinitAudioBridge() in main.jsAUDIO_INIT on first user interaction (game starts immediately, no menu)AUDIO_TOGGLE_MUTE event, UI button, M key shortcut