SwiftLAME GH Banner

SwiftLAME 是一个围绕 开源 LAME 项目构建的轻量级 Swift 封装库,用于将音频文件编码为 MP3 格式。创建此项目的目的是为了支持我们的 Producer Toolkit macOS App 的 MP3 转换功能。

要求

SwiftLAME 已经在 macOS 12+ 和 iOS 15+ 上进行了测试,尽管可能也支持更旧的版本。如果您发现确实如此,请考虑向 Package.swift 贡献更改。

安装

将依赖项添加到您的 Package.swift 文件中

dependencies: [
    .package(url: "https://github.com/hidden-spectrum/swiftlame", .upToNextMajor(from: "0.1.0")),
]

用法

import SwiftLAME

let progress = Progress()
let lameEncoder = try SwiftLameEncoder(
    sourceUrl: URL("file:///path/to/source/file.wav"), 
    configuration: .init(
        sampleRate: .constant(44100)
        bitrateMode: .constant(320)
        quality: .mp3Best
    ),
    destinationUrl: URL("file:///path/to/destination/file.wav"),
    progress: progress // optional
)
try await lameEncoder.encode(priority: .userInitiated)

源编解码器支持

SwiftLAME 支持从以下编解码器进行转换

注意

许可证

SwiftLAME,就像 LAME 项目一样,是根据 LGPL 许可证分发的。