audio-converter
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAudio Converter
音频转换器
Convert audio files between popular formats with control over quality settings. Supports batch processing and maintains metadata where possible.
在不同主流音频格式之间转换文件,可控制质量设置。支持批量处理,并尽可能保留元数据。
Quick Start
快速开始
python
from scripts.audio_converter import AudioConverterpython
from scripts.audio_converter import AudioConverterSimple conversion
简单转换
converter = AudioConverter("input.wav")
converter.convert("output.mp3")
converter = AudioConverter("input.wav")
converter.convert("output.mp3")
With quality settings
带质量设置的转换
converter = AudioConverter("input.flac")
converter.bitrate(320).sample_rate(44100).convert("output.mp3")
converter = AudioConverter("input.flac")
converter.bitrate(320).sample_rate(44100).convert("output.mp3")
Batch convert directory
批量转换目录
AudioConverter.batch_convert("./input_folder", "./output_folder", format="mp3", bitrate=192)
undefinedAudioConverter.batch_convert("./input_folder", "./output_folder", format="mp3", bitrate=192)
undefinedFeatures
功能特性
- Format Support: MP3, WAV, FLAC, OGG, M4A/AAC, AIFF
- Quality Control: Bitrate, sample rate, channels
- Metadata Preservation: Copy tags when possible
- Batch Processing: Convert entire directories
- Normalization: Optional volume normalization
- 格式支持:MP3、WAV、FLAC、OGG、M4A/AAC、AIFF
- 质量控制:比特率、采样率、声道数
- 元数据保留:尽可能复制标签信息
- 批量处理:转换整个目录下的文件
- 音量归一化:可选的音量归一化功能
API Reference
API参考
Initialization
初始化
python
undefinedpython
undefinedFrom file
从文件初始化
converter = AudioConverter("audio.wav")
undefinedconverter = AudioConverter("audio.wav")
undefinedSettings
设置
python
converter.bitrate(192) # kbps (for lossy formats)
converter.sample_rate(44100) # Hz
converter.channels(2) # 1=mono, 2=stereo
converter.normalize(True) # Normalize volumepython
converter.bitrate(192) # 千比特每秒(适用于有损格式)
converter.sample_rate(44100) # 赫兹
converter.channels(2) # 1=单声道,2=立体声
converter.normalize(True) # 启用音量归一化Conversion
转换操作
python
undefinedpython
undefinedConvert to format (inferred from extension)
根据扩展名推断格式进行转换
converter.convert("output.mp3")
converter.convert("output.mp3")
Explicit format
显式指定格式
converter.convert("output", format="mp3")
undefinedconverter.convert("output", format="mp3")
undefinedBatch Processing
批量处理
python
undefinedpython
undefinedConvert all files in directory
转换目录下所有文件
AudioConverter.batch_convert(
input_dir="./wavs",
output_dir="./mp3s",
format="mp3",
bitrate=320
)
undefinedAudioConverter.batch_convert(
input_dir="./wavs",
output_dir="./mp3s",
format="mp3",
bitrate=320
)
undefinedCLI Usage
CLI使用方法
bash
undefinedbash
undefinedSimple conversion
简单转换
python audio_converter.py --input song.wav --output song.mp3
python audio_converter.py --input song.wav --output song.mp3
With quality settings
带质量设置的转换
python audio_converter.py --input song.flac --output song.mp3 --bitrate 320 --sample-rate 44100
python audio_converter.py --input song.flac --output song.mp3 --bitrate 320 --sample-rate 44100
Batch convert
批量转换
python audio_converter.py --input-dir ./wavs --output-dir ./mp3s --format mp3 --bitrate 192
python audio_converter.py --input-dir ./wavs --output-dir ./mp3s --format mp3 --bitrate 192
Normalize during conversion
转换时启用音量归一化
python audio_converter.py --input song.wav --output song.mp3 --normalize
undefinedpython audio_converter.py --input song.wav --output song.mp3 --normalize
undefinedCLI Arguments
CLI参数
| Argument | Description | Default |
|---|---|---|
| Input audio file | Required |
| Output file path | Required |
| Input directory for batch | - |
| Output directory for batch | - |
| Output format | From extension |
| Bitrate in kbps | 192 |
| Sample rate in Hz | Original |
| Number of channels | Original |
| Normalize volume | False |
| 参数 | 描述 | 默认值 |
|---|---|---|
| 输入音频文件 | 必填 |
| 输出文件路径 | 必填 |
| 批量转换的输入目录 | - |
| 批量转换的输出目录 | - |
| 输出格式 | 从扩展名推断 |
| 比特率(千比特每秒) | 192 |
| 采样率(赫兹) | 原文件采样率 |
| 声道数量 | 原文件声道数 |
| 启用音量归一化 | False |
Supported Formats
支持的格式
| Format | Extension | Type | Notes |
|---|---|---|---|
| MP3 | .mp3 | Lossy | Most compatible |
| WAV | .wav | Lossless | Large files |
| FLAC | .flac | Lossless | Compressed lossless |
| OGG | .ogg | Lossy | Open format |
| M4A | .m4a | Lossy | AAC codec |
| AIFF | .aiff | Lossless | Apple format |
| 格式 | 扩展名 | 类型 | 说明 |
|---|---|---|---|
| MP3 | .mp3 | 有损 | 兼容性最广 |
| WAV | .wav | 无损 | 文件体积大 |
| FLAC | .flac | 无损 | 压缩型无损格式 |
| OGG | .ogg | 有损 | 开源格式 |
| M4A | .m4a | 有损 | AAC编码 |
| AIFF | .aiff | 无损 | Apple格式 |
Examples
示例
Convert WAV to MP3
将WAV转换为MP3
python
converter = AudioConverter("recording.wav")
converter.bitrate(320).convert("recording.mp3")python
converter = AudioConverter("recording.wav")
converter.bitrate(320).convert("recording.mp3")Convert FLAC to Multiple Formats
将FLAC转换为多种格式
python
source = AudioConverter("album.flac")python
source = AudioConverter("album.flac")High quality MP3
高品质MP3
source.bitrate(320).convert("album_hq.mp3")
source.bitrate(320).convert("album_hq.mp3")
Standard MP3
标准品质MP3
source.bitrate(192).convert("album_std.mp3")
source.bitrate(192).convert("album_std.mp3")
OGG for streaming
适用于流媒体的OGG格式
source.bitrate(128).convert("album.ogg")
undefinedsource.bitrate(128).convert("album.ogg")
undefinedBatch Convert for Podcast
批量转换播客文件
python
undefinedpython
undefinedConvert all WAV recordings to MP3 with podcast settings
将所有WAV录制文件转换为符合播客设置的MP3
AudioConverter.batch_convert(
input_dir="./raw_episodes",
output_dir="./episodes",
format="mp3",
bitrate=128,
sample_rate=44100,
channels=1 # Mono for podcasts
)
undefinedAudioConverter.batch_convert(
input_dir="./raw_episodes",
output_dir="./episodes",
format="mp3",
bitrate=128,
sample_rate=44100,
channels=1 # 播客使用单声道
)
undefinedDependencies
依赖项
pydub>=0.25.0
soundfile>=0.12.0Note: Requires FFmpeg installed on system for MP3/M4A support.
pydub>=0.25.0
soundfile>=0.12.0注意:系统需安装FFmpeg以支持MP3/M4A格式。
Limitations
限制条件
- Requires FFmpeg for MP3 and M4A formats
- Metadata transfer is best-effort
- Some format combinations may not preserve all tags
- 支持MP3和M4A格式需依赖FFmpeg
- 元数据传输为尽力而为模式
- 部分格式组合可能无法保留所有标签信息