iOS build scripts for the Opus Codec - a totally open, royalty-free, highly versatile audio codec.
- ✅ XCFramework with proper Apple Silicon support
- ✅ iOS Device (arm64)
- ✅ iOS Simulator (arm64 for Apple Silicon + x86_64 for Intel)
- ✅ Swift Package Manager support
- ✅ CocoaPods support
- ✅ Minimum iOS 16.0
Add the package to your Package.swift:
dependencies: [
.package(url: "https://github.com/OnBeep/Opus-iOS.git", from: "1.9.0")
]Or in Xcode:
- Go to File → Add Package Dependencies...
- Enter the repository URL:
https://github.com/OnBeep/Opus-iOS.git - Select the version and add to your target
Add to your Podfile:
pod 'Opus-ios', '~> 1.9'Then run:
pod install- Build the XCFramework (see Building the Library)
- Drag
dependencies/opus.xcframeworkinto your Xcode project - Ensure it's added to your target's Frameworks, Libraries, and Embedded Content
import opus
// Create encoder
var error: Int32 = 0
let encoder = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &error)
// Encode audio
let frameSize: Int32 = 960 // 20ms at 48kHz
var encodedData = [UInt8](repeating: 0, count: 4000)
let pcmData: [Int16] = [] // Your PCM audio samples
let encodedBytes = opus_encode(encoder, pcmData, frameSize, &encodedData, 4000)
// Clean up
opus_encoder_destroy(encoder)#import <opus/opus.h>
// Create encoder
int error;
OpusEncoder *encoder = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &error);
// Encode audio
int frameSize = 960; // 20ms at 48kHz
unsigned char encodedData[4000];
opus_int16 *pcmData = ...; // Your PCM audio samples
int encodedBytes = opus_encode(encoder, pcmData, frameSize, encodedData, 4000);
// Clean up
opus_encoder_destroy(encoder);If you need to rebuild the library from source:
- Xcode Command Line Tools
- Internet connection (to download Opus source if not cached)
Edit build-libopus.sh to set your desired versions:
VERSION="1.5.2" # Opus version
SDKVERSION="26.0" # iOS SDK version (run `xcodebuild -showsdks` to check)
MINIOSVERSION="16.0" # Minimum iOS deployment target./build-libopus.shThis will:
- Download the Opus source tarball (or use cached version from
build/src/) - Cross-compile for iOS Device (arm64)
- Cross-compile for iOS Simulator (arm64 + x86_64)
- Create an XCFramework at
dependencies/opus.xcframework
The build uses /tmp for compilation to avoid permission issues with system directories.
# Check XCFramework structure
ls -la dependencies/opus.xcframework/
# Verify device architecture (arm64)
lipo -info dependencies/opus.xcframework/ios-arm64/opus.framework/opus
# Verify simulator architectures (arm64 + x86_64)
lipo -info dependencies/opus.xcframework/ios-arm64_x86_64-simulator/opus.framework/opus- Sampling rates: 8 to 48 kHz
- Bit-rates: 6 kb/s to 510 kb/s
- Channels: Mono, Stereo, up to 255 channels
- Frame sizes: 2.5 ms to 60 ms
- Applications: VoIP, video conferencing, in-game chat, live music
If you see:
Building for 'iOS-simulator', but linking in object file built for 'iOS'
Solution: Update to version 1.9+ which includes an XCFramework with proper Apple Silicon simulator support.
For older versions, you can:
- Run the simulator with Rosetta (Product → Destination → Destination Architectures → Show Rosetta Destinations)
- Rebuild the library using the updated
build-libopus.shscript
If the build fails with "no such sysroot directory", check your installed SDK:
ls /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/Update SDKVERSION in build-libopus.sh to match your installed SDK.
The build script uses /tmp for compilation to avoid permission issues. If you still encounter problems:
# Check ownership of build directory
ls -la build/
# If owned by root, the build script will automatically use /tmpMIT License - see LICENSE for details.
- Opus Codec by Xiph.Org Foundation & Skype
- Original iOS build scripts by Mike Tigas
- Maintained by OnBeep