本文目录导读:

我来介绍几种用脚本调整音效均衡器的方法,涵盖不同操作系统和工具:
Windows系统
PowerShell + Equalizer APO
# Equalizer APO 配置文件调整脚本 $configPath = "C:\Program Files\EqualizerAPO\config\config.txt" # 备份原配置 Copy-Item $configPath "$configPath.bak" # 写入新的均衡器设置 $configContent = @" # 10段均衡器设置 Preamp: -5 dB GraphicEQ: 31 -3; 62 -2; 125 -1; 250 0; 500 1; 1k 2; 2k 3; 4k 2; 8k 1; 16k 0 "@ Set-Content -Path $configPath -Value $configContent # 重启音频服务 Restart-Service Audiosrv
Windows API 音频增强脚本
# 通过注册表设置音频增强 $audioPath = "HKCU:\Software\Microsoft\Multimedia\Audio" # 设置低音增强 Set-ItemProperty -Path $audioPath -Name "BassBoost" -Value 1 Set-ItemProperty -Path $audioPath -Name "BassBoostLevel" -Value 30 # 设置响度均衡 Set-ItemProperty -Path $audioPath -Name "LoudnessEqualization" -Value 1
macOS系统
AppleScript + 系统音频设置
-- 使用AppleScript调整系统均衡器
tell application "System Events"
-- 打开声音设置
do shell script "open x-apple.systempreferences:com.apple.Sound"
-- 切换到均衡器标签
tell process "System Preferences"
delay 1
click radio button "均衡器" of tab group 1 of window "声音"
-- 选择预置(如 低音增强)
tell pop up button 1 of group 1
click
click menu item "低音增强" of menu 1
end tell
end tell
end tell
Shell + EQMac工具
#!/bin/bash
# 使用EQMac命令调整均衡器
# 检查EQMac是否安装
if [ -d "/Applications/EQMac.app" ]; then
# 设置低音增强预置
echo "set bass-boost on" | eqmac-cli
echo "set bass-level 20" | eqmac-cli
# 设置自定义EQ
echo "set-eq -f 31.5 freq -g -6 gain" | eqmac-cli
echo "set-eq -f 63 freq -g -3 gain" | eqmac-cli
echo "set-eq -f 125 freq -g -1 gain" | eqmac-cli
echo "set-eq -f 250 freq -g 0 gain" | eqmac-cli
echo "set-eq -f 500 freq -g 1 gain" | eqmac-cli
else
echo "EQMac未安装,请先下载安装"
fi
Linux系统
PulseAudio + Python脚本
#!/usr/bin/env python3
import subprocess
import json
def set_equalizer_band(band, gain):
"""设置均衡器频段增益"""
cmd = [
"pactl", "set-sink-volume",
"@DEFAULT_SINK@",
f"{gain}%"
]
# 构造PulseAudio均衡器命令
eq_cmd = [
"pactl", "list", "modules",
"|", "grep", "equalizer"
]
# 使用PulseAudio的均衡器模块
subprocess.run(
["pactl", "load-module", "module-equalizer-sink"],
check=True
)
# 设置频段值
freq_bands = {
31: 0, # 31Hz 补偿
63: 0,
125: 0,
250: 2,
500: 1,
1000: 0,
2000: -1,
4000: -2,
8000: -1,
16000: 0
}
for freq, gain_value in freq_bands.items():
cmd = [
"qdbus", "org.pulseaudio.Server",
"/org/pulseaudio/server/equalizer",
"set-band", str(freq), str(gain_value)
]
subprocess.run(cmd)
# 运行均衡器设置
if __name__ == "__main__":
set_equalizer_band(None, None)
Bash + ALSA均衡器
#!/bin/bash # ALSA均衡器设置脚本 # 需要安装 alsa-tools # 启用均衡器 amixer sset "Equalizer" on # 设置各频段 # 32Hz 频段 amixer sset "EQ Band 1" -3 # 64Hz 频段 amixer sset "EQ Band 2" -2 # 125Hz 频段 amixer sset "EQ Band 3" -1 # 250Hz 频段 amixer sset "EQ Band 4" 0 # 500Hz 频段 amixer sset "EQ Band 5" 2 # 1kHz 频段 amixer sset "EQ Band 6" 3 # 2kHz 频段 amixer sset "EQ Band 7" 2 # 4kHz 频段 amixer sset "EQ Band 8" 1 # 8kHz 频段 amixer sset "EQ Band 9" 0 # 16kHz 频段 amixer sset "EQ Band 10" -1
跨平台解决方案
Python + pyAudio库
import numpy as np
class AudioEqualizer:
def __init__(self, sample_rate=44100):
self.sample_rate = sample_rate
self.bands = {
'bass': (20, 250), # 低频
'mids': (250, 4000), # 中频
'highs': (4000, 20000) # 高频
}
def apply_band_gain(self, audio_data, band, gain_db):
"""对特定频段应用增益"""
# 使用FFT处理
spectrum = np.fft.rfft(audio_data)
freqs = np.fft.rfftfreq(len(audio_data), 1/self.sample_rate)
# 频段掩码
freq_range = self.bands[band]
mask = (freqs >= freq_range[0]) & (freqs <= freq_range[1])
# 应用增益
gain_factor = 10 ** (gain_db / 20)
spectrum[mask] *= gain_factor
# 逆FFT
return np.fft.irfft(spectrum)
# 使用示例
eq = AudioEqualizer()
# 加载音频数据
# audio_data = load_audio_data()
# 增强低频
# result = eq.apply_band_gain(audio_data, 'bass', 5)
# 减少高频
# result = eq.apply_band_gain(result, 'highs', -3)
Node.js + Web Audio API
// 使用Web Audio API的脚本
class Equalizer {
constructor(audioContext) {
this.ctx = audioContext;
this.bands = [];
this.createBands();
}
createBands() {
// 创建10段均衡器
const frequencies = [31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, 16000];
for (let i = 0; i < frequencies.length; i++) {
const filter = this.ctx.createBiquadFilter();
filter.type = 'peaking';
filter.frequency.value = frequencies[i];
filter.gain.value = 0;
filter.Q.value = 1;
this.bands.push(filter);
}
// 连接滤波器
for (let i = 1; i < this.bands.length; i++) {
this.bands[i-1].connect(this.bands[i]);
}
}
setBandGain(bandNum, gain) {
if (bandNum >= 0 && bandNum < this.bands.length) {
this.bands[bandNum].gain.value = gain;
}
}
setPreset(type) {
const presets = {
'rock': [5, 4, 3, 1, -1, -1, 2, 3, 4, 3],
'pop': [-1, 2, 3, 2, 0, -1, -1, 2, 3, 2],
'jazz': [3, 2, 1, 2, -1, -1, 0, 1, 2, 3],
'classical': [4, 3, 2, 1, -1, -1, 0, 2, 3, 4]
};
if (presets[type]) {
presets[type].forEach((gain, i) => this.setBandGain(i, gain));
}
}
}
// 初始化
const ctx = new AudioContext();
const eq = new Equalizer(ctx);
eq.setPreset('rock');
使用建议
- 安全备份:调整前务必备份原始配置
- 渐进调整:增益幅度不要过大(建议±3-6dB)
- 测试验证:调整后输出一段测试音进行验证
- 权限处理:脚本可能需要管理员权限
- 硬件兼容:部分声卡不支持某些均衡器功能
选择哪种脚本取决于你的:
- 操作系统
- 音频设备
- 具体需求(系统级/应用级/音频处理)
如果需要更具体的解决方案,请告诉我你的使用场景和系统环境。