Audio Handler
Analyze, convert, and process audio files.
Supported Formats
| Format | Extensions | Read | Convert | Metadata |
|---|
| MP3 | .mp3 | ✅ | ✅ | ✅ |
| WAV |
.wav | ✅ | ✅ | ✅ |
| FLAC | .flac | ✅ | ✅ | ✅ |
| AAC/M4A | .m4a, .aac | ✅ | ✅ | ✅ |
| OGG | .ogg | ✅ | ✅ | ✅ |
| Opus | .opus | ✅ | ✅ | ✅ |
| WMA | .wma | ✅ | ✅ | ✅ |
| AIFF | .aiff, .aif | ✅ | ✅ | ✅ |
Quick Commands
Metadata (ffprobe)
CODEBLOCK0
Convert Formats (ffmpeg)
CODEBLOCK1
Trim & Clip
CODEBLOCK2
Volume & Speed
CODEBLOCK3
Merge & Concatenate
CODEBLOCK4
Extract Audio from Video
CODEBLOCK5
Playback (macOS)
CODEBLOCK6
Text-to-Speech (macOS)
CODEBLOCK7
Scripts
audio_info.sh
Get comprehensive audio metadata.
CODEBLOCK8
convert_audio.sh
Convert between formats with quality options.
CODEBLOCK9
trim_audio.sh
Trim audio with start/end times.
CODEBLOCK10
normalize_audio.sh
Normalize volume level.
CODEBLOCK11
Quality Guide
| Use Case | Format | Settings |
|---|
| Music archive | FLAC | INLINECODE0 |
| Music portable |
MP3 |
-codec:a libmp3lame -qscale:a 2 |
| Podcast/speech | Opus |
-codec:a libopus -b:a 64k |
| Voice memo | M4A |
-codec:a aac -b:a 128k |
| Uncompressed | WAV |
-codec:a pcm_s16le |
Notes
- -
ffmpeg handles almost all audio formats - INLINECODE6 is fast but may be inaccurate for trimming
- Re-encode (
-af) for precise cuts but takes longer - Opus is best for speech at low bitrates
- Use
loudnorm filter for consistent volume across files
音频处理器
分析、转换和处理音频文件。
支持的格式
| 格式 | 扩展名 | 读取 | 转换 | 元数据 |
|---|
| MP3 | .mp3 | ✅ | ✅ | ✅ |
| WAV |
.wav | ✅ | ✅ | ✅ |
| FLAC | .flac | ✅ | ✅ | ✅ |
| AAC/M4A | .m4a, .aac | ✅ | ✅ | ✅ |
| OGG | .ogg | ✅ | ✅ | ✅ |
| Opus | .opus | ✅ | ✅ | ✅ |
| WMA | .wma | ✅ | ✅ | ✅ |
| AIFF | .aiff, .aif | ✅ | ✅ | ✅ |
快速命令
元数据 (ffprobe)
bash
获取所有元数据
ffprobe -v quiet -print
format json -showformat -show_streams audio.mp3
仅获取时长
ffprobe -v error -show
entries format=duration -of default=noprintwrappers=1:nokey=1 audio.mp3
获取比特率
ffprobe -v error -show
entries format=bitrate -of default=noprint_wrappers=1:nokey=1 audio.mp3
获取采样率和声道数
ffprobe -v error -select
streams a:0 -showentries stream=sample
rate,channels -of default=noprintwrappers=1 audio.mp3
人类可读信息
ffprobe -hide_banner audio.mp3
格式转换 (ffmpeg)
bash
转换为MP3(高质量)
ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3
转换为MP3(指定比特率)
ffmpeg -i input.wav -codec:a libmp3lame -b:a 192k output.mp3
转换为WAV(未压缩)
ffmpeg -i input.mp3 output.wav
转换为FLAC(无损)
ffmpeg -i input.wav output.flac
转换为M4A/AAC
ffmpeg -i input.wav -codec:a aac -b:a 256k output.m4a
转换为OGG Vorbis
ffmpeg -i input.wav -codec:a libvorbis -qscale:a 5 output.ogg
转换为Opus(最适合语音)
ffmpeg -i input.wav -codec:a libopus -b:a 64k output.opus
裁剪与截取
bash
裁剪音频(从30秒到90秒)
ffmpeg -i input.mp3 -ss 30 -to 90 -c copy output.mp3
从开头裁剪指定时长
ffmpeg -i input.mp3 -t 60 -c copy output.mp3 # 前60秒
重新编码裁剪(更精确)
ffmpeg -i input.mp3 -ss 30 -to 90 output.mp3
音量与速度
bash
调整音量(2倍音量)
ffmpeg -i input.mp3 -af volume=2 output.mp3
降低音量(一半)
ffmpeg -i input.mp3 -af volume=0.5 output.mp3
标准化音频
ffmpeg -i input.mp3 -af loudnorm output.mp3
加速(1.5倍)
ffmpeg -i input.mp3 -af atempo=1.5 output.mp3
减速(0.75倍)
ffmpeg -i input.mp3 -af atempo=0.75 output.mp3
合并与拼接
bash
拼接音频文件
ffmpeg -i concat:part1.mp3|part2.mp3|part3.mp3 -acodec copy output.mp3
使用文件列表合并
echo file part1.mp3 > list.txt
echo file part2.mp3 >> list.txt
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp3
混合两个音轨
ffmpeg -i voice.mp3 -i music.mp3 -filter_complex amix=inputs=2:duration=longest output.mp3
从视频中提取音频
bash
提取音轨
ffmpeg -i video.mp4 -vn -acodec copy audio.aac
提取并转换
ffmpeg -i video.mp4 -vn -acodec libmp3lame -b:a 192k audio.mp3
播放 (macOS)
bash
播放音频文件
afplay audio.mp3
带音量播放(0.0到1.0)
afplay -v 0.5 audio.mp3
后台播放
afplay audio.mp3 &
停止播放
killall afplay
文字转语音 (macOS)
bash
朗读文本
say 你好,这是一个测试
保存到文件
say -o output.aiff 这段文字将被保存为音频
列出语音
say -v ?
使用特定语音
say -v Tingting 你好,我是婷婷
转换为MP3
say -o temp.aiff 要转换的文字 && ffmpeg -i temp.aiff output.mp3 && rm temp.aiff
脚本
audio_info.sh
获取全面的音频元数据。
bash
~/Dropbox/jarvis/skills/audio-handler/scripts/audio_info.sh <音频文件>
convert_audio.sh
带质量选项的格式转换。
bash
~/Dropbox/jarvis/skills/audio-handler/scripts/convert_audio.sh <输入文件> <输出文件> [质量]
trim_audio.sh
带开始/结束时间的音频裁剪。
bash
~/Dropbox/jarvis/skills/audio-handler/scripts/trim_audio.sh <输入文件> <输出文件> <开始时间> <结束时间>
normalize_audio.sh
标准化音量级别。
bash
~/Dropbox/jarvis/skills/audio-handler/scripts/normalize_audio.sh <输入文件> <输出文件>
质量指南
| 使用场景 | 格式 | 设置 |
|---|
| 音乐存档 | FLAC | -codec:a flac |
| 便携音乐 |
MP3 | -codec:a libmp3lame -qscale:a 2 |
| 播客/语音 | Opus | -codec:a libopus -b:a 64k |
| 语音备忘录 | M4A | -codec:a aac -b:a 128k |
| 未压缩 | WAV | -codec:a pcm_s16le |
备注
- - ffmpeg 几乎支持所有音频格式
- -c copy 速度快,但裁剪时可能不精确
- 重新编码(-af)可实现精确裁剪,但耗时更长
- Opus 在低比特率下最适合语音
- 使用 loudnorm 滤镜可统一不同文件的音量