sound-effects-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSound Effects Generator
音效生成器
Generate programmatic audio: pure tones, noise types, DTMF signals, and simple sound effects. Perfect for testing, alerts, audio cues, and placeholder sounds.
通过编程生成音频:纯音调、各类噪音、DTMF信号以及简单音效。非常适合用于测试、警报、音频提示和占位音效。
Quick Start
快速开始
python
from scripts.sfx_generator import SoundEffectsGeneratorpython
from scripts.sfx_generator import SoundEffectsGeneratorGenerate a tone
生成音调
sfx = SoundEffectsGenerator()
sfx.tone(440, duration=1000).save("a440.wav")
sfx = SoundEffectsGenerator()
sfx.tone(440, duration=1000).save("a440.wav")
Generate white noise
生成白噪音
sfx.noise("white", duration=2000).save("whitenoise.wav")
sfx.noise("white", duration=2000).save("whitenoise.wav")
Create a beep sequence
创建蜂鸣序列
sfx.beep_sequence([440, 880, 440], durations=200, gap=100).save("alert.wav")
undefinedsfx.beep_sequence([440, 880, 440], durations=200, gap=100).save("alert.wav")
undefinedFeatures
功能特性
- Tones: Sine, square, sawtooth, triangle waveforms
- Noise: White, pink, brown/red noise
- DTMF: Phone dial tones
- Sequences: Multi-tone patterns
- Effects: Fade, volume control
- Export: WAV, MP3
- 音调:正弦波、方波、锯齿波、三角波波形
- 噪音:白噪音、粉噪音、棕噪音(红噪音)
- DTMF:电话拨号音
- 序列:多音调模式
- 特效:淡入淡出、音量控制
- 导出:WAV、MP3格式
API Reference
API参考
Initialization
初始化
python
sfx = SoundEffectsGenerator(sample_rate=44100)python
sfx = SoundEffectsGenerator(sample_rate=44100)Tone Generation
音调生成
python
undefinedpython
undefinedPure sine wave
纯正弦波
sfx.tone(frequency=440, duration=1000)
sfx.tone(frequency=440, duration=1000)
Different waveforms
不同波形
sfx.tone(440, duration=1000, waveform="sine") # Default
sfx.tone(440, duration=1000, waveform="square")
sfx.tone(440, duration=1000, waveform="sawtooth")
sfx.tone(440, duration=1000, waveform="triangle")
sfx.tone(440, duration=1000, waveform="sine") # 默认
fx.tone(440, duration=1000, waveform="square")
sfx.tone(440, duration=1000, waveform="sawtooth")
sfx.tone(440, duration=1000, waveform="triangle")
With volume (0.0 to 1.0)
带音量控制(0.0 至 1.0)
sfx.tone(440, duration=1000, volume=0.5)
undefinedsfx.tone(440, duration=1000, volume=0.5)
undefinedNoise Generation
噪音生成
python
undefinedpython
undefinedWhite noise (equal energy all frequencies)
白噪音(全频段能量均等)
sfx.noise("white", duration=2000)
sfx.noise("white", duration=2000)
Pink noise (1/f, natural sounding)
粉噪音(1/f分布,更贴近自然音效)
sfx.noise("pink", duration=2000)
sfx.noise("pink", duration=2000)
Brown noise (1/f^2, deeper)
棕噪音(1/f²分布,更低沉)
sfx.noise("brown", duration=2000)
sfx.noise("brown", duration=2000)
With volume
带音量控制
sfx.noise("white", duration=1000, volume=0.3)
undefinedsfx.noise("white", duration=1000, volume=0.3)
undefinedDTMF Tones
DTMF音调
python
undefinedpython
undefinedSingle digit
单个数字
sfx.dtmf("5", duration=200)
sfx.dtmf("5", duration=200)
Sequence (phone number)
序列(电话号码)
sfx.dtmf_sequence("5551234", tone_duration=150, gap=50)
undefinedsfx.dtmf_sequence("5551234", tone_duration=150, gap=50)
undefinedBeep Sequences
蜂鸣序列
python
undefinedpython
undefinedSingle beep
单个蜂鸣音
sfx.beep(frequency=800, duration=200)
sfx.beep(frequency=800, duration=200)
Multiple beeps (same frequency)
多个蜂鸣音(同一频率)
sfx.beep_sequence([800, 800, 800], durations=100, gap=100)
sfx.beep_sequence([800, 800, 800], durations=100, gap=100)
Melody (different frequencies)
旋律(不同频率)
sfx.beep_sequence([523, 659, 784, 1047], durations=200, gap=50)
sfx.beep_sequence([523, 659, 784, 1047], durations=200, gap=50)
Varying durations
可变时长
sfx.beep_sequence(
frequencies=[440, 880],
durations=[300, 500],
gap=100
)
undefinedsfx.beep_sequence(
frequencies=[440, 880],
durations=[300, 500],
gap=100
)
undefinedSilence
静音
python
undefinedpython
undefinedGenerate silence
生成静音
sfx.silence(duration=1000)
undefinedsfx.silence(duration=1000)
undefinedEffects
特效
python
undefinedpython
undefinedFade in/out
淡入/淡出
sfx.tone(440, 2000).fade_in(200).fade_out(500)
sfx.tone(440, 2000).fade_in(200).fade_out(500)
Volume adjustment
音量调整
sfx.tone(440, 1000).volume(0.5)
undefinedsfx.tone(440, 1000).volume(0.5)
undefinedChaining
链式调用
python
undefinedpython
undefinedCombine multiple sounds
组合多个音效
sfx.tone(440, 500)
.silence(200)
.tone(880, 500)
.save("two_tones.wav")
.silence(200)
.tone(880, 500)
.save("two_tones.wav")
undefinedsfx.tone(440, 500)
.silence(200)
.tone(880, 500)
.save("two_tones.wav")
.silence(200)
.tone(880, 500)
.save("two_tones.wav")
undefinedSave
保存
python
undefinedpython
undefinedSave to WAV
保存为WAV格式
sfx.save("output.wav")
sfx.save("output.wav")
Save to MP3 (requires pydub)
保存为MP3格式(需要pydub)
sfx.save("output.mp3", bitrate=192)
undefinedsfx.save("output.mp3", bitrate=192)
undefinedCLI Usage
CLI使用方法
bash
undefinedbash
undefinedGenerate tone
生成音调
python sfx_generator.py --tone 440 --duration 1000 --output tone.wav
python sfx_generator.py --tone 440 --duration 1000 --output tone.wav
Generate noise
生成噪音
python sfx_generator.py --noise white --duration 2000 --output noise.wav
python sfx_generator.py --noise white --duration 2000 --output noise.wav
Generate DTMF
生成DTMF序列
python sfx_generator.py --dtmf "5551234" --output phone.wav
python sfx_generator.py --dtmf "5551234" --output phone.wav
Generate beep pattern
生成蜂鸣模式
python sfx_generator.py --beeps "800,800,800" --duration 100 --gap 100 --output alert.wav
python sfx_generator.py --beeps "800,800,800" --duration 100 --gap 100 --output alert.wav
With waveform
指定波形
python sfx_generator.py --tone 440 --waveform square --duration 1000 --output square.wav
undefinedpython sfx_generator.py --tone 440 --waveform square --duration 1000 --output square.wav
undefinedCLI Arguments
CLI参数
| Argument | Description | Default |
|---|---|---|
| Frequency in Hz | - |
| Noise type (white, pink, brown) | - |
| DTMF digits | - |
| Comma-separated frequencies | - |
| Duration in ms | 1000 |
| Gap between sounds (ms) | 100 |
| Tone waveform | sine |
| Volume (0.0-1.0) | 0.8 |
| Sample rate | 44100 |
| Output file | Required |
| 参数 | 描述 | 默认值 |
|---|---|---|
| 频率(Hz) | - |
| 噪音类型(white, pink, brown) | - |
| DTMF数字 | - |
| 逗号分隔的频率列表 | - |
| 时长(ms) | 1000 |
| 音效间隔(ms) | 100 |
| 音调波形 | sine |
| 音量(0.0-1.0) | 0.8 |
| 采样率 | 44100 |
| 输出文件 | 必填 |
Examples
示例
Alert Sound
警报音效
python
sfx = SoundEffectsGenerator()
sfx.beep_sequence(
frequencies=[880, 1100, 880, 1100],
durations=150,
gap=50
)
sfx.fade_out(100)
sfx.save("alert.wav")python
sfx = SoundEffectsGenerator()
sfx.beep_sequence(
frequencies=[880, 1100, 880, 1100],
durations=150,
gap=50
)
sfx.fade_out(100)
sfx.save("alert.wav")Notification Chime
通知提示音
python
sfx = SoundEffectsGenerator()python
sfx = SoundEffectsGenerator()C-E-G chord progression
C-E-G和弦进行
notes = [523, 659, 784] # C5, E5, G5
for freq in notes:
sfx.tone(freq, 200)
sfx.silence(50)
sfx.fade_out(200)
sfx.save("chime.wav")
undefinednotes = [523, 659, 784] # C5, E5, G5
for freq in notes:
sfx.tone(freq, 200)
sfx.silence(50)
sfx.fade_out(200)
sfx.save("chime.wav")
undefinedWhite Noise Background
白噪音背景音
python
sfx = SoundEffectsGenerator()
sfx.noise("brown", duration=60000) # 1 minute
sfx.volume(0.3) # Quiet
sfx.fade_in(2000)
sfx.fade_out(2000)
sfx.save("background.mp3", bitrate=128)python
sfx = SoundEffectsGenerator()
sfx.noise("brown", duration=60000) # 1分钟
sfx.volume(0.3) # 低音量
sfx.fade_in(2000)
sfx.fade_out(2000)
sfx.save("background.mp3", bitrate=128)DTMF Phone Number
DTMF电话号码拨号音
python
sfx = SoundEffectsGenerator()
sfx.dtmf_sequence("18005551234", tone_duration=180, gap=80)
sfx.save("phone_dial.wav")python
sfx = SoundEffectsGenerator()
sfx.dtmf_sequence("18005551234", tone_duration=180, gap=80)
sfx.save("phone_dial.wav")Test Tone Sweep
测试音调扫描
python
sfx = SoundEffectsGenerator()python
sfx = SoundEffectsGenerator()Generate tones from 100Hz to 1000Hz
生成100Hz到1000Hz的音调
for freq in range(100, 1001, 100):
sfx.tone(freq, 200)
sfx.silence(50)
sfx.save("sweep.wav")
undefinedfor freq in range(100, 1001, 100):
sfx.tone(freq, 200)
sfx.silence(50)
sfx.save("sweep.wav")
undefinedCommon Frequencies
常用频率
| Name | Frequency (Hz) |
|---|---|
| A4 (Concert pitch) | 440 |
| Middle C (C4) | 261.63 |
| C5 | 523.25 |
| Standard dial tone | 350 + 440 |
| Busy signal | 480 + 620 |
| 名称 | 频率(Hz) |
|---|---|
| A4(标准音高) | 440 |
| 中央C(C4) | 261.63 |
| C5 | 523.25 |
| 标准拨号音 | 350 + 440 |
| 忙音 | 480 + 620 |
Musical Notes (A4 = 440Hz)
音符频率(A4 = 440Hz)
| Note | Frequency |
|---|---|
| C4 | 261.63 |
| D4 | 293.66 |
| E4 | 329.63 |
| F4 | 349.23 |
| G4 | 392.00 |
| A4 | 440.00 |
| B4 | 493.88 |
| C5 | 523.25 |
| 音符 | 频率 |
|---|---|
| C4 | 261.63 |
| D4 | 293.66 |
| E4 | 329.63 |
| F4 | 349.23 |
| G4 | 392.00 |
| A4 | 440.00 |
| B4 | 493.88 |
| C5 | 523.25 |
Dependencies
依赖项
numpy>=1.24.0
scipy>=1.10.0
soundfile>=0.12.0Optional: pydub (for MP3 export)
numpy>=1.24.0
scipy>=1.10.0
soundfile>=0.12.0可选:pydub(用于MP3导出)
Limitations
局限性
- No complex synthesis (no ADSR envelopes)
- No stereo panning
- Limited to basic waveforms
- MP3 export requires pydub + FFmpeg
- 不支持复杂合成(无ADSR包络)
- 不支持立体声平移
- 仅支持基础波形
- MP3导出需要pydub + FFmpeg