add-audio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdd Audio
添加音频
Add procedural music and sound effects to an existing game. BGM uses Strudel.cc for looping patterns. SFX use the Web Audio API directly for true one-shot playback. No audio files needed — everything is synthesized in the browser.
为现有游戏添加程序化音乐和音效。背景音乐(BGM)使用Strudel.cc实现循环模式,音效(SFX)直接使用Web Audio API实现真正的一次性播放。无需音频文件——所有内容均在浏览器中合成。
Instructions
操作步骤
Analyze the game at (or the current directory if no path given).
$ARGUMENTSFirst, load the game-audio skill to get the full Strudel patterns and integration guide.
分析路径下的游戏(若未指定路径则分析当前目录)。
$ARGUMENTS首先,加载game-audio技能以获取完整的Strudel模式和集成指南。
Step 1: Audit
步骤1:审计
- Read to identify the engine and check if
package.jsonis installed@strudel/web - Read to see what game events exist (flap, score, death, etc.)
src/core/EventBus.js - Read all scene files to understand the game flow (gameplay, game over)
- Identify what music and SFX would fit the game's genre and mood
- 读取以识别游戏引擎,并检查是否已安装
package.json@strudel/web - 读取以查看存在哪些游戏事件(如flap、score、death等)
src/core/EventBus.js - 读取所有场景文件以理解游戏流程(游戏进行中、游戏结束)
- 确定适合游戏类型和氛围的音乐与音效风格
Step 2: Plan
步骤2:规划
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)."
呈现一份规划音频的表格:
| 事件/场景 | 音频类型 | 风格 | 描述 |
|---|---|---|---|
| GameScene | BGM | 芯片音乐(Chiptune) | 欢快的方波旋律+贝斯+鼓点 |
| GameOverScene | BGM | 低沉忧郁 | 缓慢下行的旋律 |
| 玩家动作 | SFX | 复古风格 | 快速音调扫频 |
| 得分 | SFX | 复古风格 | 双音调提示音 |
| 死亡 | SFX | 复古风格 | 下行失真音符 |
用通俗易懂的语言说明:“背景音乐将在每个场景中自动循环播放。当你执行跳跃、得分或死亡等操作时,会触发音效播放。首次点击/触摸时,音频系统将激活(浏览器要求必须有用户交互才能播放声音)。”
Step 3: Implement
步骤3:实现
- Install if not already present
@strudel/web - Create — manages Strudel init, BGM play/stop (uses
src/audio/AudioManager.js+ 100ms delay before newhush()).play() - Create — wires EventBus events to AudioManager for BGM, calls SFX functions directly
src/audio/AudioBridge.js - Create with BGM for each scene (Strudel
src/audio/music.js+stack()— these loop continuously).play() - Create with SFX for each event (Web Audio API — OscillatorNode + GainNode + BiquadFilterNode for true one-shot playback)
src/audio/sfx.js - Add audio events to (
EventBus.js,AUDIO_INIT,MUSIC_GAMEPLAY,MUSIC_GAMEOVER)MUSIC_STOP - Wire in
initAudioBridge()main.js - Emit on first user interaction (game starts immediately, no menu)
AUDIO_INIT - Emit music events at scene transitions and SFX events at game actions
Critical: Strudel's starts a continuously looping pattern — correct for BGM, wrong for SFX. SFX must use the Web Audio API directly (see game-audio skill). Import , , , from for BGM only.
.play()stacknoteshush@strudel/web- 若尚未安装,则进行安装
@strudel/web - 创建——管理Strudel初始化、BGM播放/停止(使用
src/audio/AudioManager.js+100ms延迟后再执行新的hush()).play() - 创建——将EventBus事件与AudioManager关联以控制BGM,直接调用SFX函数
src/audio/AudioBridge.js - 创建,包含每个场景的BGM(使用Strudel的
src/audio/music.js+stack()——这些会持续循环).play() - 创建,包含每个事件的SFX(Web Audio API——使用OscillatorNode + GainNode + BiquadFilterNode实现真正的一次性播放)
src/audio/sfx.js - 向中添加音频事件(
EventBus.js、AUDIO_INIT、MUSIC_GAMEPLAY、MUSIC_GAMEOVER)MUSIC_STOP - 在中调用
main.jsinitAudioBridge() - 在首次用户交互时触发(游戏直接启动,无菜单)
AUDIO_INIT - 在场景切换时触发音乐事件,在游戏动作触发时触发SFX事件
关键注意事项:Strudel的会启动持续循环的模式——这适用于BGM,但不适用于SFX。SFX必须直接使用Web Audio API实现(请查看game-audio技能)。仅在BGM中从导入、、、。
.play()@strudel/webstacknoteshushStep 4: Verify
步骤4:验证
- Run to confirm no errors
npm run build - List all files created/modified
- Remind the user: "Click/tap once to activate audio, then you'll hear the music"
- Note the AGPL-3.0 license requirement for
@strudel/web
- 运行以确认无错误
npm run build - 列出所有创建/修改的文件
- 提醒用户:“点击/触摸一次以激活音频,之后即可听到音乐”
- 注意要求遵循AGPL-3.0许可证
@strudel/web
Next Step
下一步
Tell the user:
Your game now has music and sound effects! Next, runto add automated tests that verify your game boots correctly, scenes transition properly, scoring works, and visuals haven't broken./game-creator:qa-gamePipeline progress:/make-game→/design-game→/add-audio→→/qa-game/review-game
告知用户:
你的游戏现在已经拥有音乐和音效了!接下来,请运行添加自动化测试,验证游戏能否正常启动、场景切换是否正常、计分功能是否可用,以及视觉效果是否未被破坏。/game-creator:qa-game流程进度:/make-game→/design-game→/add-audio→→/qa-game/review-game