A Swift library for converting to and from opus/ogg format

Related tags

Utility swift-ogg
Overview

swift-ogg

This library provides a very simple API to convert between opus/ogg and MPEG4AAC/m4a files. It uses opus's libopus libogg to convert between opus/ogg and linear PCM audio data and native iOS apis to convert between PCM and MPEG4AAC/m4a(but could be very easily adapted to use any other codec/container supported by iOS). Apple's recording and playback APIs from AVFoundation can then be used quite simply with a codec/container pair that iOS natively supports (MPEG4AAC/m4a in this case).

Usage

    let src:URL = ...
    let dest:URL = ...
    let dest2:URL = ...
    do {
        // Convert to OGG
        try OGGConverter.convertM4aFileToOpusOGG(src: src, dest: dest)
        // And back to M4a
        try OGGConverter.convertOpusOGGToM4aFile(src: dest, dest: dest2)
    } catch {
        // handle error
    }

Licence

Portions of the swift-ogg library contain code derived from watson-developer-cloud/swift-sdk under the Apache License 2.0

This project makes use of opus-swift and ogg-swift which package the source code of libopus and libogg as platform independend XCFrameworks. These two projects are under the MIT licence while the underlying libopus and libogg library source themselves are included under the BSD Licence described here

Comments
  • Validate input sample rate for decoding is a valid value as per opus documentation

    Validate input sample rate for decoding is a valid value as per opus documentation

    Fixes https://github.com/vector-im/swift-ogg/issues/4

    The existing code blindly accepted the sample rate in the opus file header(if it was within a specific range).

    However as per the opus documentation:

    Sampling rate to decode at (in Hz). This must be one of 8000, 12000, 16000, 24000, or 48000.

    To fix the issue I have:

    1. Fixed the incorrectly handled optional that was causing a crash before we could read the status error from the attempt to create the decoder. We now throw OpusError.badArgument error if the decoder is nil.
    2. Rather than accepting the sample rate in the header, we now choose the closest valid sample rate to that defined in the header(For example in the bug reported the file had an input sample rate of 44100, this now gets mapped to a valid sample rate of 48000).
    3. Added a test to verify opus files with invalid sample rates are handled correctly.
    opened by langleyd 2
  • The library is making assumptions about the source file format.

    The library is making assumptions about the source file format.

    Describe the bug As described in https://github.com/vector-im/element-ios/issues/6603, OGGConverter and OGGDecoder make assumptions about the format of the file, in particular that the file is mono. This can result in incorrect decoding and playback when a user tries to play an opus file that wasn't sent using the voice message functionality.

    To Reproduce See the issue in Element iOS

    Expected behavior The library should determine the format of the audio decode from the file rather than having this hard-coded.

    Smartphone (please complete the following information): iPhone 12 on iOS 15.6.1 running Element 1.8.27

    opened by pixlwave 2
  • Crashes when I use  my   audio.m4a file    replace  VoiceRecordingWeb.m4a  https://github.com/FSilver/Resource/blob/main/audio.m4a

    Crashes when I use my audio.m4a file replace VoiceRecordingWeb.m4a https://github.com/FSilver/Resource/blob/main/audio.m4a

    1. func testConversionRoundTrip() { let src = Bundle.main.url(forResource: "VoiceRecordingWeb", withExtension: "m4a")!

    func testConversionRoundTrip() { let src = Bundle.main.url(forResource: "audio", withExtension: "m4a")!

    1. creashed encoder = opus_encoder_create(opusRate, pcmChannels, application.rawValue, &status)
      OGGEncoder.swift:80: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

    2. AVAudioRecorder [ AVFormatIDKey: NSNumber(value: kAudioFormatMPEG4AAC), AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey : AVAudioQuality.low.rawValue, AVLinearPCMBitDepthKey : 16, AVSampleRateKey : 44100.0 ] use this setting to create audio.m4a 文件地址 https://github.com/FSilver/Resource/blob/main/audio.m4a

    opened by FSilver 1
  • Initial commit for swift-ogg

    Initial commit for swift-ogg

    This PR adds support for converting between opus/ogg and mpeg4aac/m4a files. Most files are opus' own header files. The main files of interest are OGGEncoder and OGGDecoder which were adapted from watson-developer-cloud/swift-sdk. Within that library they were specifcally targeted at the a speed -to-text use case and converted directly to WAV format rather than raw PCM(with no WAV container). This encoder/decoder within this convert directly to linear PCM which is then used in OGGConverted along with apples native AVFAudio and AVFoundation libraries to convert between PCM and mpeg4aac/m4a

    Round-trip conversion tests are added in ConverterTests using a an audio recording of 2 minutes(at the time of writing the max supported for element voice messages).

    opened by langleyd 1
  • let src = Bundle.main.url(forResource:

    let src = Bundle.main.url(forResource: "VoiceRecordingWeb", withExtension: "m4a")!

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by FSilver 0
  • OGG: Unexpectedly found nil while implicitly unwrapping an Optional value

    OGG: Unexpectedly found nil while implicitly unwrapping an Optional value

    // initialize opus encoder
    encoder = opus_encoder_create(opusRate, pcmChannels, application.rawValue, &status)
    

    happening when I encode an m4a file. the exception is thrown in OGGEncoder.swift

    image
    opened by yspreen 2
Owner
Element
We make Element, a decentralised encrypted comms app for the Matrix.org ecosystem
Element
MetricTime is designed to be one universal timekeeping system that eliminates the hassle of calculating time since most of its convertions as simple as converting meters to centimeters

MetricTime MetricTime is designed to be one universal timekeeping system that eliminates the hassle of calculating time since most of its convertions

Adrian Edwards 4 Feb 10, 2022
Swift library and command line tool that interacts with the mach-o file format.

MachO-Reader Playground project to learn more about the Mach-O file format. How to run swift run MachO-Reader <path-to-binary> You should see a simila

Gonzalo 5 Jun 25, 2022
Swift implementation of the QOI Format

Swift-QOI Swift implementation of the QOI Format. Contains extensions for AppKit and UIKit to integrate into your projects with ease. Documentation //

Amy While 18 Oct 21, 2022
Swift implementation of the QOI Format

Swift-QOI Swift implementation of the QOI Format. Contains extensions for AppKit and UIKit to integrate into your projects with ease. Documentation //

Amy While 1 Dec 9, 2021
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Focus is an Optics library for Swift (where Optics includes Lens, Prisms, and Isos)

Focus Focus is an Optics library for Swift (where Optics includes Lens, Prisms, and Isos) that is inspired by Haskell's Lens library. Introduction Foc

TypeLift 201 Dec 31, 2022
A Swift micro library for generating Sunrise and Sunset times.

Solar A Swift helper for generating Sunrise and Sunset times. Solar performs its calculations locally using an algorithm from the United States Naval

Chris Howell 493 Dec 25, 2022
Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Apple 4.1k Dec 28, 2022
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Zamzam Inc. 261 Dec 15, 2022
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.

Mechanica A library of Swift utils to ease your iOS, macOS, watchOS, tvOS and Linux development. Requirements Documentation Installation License Contr

Alessandro 28 Aug 28, 2022
A μframework of extensions for SequenceType in Swift 2.0, inspired by Python's itertools, Haskell's standard library, and other things.

SwiftSequence Full reference here. (If you're looking for data structures in Swift, those have been moved to here) SwiftSequence is a lightweight fram

Donnacha Oisín Kidney 376 Oct 12, 2022
swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

kelvin 4 Aug 14, 2022
ZIP Foundation is a library to create, read and modify ZIP archive files.

ZIP Foundation is a library to create, read and modify ZIP archive files. It is written in Swift and based on Apple's libcompression for high performa

Thomas Zoechling 1.9k Dec 27, 2022
Butterfly is a lightweight library for integrating bug-report and feedback features with shake-motion event.

Butterfly is a lightweight library for integrating bug-report and feedback features with shake-motion event. Goals of this project One of th

Zigii Wong 410 Sep 9, 2022
📘A library for isolated developing UI components and automatically taking snapshots of them.

A library for isolated developing UI components and automatically taking snapshots of them. Playbook Playbook is a library that provides a sandbox for

Playbook 969 Dec 27, 2022
Hammer is a touch, stylus and keyboard synthesis library for emulating user interaction events

Hammer is a touch, stylus and keyboard synthesis library for emulating user interaction events. It enables better ways of triggering UI actions in unit tests, replicating a real world environment as much as possible.

Lyft 626 Dec 23, 2022
Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data.

Pigeon ?? Introduction Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data. It is heavily inspired by React Qu

Fernando Martín Ortiz 369 Dec 30, 2022
μ-library enabling if/else and switch statements to be used as expressions.

swift-expression Many languages such as Scala, Rust and Kotlin support using if/else and switch statements as expressions – meaning that they can by t

Nikita Mounier 1 Nov 8, 2021
macOS system library in Swift

SystemKit A macOS system library in Swift based off of libtop, from Apple's top implementation. For an example usage of this library, see dshb, a macO

null 323 Jan 5, 2023