{"id":13572469,"url":"https://github.com/exPHAT/SwiftWhisper","last_synced_at":"2025-04-04T10:30:31.440Z","repository":{"id":149513270,"uuid":"620611450","full_name":"exPHAT/SwiftWhisper","owner":"exPHAT","description":"🎤 The easiest way to transcribe audio in Swift","archived":false,"fork":false,"pushed_at":"2024-05-23T04:20:11.000Z","size":737,"stargazers_count":658,"open_issues_count":11,"forks_count":81,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-04T06:02:43.858Z","etag":null,"topics":["ios","macos","openai","speech-recognition","speech-to-text","swift","transcription","whisper","whisper-cpp"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/exPHAT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-29T02:53:01.000Z","updated_at":"2025-04-04T04:00:14.000Z","dependencies_parsed_at":"2024-01-06T17:21:35.658Z","dependency_job_id":"1c5bd3ce-9549-46da-9ef9-02e0ab9d0b64","html_url":"https://github.com/exPHAT/SwiftWhisper","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftWhisper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftWhisper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftWhisper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftWhisper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exPHAT","download_url":"https://codeload.github.com/exPHAT/SwiftWhisper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157283,"owners_count":20893220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","macos","openai","speech-recognition","speech-to-text","swift","transcription","whisper","whisper-cpp"],"created_at":"2024-08-01T14:01:24.094Z","updated_at":"2025-04-04T10:30:31.392Z","avatar_url":"https://github.com/exPHAT.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# SwiftWhisper\n\n\u003e The easiest way to use Whisper in Swift\n\nEasily add transcription to your app or package. Powered by [whisper.cpp](https://github.com/ggerganov/whisper.cpp).\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FexPHAT%2FSwiftWhisper%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/exPHAT/SwiftWhisper)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FexPHAT%2FSwiftWhisper%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/exPHAT/SwiftWhisper)\n\n## Install\n\n\n#### Swift Package Manager\n\nAdd SwiftWhisper as a dependency in your `Package.swift` file:\n\n```swift\nlet package = Package(\n  ...\n  dependencies: [\n    // Add the package to your dependencies\n    .package(url: \"https://github.com/exPHAT/SwiftWhisper.git\", branch: \"master\"),\n  ],\n  ...\n  targets: [\n    // Add SwiftWhisper as a dependency on any target you want to use it in\n    .target(name: \"MyTarget\",\n            dependencies: [.byName(name: \"SwiftWhisper\")])\n  ]\n  ...\n)\n```\n\n#### Xcode\n\nAdd `https://github.com/exPHAT/SwiftWhisper.git` in the [\"Swift Package Manager\" tab.](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app)\n\n## Usage\n\n[API Documentation.](https://swiftpackageindex.com/exPHAT/SwiftWhisper/1.0.1/documentation/)\n\n```swift\nimport SwiftWhisper\n\nlet whisper = Whisper(fromFileURL: /* Model file URL */)\nlet segments = try await whisper.transcribe(audioFrames: /* 16kHz PCM audio frames */)\n\nprint(\"Transcribed audio:\", segments.map(\\.text).joined())\n```\n\n#### Delegate methods\n\nYou can subscribe to segments, transcription progress, and errors by implementing `WhisperDelegate` and setting `whisper.delegate = ...`\n\n```swift\nprotocol WhisperDelegate {\n  // Progress updates as a percentage from 0-1\n  func whisper(_ aWhisper: Whisper, didUpdateProgress progress: Double)\n\n  // Any time a new segments of text have been transcribed\n  func whisper(_ aWhisper: Whisper, didProcessNewSegments segments: [Segment], atIndex index: Int)\n  \n  // Finished transcribing, includes all transcribed segments of text\n  func whisper(_ aWhisper: Whisper, didCompleteWithSegments segments: [Segment])\n\n  // Error with transcription\n  func whisper(_ aWhisper: Whisper, didErrorWith error: Error)\n}\n```\n\n## Misc\n\n### Downloading Models :inbox_tray:\n\nYou can find the pre-trained models [here](https://huggingface.co/ggerganov/whisper.cpp) for download.\n\n### CoreML Support :brain:\n\nTo use CoreML, you'll need to include a CoreML model file with the suffix `-encoder.mlmodelc` under the same name as the whisper model (Example: `tiny.bin` would also sit beside a `tiny-encoder.mlmodelc` file). In addition to the additonal model file, you will also need to use the `Whisper(fromFileURL:)` initializer. You can verify CoreML is active by checking the console output during transcription.\n\n### Converting audio to 16kHz PCM :wrench:\n\nThe easiest way to get audio frames into SwiftWhisper is to use [AudioKit](https://github.com/AudioKit/AudioKit). The following example takes an input audio file, converts and resamples it, and returns an array of 16kHz PCM floats.\n\n```swift\nimport AudioKit\n\nfunc convertAudioFileToPCMArray(fileURL: URL, completionHandler: @escaping (Result\u003c[Float], Error\u003e) -\u003e Void) {\n    var options = FormatConverter.Options()\n    options.format = .wav\n    options.sampleRate = 16000\n    options.bitDepth = 16\n    options.channels = 1\n    options.isInterleaved = false\n\n    let tempURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)\n    let converter = FormatConverter(inputURL: fileURL, outputURL: tempURL, options: options)\n    converter.start { error in\n        if let error {\n            completionHandler(.failure(error))\n            return\n        }\n\n        let data = try! Data(contentsOf: tempURL) // Handle error here\n\n        let floats = stride(from: 44, to: data.count, by: 2).map {\n            return data[$0..\u003c$0 + 2].withUnsafeBytes {\n                let short = Int16(littleEndian: $0.load(as: Int16.self))\n                return max(-1.0, min(Float(short) / 32767.0, 1.0))\n            }\n        }\n\n        try? FileManager.default.removeItem(at: tempURL)\n\n        completionHandler(.success(floats))\n    }\n}\n```\n\n### Development speed boost :rocket:\n\nYou may find the performance of the transcription slow when compiling your app for the `Debug` build configuration. This is because the compiler doesn't fully optimize SwiftWhisper unless the build configuration is set to `Release`.\n\nYou can get around this by installing a version of SwiftWhisper that uses `.unsafeFlags([\"-O3\"])` to force maximum optimization. The easiest way to do this is to use the latest commit on the [`fast`](https://github.com/exPHAT/SwiftWhisper/tree/fast) branch. Alternatively, you can configure your scheme to build in the `Release` configuration.\n\n```swift\n  ...\n  dependencies: [\n    // Using latest commit hash for `fast` branch:\n    .package(url: \"https://github.com/exPHAT/SwiftWhisper.git\", revision: \"deb1cb6a27256c7b01f5d3d2e7dc1dcc330b5d01\"),\n  ],\n  ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FexPHAT%2FSwiftWhisper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FexPHAT%2FSwiftWhisper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FexPHAT%2FSwiftWhisper/lists"}