Argmax Open-Source SDK Swift

repository·main·Indexed 27 days ago

https://github.com/argmaxinc/argmax-oss-swift

A collection of on-device inference frameworks for Apple platforms. It includes WhisperKit for speech-to-text using OpenAI Whisper, SpeakerKit for speaker diarization using Pyannote, and TTSKit for text-to-speech using Qwen-TTS. The SDK provides Swift libraries, a command-line interface, and a local OpenAI-compatible server for audio transcription and translation.

Tokens
6.6K
Snippets
28
Records
43
Agent score
42%

What's inside argmax-oss-swift

  1. Overview of Argmax Open-Source SDK

    main

    The Argmax Open-Source SDK Swift is a collection of turn-key on-device inference frameworks for Apple platforms. It provides three primary kits:

    • WhisperKit: Speech-to-text using OpenAI Whisper.
    • SpeakerKit: Speaker diarization using Pyannote.
    • TTSKit: Text-to-speech using Qwen-TTS.

    Note: For advanced features like real-time transcription with speakers, custom vocabulary, or Android support, use the Argmax Pro SDK.

  2. Configure Package.swift dependencies

    main

    To use the SDK in your Swift package, add the dependency to your Package.swift and then specify the desired product in your target dependencies. You can use the ArgmaxOSS umbrella product or individual kits.

    .target(
        name: "YourApp",
        dependencies: [
            // Import everything at once:
            .product(name: "ArgmaxOSS", package: "argmax-oss-swift"),
    
            // Or pick individual kits:
            // .product(name: "WhisperKit", package: "argmax-oss-swift"),   // speech-to-text
            // .product(name: "TTSKit", package: "argmax-oss-swift"),       // text-to-speech
            // .product(name: "SpeakerKit", package: "argmax-oss-swift"), // speaker diarization
        ]
    ),
  3. Generate API clients from OpenAPI spec

    main

    The local server's OpenAPI specification can be used to generate clients for various languages.

    Generate Python client:

    swift run swift-openapi-generator generate scripts/specs/localserver_openapi.yaml \
      --output-directory python-client \
      --mode client \
      --mode types

    Generate TypeScript client:

    npx @openapitools/openapi-generator-cli generate \
      -i scripts/specs/localserver_openapi.yaml \
      -g typescript-fetch \
      -o typescript-client
  4. Configure the Xcode environment for benchmarks

    main

    The benchmark process uses Fastlane to pass the model name to Xcode via an environment variable. To ensure the environment is set up correctly:

    1. Open the example project: xed Examples/WhisperAX.
    2. Click on the WhisperAX scheme at the top of the Xcode window and select Edit Scheme.
    3. Under Environment Variables, verify there is an entry with MODEL_NAME as the name and $(MODEL_NAME) as the value.
    xed Examples/WhisperAX
  5. Install and use the WhisperKit Swift CLI

    main

    The Swift CLI is useful for testing transcription outside of an Xcode project.

    Setup:

    git clone https://github.com/argmaxinc/argmax-oss-swift.git
    cd argmax-oss-swift
    make setup
    # Download a specific model (requires git-lfs)
    make download-model MODEL=large-v3-v20240930_626MB
    # Or download all models
    make download-models

    Usage:

    # Transcribe a file
    swift run argmax-cli transcribe --model-path "Models/whisperkit-coreml/openai_whisper-large-v3-v20240930_626MB" --audio-path "path/to/your/audio.{wav,mp3,m4a,flac}"
    
    # Stream from microphone
    swift run argmax-cli transcribe --model-path "Models/whisperkit-coreml/openai_whisper-large-v3-v20240930_626MB" --stream
    git clone https://github.com/argmaxinc/argmax-oss-swift.git
    cd argmax-oss-swift
    make setup
    make download-model MODEL=large-v3-v20240930_626MB
  6. Use TTSKit for on-device Text-to-Speech

    main

    TTSKit is a Core ML-based framework for real-time text-to-speech on Apple silicon. It supports macOS 15.0+ and iOS 18.0+.

    Basic Usage: Initialize TTSKit() (which automatically downloads the 0.6B model on first run) and call generate(text:).

    Model Variants:

    • .qwen3TTS_0_6b: Fast, runs on all platforms (~1 GB).
    • .qwen3TTS_1_7b: Higher quality, macOS only (~2.2 GB), supports natural language style instructions.
    import TTSKit
    
    Task {
        let tts = try await TTSKit()
        let result = try await tts.generate(text: "Hello from TTSKit!")
        print("Generated \(result.audioDuration)s of audio at \(result.sampleRate)Hz")
    }
  7. Run the WhisperKit Local OpenAI-compatible Server

    main

    The Argmax CLI includes a local server that implements the OpenAI Audio API for transcription and translation, supporting output streaming.

    Build the server:

    make build-local-server
    # OR
    BUILD_ALL=1 swift build --product argmax-cli

    Start the server:

    # Default settings
    BUILD_ALL=1 swift run argmax-cli serve
    
    # Custom host, port, and model
    BUILD_ALL=1 swift run argmax-cli serve --host 0.0.0.0 --port 8080 --model tiny --verbose

    API Endpoints:

    • POST /v1/audio/transcriptions: Transcribe audio to text.
    • POST /v1/audio/translations: Translate audio to English.
    BUILD_ALL=1 swift run argmax-cli serve --host 0.0.0.0 --port 8080
  8. Run WhisperKit benchmarks

    main

    Benchmarks are managed via a Makefile and executed using Fastlane. You can run different configurations depending on your needs:

    • Debug Mode: Run with DEBUG=true to check for potential errors.
    • Full Mode: Run the standard full benchmark suite.
    • Target Specific Devices: Use the DEVICES option with a comma-separated list of device names (obtained from make list-devices).

    Note: An active developer account and Developer Mode enabled on physical devices are required.