├── Scripts ├── say.scpt ├── VOCursor.scpt └── VOScreenshot.scpt ├── VOCR ├── Assets.xcassets │ ├── Contents.json │ └── AppIcon.appiconset │ │ ├── icon_16x16.png │ │ ├── icon_32x32.png │ │ ├── icon_128x128.png │ │ ├── icon_16x16@2x.png │ │ ├── icon_256x256.png │ │ ├── icon_32x32@2x.png │ │ ├── icon_512x512.png │ │ ├── icon_128x128@2x.png │ │ ├── icon_256x256@2x.png │ │ ├── icon_512x512@2x.png │ │ └── Contents.json ├── VOCR.entitlements ├── Engines.swift ├── Bundle Extension.swift ├── NSRunningApplication Extension.swift ├── Shortcut.swift ├── Double Extension.swift ├── AboutViewController.swift ├── Player.swift ├── KeychainManager.swift ├── Observation.swift ├── LlamaCpp.swift ├── FileLogger.swift ├── Info.plist ├── RealTime.swift ├── Accessibility.swift ├── UIElement Extension.swift ├── AppDelegate.swift ├── gpt.swift ├── Ollama.swift ├── AXUIElement Extension.swift ├── AutoUpdateManager.swift ├── OCRTextSearch.swift ├── ShortcutsWindowController.swift ├── MacCamera.swift ├── Shortcuts.swift ├── Utils.swift ├── Navigation.swift └── Settings.swift ├── docs ├── _config.yml ├── _includes │ └── youtube.html ├── appcast.xml ├── VOCR_v2.3.1.html └── README.md ├── uninstall.command ├── VOCR.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── swiftpm │ │ └── Package.resolved ├── xcshareddata │ └── xcschemes │ │ └── VOCR.xcscheme └── project.pbxproj ├── com.chikim.VOCR.plist ├── Shortcuts.json ├── release.py ├── .gitignore ├── readme.md └── LICENSE /Scripts/say.scpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/Scripts/say.scpt -------------------------------------------------------------------------------- /Scripts/VOCursor.scpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/Scripts/VOCursor.scpt -------------------------------------------------------------------------------- /Scripts/VOScreenshot.scpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/Scripts/VOScreenshot.scpt -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | markdown: kramdown # kramdown or GFM 2 | title: VOCR 3 | description: Enhancing Accessibility with Seamless Screen Recognition -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_16x16.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_32x32.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_128x128.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_256x256.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_512x512.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chigkim/VOCR/HEAD/VOCR/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png -------------------------------------------------------------------------------- /uninstall.command: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | brew uninstall --ignore-dependencies --force imagemagick 3 | brew uninstall --ignore-dependencies --force tesseract-lang 4 | brew uninstall --ignore-dependencies --force tesseract 5 | -------------------------------------------------------------------------------- /VOCR.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VOCR.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /VOCR/VOCR.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.automation.apple-events 6 | 7 | com.apple.security.device.camera 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /VOCR/Engines.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | protocol EngineAsking { 4 | static func ask(image: CGImage) 5 | static func describe(image: CGImage, system: String, prompt: String, completion: @escaping (String) -> Void) 6 | } 7 | 8 | enum Engines: Int { 9 | case gpt = 0, ollama, llamaCpp 10 | } 11 | 12 | func getEngine(for engine: Engines) -> EngineAsking.Type { 13 | switch engine { 14 | case .gpt: 15 | return GPT.self 16 | case .ollama: 17 | return Ollama.self 18 | case .llamaCpp: 19 | return LlamaCpp.self 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /docs/_includes/youtube.html: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | -------------------------------------------------------------------------------- /VOCR/Bundle Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Bundle Extension.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 10/15/19. 6 | // Copyright © 2019 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension Bundle { 12 | 13 | var releaseVersionNumber: String? { 14 | return infoDictionary?["CFBundleShortVersionString"] as? String 15 | } 16 | 17 | var buildVersionNumber: String? { 18 | return infoDictionary?["CFBundleVersion"] as? String 19 | } 20 | 21 | var version: String { 22 | return "v\(releaseVersionNumber!).\(buildVersionNumber!)" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /com.chikim.VOCR.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | New item 6 | Media.xcassets 7 | KeepAlive 8 | 9 | SuccessfulExit 10 | 11 | Label 12 | com.chikim.VOCR 13 | LimitLoadToSessionType 14 | Aqua 15 | Program 16 | /Applications/VOCR.app/Contents/MacOS/VOCR 17 | RunAtLoad 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /VOCR/NSRunningApplication Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSRunningApplication Extension.swift 3 | // Inspector 4 | // 5 | // Created by Chi Kim on 10/28/18. 6 | // Copyright © 2018 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | extension NSRunningApplication { 12 | func windows() -> [AXUIElement] { 13 | let appRef = AXUIElementCreateApplication(self.processIdentifier) 14 | var windowList:CFTypeRef? 15 | AXUIElementCopyAttributeValue(appRef, "AXWindows" as CFString, &windowList) 16 | if windowList != nil { 17 | return windowList as! [AXUIElement] 18 | } else { 19 | return []} 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /VOCR/Shortcut.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Shortcut.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/11/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import Carbon.HIToolbox.Events // Import this to use Carbon keycodes 11 | 12 | struct Shortcut: Codable { 13 | var name: String 14 | var key: UInt32 15 | var modifiers:UInt32 16 | var keyName:String { 17 | get { 18 | if let event = createKeyEvent(keyCode: key, keyModifiers: modifiers) { 19 | return event.modifierFlags.description+event.charactersIgnoringModifiers! 20 | } else { 21 | return "Unassigned" 22 | } 23 | } 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /VOCR/Double Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Double Extension.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 10/12/19. 6 | // Copyright © 2019 Chi Kim. All rights reserved. 7 | // 8 | 9 | public extension Double { 10 | func normalize(from: ClosedRange, into: ClosedRange) -> Double { 11 | let fromMaxMinusMin = from.upperBound - from.lowerBound 12 | let intoMaxMinusMin = into.upperBound - into.lowerBound 13 | return Swift.max( 14 | into.lowerBound, 15 | Swift.min( 16 | into.upperBound, 17 | (self - from.lowerBound) / fromMaxMinusMin * intoMaxMinusMin + into.lowerBound 18 | ) 19 | ) 20 | 21 | } 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /VOCR/AboutViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 7/29/19. 6 | // Copyright © 2019 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | 12 | class AboutViewController: NSViewController, NSWindowDelegate { 13 | 14 | @IBOutlet var info: NSTextField! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | info.stringValue = "\(Bundle.main.version)" 19 | // Do any additional setup after loading the view. 20 | } 21 | 22 | override func viewDidAppear() { 23 | super.viewDidAppear() 24 | if let window = self.view.window { 25 | window.delegate = self 26 | } 27 | } 28 | 29 | override var representedObject: Any? { 30 | didSet { 31 | // Update the view, if already loaded. 32 | } 33 | } 34 | 35 | func windowWillClose(_ notification: Notification) { 36 | NSApplication.shared.hide(nil) 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /docs/appcast.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | VOCR 5 | 6 | 2.3.1 7 | Tue, 06 May 2025 19:04:15 -0400 8 | 49 9 | 2.3.1 10 | 13.0 11 | https://chigkim.github.io/VOCR/VOCR_v2.3.1.html 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /VOCR/Player.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Player.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 10/12/19. 6 | // Copyright © 2019 Chi Kim. All rights reserved. 7 | // 8 | 9 | import AudioKit 10 | import SoundpipeAudioKit 11 | import AVFoundation 12 | 13 | class Player { 14 | 15 | static let shared = Player() 16 | 17 | let osc:PinkNoise 18 | let panner:Panner 19 | let eq:BandPassButterworthFilter 20 | let env:AmplitudeEnvelope 21 | let ramp:Float = 0.1 22 | let engine = AudioEngine() 23 | 24 | init() { 25 | osc = PinkNoise(amplitude: 1.0) 26 | 27 | env = AmplitudeEnvelope(osc) 28 | env.attackDuration = 0.05 29 | env.decayDuration = 0.05 30 | env.sustainLevel = 0.8 31 | env.releaseDuration = 0.05 32 | env.start() 33 | 34 | eq = BandPassButterworthFilter(env) 35 | eq.bandwidth = 100 36 | 37 | let mixer = Mixer(eq) 38 | panner = Panner(mixer) 39 | 40 | osc.start() 41 | engine.output = panner 42 | try! engine.start() 43 | mixer.volume = 1.0 44 | } 45 | 46 | func play(_ freq:Float, _ pan:Float) { 47 | eq.$centerFrequency.ramp(to:freq, duration:ramp) 48 | panner.$pan.ramp(to: pan, duration: ramp) 49 | env.openGate() 50 | usleep(100000) 51 | env.closeGate() 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /VOCR/KeychainManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // KeychainManager.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/19/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Security 11 | 12 | class KeychainManager { 13 | 14 | @discardableResult 15 | static func store(key: String, data: Data) -> OSStatus { 16 | let query = [ 17 | kSecClass as String: kSecClassGenericPassword, 18 | kSecAttrAccount as String: key, 19 | kSecValueData as String: data, 20 | kSecAttrAccessible as String: kSecAttrAccessibleWhenUnlocked] as [String : Any] 21 | 22 | SecItemDelete(query as CFDictionary) // Remove any existing item with the same key 23 | return SecItemAdd(query as CFDictionary, nil) 24 | } 25 | 26 | static func retrieve(key: String) -> Data? { 27 | let query = [ 28 | kSecClass as String: kSecClassGenericPassword, 29 | kSecAttrAccount as String: key, 30 | kSecReturnData as String: kCFBooleanTrue as Any, 31 | kSecMatchLimit as String: kSecMatchLimitOne] as [String : Any] 32 | 33 | var itemCopy: AnyObject? 34 | let status = SecItemCopyMatching(query as CFDictionary, &itemCopy) 35 | 36 | if status == noErr, let data = itemCopy as? Data { 37 | return data 38 | } else { 39 | return nil 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Shortcuts.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"keyName":"⌃⇧⌘S","key":1,"modifiers":4864,"name":"Settings"}, 3 | {"keyName":"⌃⇧⌘W","key":13,"modifiers":4864,"name":"OCR Window"}, 4 | {"keyName":"⌃⇧⌘V","key":9,"modifiers":4864,"name":"OCR VOCursor"}, 5 | {"keyName":"⌃⇧⌘C","key":8,"modifiers":4864,"name":"Capture Camera"}, 6 | {"keyName":"⌃⇧⌘E","key":14,"modifiers":4864,"name":"Explore"}, 7 | {"keyName":"⌃⇧⌘A","key":0,"modifiers":4864,"name":"Ask"}, 8 | {"keyName":"⌃⇧⌘R","key":15,"modifiers":4864,"name":"Realtime OCR"}, 9 | {"keyName":"⌃⌘","key":124,"modifiers":4352,"name":"Right"}, 10 | {"keyName":"⌃⌘","key":123,"modifiers":4352,"name":"Left"}, 11 | {"keyName":"⌃⌘","key":125,"modifiers":4352,"name":"Down"}, 12 | {"keyName":"⌃⌘","key":126,"modifiers":4352,"name":"Up"}, 13 | {"keyName":"⌃⌘","key":115,"modifiers":4352,"name":"Beginning"}, 14 | {"keyName":"⌃⌘","key":119,"modifiers":4352,"name":"End"}, 15 | {"keyName":"⌃⌘","key":116,"modifiers":4352,"name":"Top"}, 16 | {"keyName":"⌃⌘","key":121,"modifiers":4352,"name":"Bottom"}, 17 | {"keyName":"⌃⇧⌘","key":124,"modifiers":4864,"name":"Next Character"}, 18 | {"keyName":"⌃⇧⌘","key":123,"modifiers":4864,"name":"Previous Character"}, 19 | {"keyName":"⌃⌘l","key":37,"modifiers":4352,"name":"Report Location"}, 20 | {"keyName":"⌃⌘i","key":34,"modifiers":4352,"name":"Identify Object"}, 21 | {"keyName":"⌃⌘f","key":3,"modifiers":4352,"name":"Find Text"}, 22 | {"keyName":"⌃⌘g","key":5,"modifiers":4352,"name":"Find Next"}, 23 | {"keyName":"⌃⇧⌘g","key":5,"modifiers":4864,"name":"Find Previous"}, 24 | {"keyName":"\u001b","key":53,"modifiers":0,"name":"Exit Navigation"} 25 | ] 26 | -------------------------------------------------------------------------------- /VOCR/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | }, 6 | "images" : [ 7 | { 8 | "idiom" : "mac", 9 | "filename" : "icon_16x16.png", 10 | "scale" : "1x", 11 | "size" : "16x16" 12 | }, 13 | { 14 | "size" : "16x16", 15 | "scale" : "2x", 16 | "filename" : "icon_16x16@2x.png", 17 | "idiom" : "mac" 18 | }, 19 | { 20 | "idiom" : "mac", 21 | "scale" : "1x", 22 | "size" : "32x32", 23 | "filename" : "icon_32x32.png" 24 | }, 25 | { 26 | "filename" : "icon_32x32@2x.png", 27 | "scale" : "2x", 28 | "idiom" : "mac", 29 | "size" : "32x32" 30 | }, 31 | { 32 | "scale" : "1x", 33 | "filename" : "icon_128x128.png", 34 | "size" : "128x128", 35 | "idiom" : "mac" 36 | }, 37 | { 38 | "scale" : "2x", 39 | "size" : "128x128", 40 | "idiom" : "mac", 41 | "filename" : "icon_128x128@2x.png" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "256x256", 46 | "scale" : "1x", 47 | "filename" : "icon_256x256.png" 48 | }, 49 | { 50 | "size" : "256x256", 51 | "idiom" : "mac", 52 | "scale" : "2x", 53 | "filename" : "icon_256x256@2x.png" 54 | }, 55 | { 56 | "size" : "512x512", 57 | "idiom" : "mac", 58 | "scale" : "1x", 59 | "filename" : "icon_512x512.png" 60 | }, 61 | { 62 | "scale" : "2x", 63 | "size" : "512x512", 64 | "idiom" : "mac", 65 | "filename" : "icon_512x512@2x.png" 66 | } 67 | ] 68 | } -------------------------------------------------------------------------------- /VOCR/Observation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Observation.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/5/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Vision 11 | struct GPTObservation: Decodable { 12 | let label: String 13 | let uid: Int 14 | let description: String 15 | let content: String 16 | let boundingBox: [Float] 17 | 18 | // Coding keys to match the JSON property names 19 | enum CodingKeys: String, CodingKey { 20 | case label 21 | case uid 22 | case description 23 | case content 24 | case boundingBox 25 | } 26 | } 27 | 28 | 29 | struct Observation { 30 | 31 | var boundingBox:CGRect 32 | var value:String 33 | var vnObservation:VNRecognizedTextObservation? 34 | var gptObservation:GPTObservation? 35 | 36 | init(_ obs:GPTObservation) { 37 | self.gptObservation = obs 38 | self.value = obs.label+"\n"+obs.content+"\n"+obs.description 39 | let x = CGFloat(obs.boundingBox[0]) 40 | let y = CGFloat(obs.boundingBox[1]) 41 | let width = CGFloat(obs.boundingBox[2]) 42 | let height = CGFloat(obs.boundingBox[3]) 43 | var rect = CGRect(x:x, y:y, width:width, height:height) 44 | // rect = VNNormalizedRectForImageRect(rect, Int(Navigation.cgSize.width), Int(Navigation.cgSize.height)) 45 | // rect = CGRect(x:rect.minX, y:1-rect.maxY, width:rect.width, height:rect.height) 46 | self.boundingBox = rect 47 | } 48 | 49 | init(_ obs:VNRecognizedTextObservation) { 50 | self.vnObservation = obs 51 | self.value = obs.topCandidates(1)[0].string 52 | self.boundingBox = obs.boundingBox 53 | } 54 | 55 | init(_ obs:VNRectangleObservation, value:String) { 56 | self.boundingBox = obs.boundingBox 57 | self.value = value 58 | } 59 | 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /VOCR/LlamaCpp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LlamaCpp.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/11/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | 10 | import Cocoa 11 | 12 | enum LlamaCpp:EngineAsking { 13 | 14 | struct Response: Decodable { 15 | let content: String 16 | } 17 | 18 | static func ask(image:CGImage) { 19 | LlamaCpp.describe(image:image, system:Settings.systemPrompt, prompt:Settings.prompt) { description in 20 | NSSound(contentsOfFile: "/System/Library/Sounds/Pop.aiff", byReference: true)?.play() 21 | sleep(1) 22 | Accessibility.speak(description) 23 | } 24 | } 25 | 26 | static func describe(image: CGImage, system:String, prompt: String, completion: @escaping (String) -> Void) { 27 | let base64_image = imageToBase64(image: image) 28 | let jsonBody: [String: Any] = [ 29 | "temperature": 0.1, 30 | "prompt": "USER: [img-1]\n\(prompt)\nASSISTANT:", 31 | "image_data": [ 32 | [ 33 | "data": base64_image, 34 | "id": 1 35 | ] 36 | ], 37 | "n_predict": 4096 38 | ] 39 | let jsonData = try! JSONSerialization.data(withJSONObject: jsonBody, options: []) 40 | let url = URL(string: "http://127.0.0.1:8080/completion")! 41 | var request = URLRequest(url: url) 42 | request.httpBody = jsonData 43 | performRequest(&request, name:"Llama.Cpp") { data in 44 | log("Llama: \(String(data: data, encoding: .utf8)!)") 45 | do { 46 | let response = try JSONDecoder().decode(Response.self, from: data) 47 | let description = response.content 48 | copyToClipboard(description) 49 | completion(description) 50 | } catch { 51 | Accessibility.speakWithSynthesizer("Error decoding JSON: \(error)") 52 | completion("Error: Could not parse JSON.") 53 | } 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /VOCR/FileLogger.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FileLogger.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/16/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class FileLogger { 12 | static let shared = FileLogger() 13 | 14 | private let fileURL: URL 15 | private var fileHandle: FileHandle? 16 | private let queue = DispatchQueue(label: "com.yourapp.filelogger", qos: .background) 17 | 18 | init() { 19 | let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! 20 | self.fileURL = documentsDirectory.appendingPathComponent("VOCR.txt") 21 | if FileManager.default.fileExists(atPath: self.fileURL.path) { 22 | try! FileManager.default.removeItem(at: self.fileURL) 23 | } 24 | 25 | } 26 | 27 | deinit { 28 | fileHandle?.closeFile() 29 | } 30 | 31 | private func setupFileHandleIfNeeded() { 32 | if !FileManager.default.fileExists(atPath: self.fileURL.path) { 33 | FileManager.default.createFile(atPath: self.fileURL.path, contents: nil, attributes: nil) 34 | fileHandle = try? FileHandle(forWritingTo: self.fileURL) 35 | } 36 | 37 | if fileHandle == nil { 38 | fileHandle = try? FileHandle(forWritingTo: self.fileURL) 39 | } 40 | } 41 | 42 | func write(_ message: String) { 43 | setupFileHandleIfNeeded() 44 | 45 | queue.async { [weak self] in 46 | guard let self = self, Settings.writeLog else { return } 47 | 48 | guard let data = message.data(using: .utf8) else { return } 49 | self.fileHandle?.seekToEndOfFile() 50 | self.fileHandle?.write(data) 51 | } 52 | } 53 | func log(_ message: String) { 54 | let timestamp = Date().description 55 | let logMessage = "\(timestamp)\n\(message)\n" 56 | print(logMessage) 57 | if Settings.writeLog { 58 | write(logMessage) 59 | } 60 | } 61 | 62 | func read() -> String? { 63 | return try? String(contentsOf: fileURL, encoding: .utf8) 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /VOCR.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "originHash" : "8b1cd6dfb6155b6ecc9ff40b0f01cb92ba45eafc6fd3ff8f4709d4884640a36f", 3 | "pins" : [ 4 | { 5 | "identity" : "audiokit", 6 | "kind" : "remoteSourceControl", 7 | "location" : "https://github.com/AudioKit/AudioKit", 8 | "state" : { 9 | "revision" : "82cab9d4c168b5b03b67e2ff099819f589b530f7", 10 | "version" : "5.6.2" 11 | } 12 | }, 13 | { 14 | "identity" : "audiokitex", 15 | "kind" : "remoteSourceControl", 16 | "location" : "https://github.com/AudioKit/AudioKitEX", 17 | "state" : { 18 | "revision" : "58fa4a002028a2addf96466dd5ad68182e7d387e", 19 | "version" : "5.6.0" 20 | } 21 | }, 22 | { 23 | "identity" : "axswift", 24 | "kind" : "remoteSourceControl", 25 | "location" : "https://github.com/tmandry/AXSwift", 26 | "state" : { 27 | "branch" : "main", 28 | "revision" : "e18a18453d135ad45809a384ee5139e05ea52def" 29 | } 30 | }, 31 | { 32 | "identity" : "hotkey", 33 | "kind" : "remoteSourceControl", 34 | "location" : "https://github.com/soffes/HotKey", 35 | "state" : { 36 | "revision" : "31234dfbb4330b90ee10d89fbacb77316781cc06", 37 | "version" : "0.2.0" 38 | } 39 | }, 40 | { 41 | "identity" : "kissfft", 42 | "kind" : "remoteSourceControl", 43 | "location" : "https://github.com/AudioKit/KissFFT", 44 | "state" : { 45 | "revision" : "dd0636e151724b8ba2e0908eba4d99a6ff24d00c", 46 | "version" : "1.0.0" 47 | } 48 | }, 49 | { 50 | "identity" : "soundpipeaudiokit", 51 | "kind" : "remoteSourceControl", 52 | "location" : "https://github.com/AudioKit/SoundpipeAudioKit.git", 53 | "state" : { 54 | "revision" : "ee7d9542078ae48b24744a67c0350a12f9de354b", 55 | "version" : "5.6.1" 56 | } 57 | }, 58 | { 59 | "identity" : "sparkle", 60 | "kind" : "remoteSourceControl", 61 | "location" : "https://github.com/sparkle-project/Sparkle", 62 | "state" : { 63 | "revision" : "0ca3004e98712ea2b39dd881d28448630cce1c99", 64 | "version" : "2.7.0" 65 | } 66 | } 67 | ], 68 | "version" : 3 69 | } 70 | -------------------------------------------------------------------------------- /VOCR/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeName 11 | Image files 12 | CFBundleTypeRole 13 | Viewer 14 | LSHandlerRank 15 | Owner 16 | LSItemContentTypes 17 | 18 | public.image 19 | 20 | 21 | 22 | CFBundleExecutable 23 | $(EXECUTABLE_NAME) 24 | CFBundleIconFile 25 | 26 | CFBundleIdentifier 27 | $(PRODUCT_BUNDLE_IDENTIFIER) 28 | CFBundleInfoDictionaryVersion 29 | 6.0 30 | CFBundleName 31 | $(PRODUCT_NAME) 32 | CFBundlePackageType 33 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 34 | CFBundleShortVersionString 35 | $(MARKETING_VERSION) 36 | CFBundleVersion 37 | $(CURRENT_PROJECT_VERSION) 38 | LSApplicationCategoryType 39 | public.app-category.utilities 40 | LSMinimumSystemVersion 41 | $(MACOSX_DEPLOYMENT_TARGET) 42 | LSUIElement 43 | 44 | NSAppTransportSecurity 45 | 46 | NSAllowsArbitraryLoads 47 | 48 | 49 | NSAppleEventsUsageDescription 50 | Speak announcements and take Screenshot under VoiceOver cursor 51 | NSCameraUsageDescription 52 | Capture a photo to VOCR to use. 53 | NSHumanReadableCopyright 54 | Copyright © 2019 Chi Kim. All rights reserved. 55 | NSMainStoryboardFile 56 | Main 57 | NSPrincipalClass 58 | NSApplication 59 | NSSupportsAutomaticTermination 60 | 61 | NSSupportsSuddenTermination 62 | 63 | NSUserNotificationAlertStyle 64 | alert 65 | SUFeedURL 66 | https://chigkim.github.io/VOCR/appcast.xml 67 | SUPublicEDKey 68 | ofVGoHbzXlM0JFWqISYkWokIdXAtq9gJu7hMnbKLY0E= 69 | 70 | 71 | -------------------------------------------------------------------------------- /VOCR/RealTime.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RealTime.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/9/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Vision 11 | import Cocoa 12 | 13 | enum RealTime { 14 | 15 | static var run:Bool = false 16 | 17 | static func performOCR(cgImage:CGImage) -> [VNRecognizedTextObservation]? { 18 | let textRecognitionRequest = VNRecognizeTextRequest() 19 | textRecognitionRequest.recognitionLevel = VNRequestTextRecognitionLevel.accurate 20 | textRecognitionRequest.minimumTextHeight = 0 21 | textRecognitionRequest.usesLanguageCorrection = true 22 | textRecognitionRequest.customWords = [] 23 | textRecognitionRequest.usesCPUOnly = false 24 | textRecognitionRequest.cancel() 25 | let requestHandler = VNImageRequestHandler(cgImage: cgImage, options: [:]) 26 | do { 27 | try requestHandler.perform([textRecognitionRequest]) 28 | } catch _ {} 29 | guard let texts = textRecognitionRequest.results else { 30 | return [] 31 | } 32 | return texts 33 | } 34 | 35 | static func diff(old:String, new:String) -> String? { 36 | let oldArray = old.lowercased().components(separatedBy: .whitespaces) 37 | let newArray = new.lowercased().components(separatedBy: .whitespaces) 38 | let difference = newArray.difference(from: oldArray) 39 | let insertedTexts = difference.compactMap { 40 | if case .insert(_, let element, _) = $0 { 41 | return element 42 | } else { return nil } 43 | } 44 | 45 | if insertedTexts.isNotEmpty { 46 | return insertedTexts.joined(separator: " ") 47 | } 48 | return nil 49 | } 50 | 51 | static func continuousOCR() { 52 | DispatchQueue.global(qos: .background).async { 53 | var rect:CGRect? 54 | if Navigation.mode == .WINDOW { 55 | rect = Navigation.getWindow() 56 | } else { 57 | rect = Navigation.getVOCursor() 58 | } 59 | if let rect = rect { 60 | var oldText = "" 61 | while run { 62 | if let cgImage = TakeScreensShots(rect: rect) { 63 | if let texts = performOCR(cgImage:cgImage) { 64 | let newText = texts.map { $0.topCandidates(1)[0].string }.joined(separator: " ") 65 | if let insertedText = diff(old:oldText, new:newText) { 66 | oldText = newText 67 | Accessibility.speak(insertedText) 68 | } 69 | } 70 | } 71 | Thread.sleep(forTimeInterval: 0.5) 72 | // NSSound(contentsOfFile: "/System/Library/Sounds/Tink.aiff", byReference: true)?.play() 73 | } 74 | } 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /VOCR/Accessibility.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Accessibility.swift 3 | // Inspector 4 | // 5 | // Created by Chi Kim on 10/29/18. 6 | // Copyright © 2018 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import Carbon 11 | 12 | enum Accessibility { 13 | 14 | static let speech:NSSpeechSynthesizer = NSSpeechSynthesizer() 15 | 16 | 17 | static func isTrusted(ask:Bool) -> Bool { 18 | let prompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString 19 | let options = [prompt: ask] 20 | return AXIsProcessTrustedWithOptions(options as CFDictionary?) 21 | } 22 | 23 | static func notify(_ message:String) { 24 | let announcement = [NSAccessibility.NotificationUserInfoKey.announcement:message, NSAccessibility.NotificationUserInfoKey.priority:"High"] 25 | let element = NSApplication.shared as Any 26 | NSAccessibility.post(element:element, notification: NSAccessibility.Notification.announcementRequested, userInfo: announcement) 27 | } 28 | 29 | static func speakWithSynthesizer(_ message:String) { 30 | log("Speak with synthesizer: \(message)") 31 | DispatchQueue.global().async { 32 | speech.startSpeaking(message) 33 | } 34 | } 35 | 36 | static func isVoiceOverRunning() -> Bool { 37 | let runningApplications = NSWorkspace.shared.runningApplications 38 | for app in runningApplications { 39 | if app.localizedName == "VoiceOver" { 40 | return true 41 | } 42 | } 43 | return false 44 | } 45 | 46 | static func speak(_ message:String) { 47 | if !isVoiceOverRunning() { 48 | speakWithSynthesizer(message) 49 | return 50 | } 51 | 52 | let bundle = Bundle.main 53 | let url = bundle.url(forResource: "say", withExtension: "scpt") 54 | let parameters = NSAppleEventDescriptor.list() 55 | parameters.insert(NSAppleEventDescriptor(string: message), at: 0) 56 | let event = NSAppleEventDescriptor.appleEvent(withEventClass: AEEventClass(kASAppleScriptSuite), eventID: AEEventID(kASSubroutineEvent), targetDescriptor: nil, returnID: AEReturnID(kAutoGenerateReturnID), transactionID: AETransactionID(kAnyTransactionID)) 57 | event.setDescriptor(NSAppleEventDescriptor(string: "speak"), forKeyword: AEKeyword(keyASSubroutineName)) 58 | event.setDescriptor(parameters, forKeyword: AEKeyword(keyDirectObject)) 59 | var error:NSDictionary? 60 | if let scriptObject = NSAppleScript(contentsOf: url!, error: &error) { 61 | var outputError:NSDictionary? 62 | if let output = scriptObject.executeAppleEvent(event, error: &outputError).stringValue { 63 | debugPrint(outputError) 64 | log("Speak: \(output)") 65 | } else { 66 | log("Output Error: \(String(describing: outputError))") 67 | } 68 | } else { 69 | log("\(error!)") 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /VOCR/UIElement Extension.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // UIElement Extension.swift 4 | // FloTools 5 | // 6 | // Created by Chi Kim on 2/3/19. 7 | // Copyright © 2019 Chi Kim. All rights reserved. 8 | // 9 | 10 | import Foundation 11 | import Cocoa 12 | import AXSwift 13 | 14 | extension Array where Element == UIElement { 15 | func filter(role:Role) -> [UIElement] { 16 | return filter {try! $0.role()! == role} 17 | } 18 | 19 | func filter(title:String) -> [UIElement] { 20 | return filter { 21 | if let regex = try? NSRegularExpression(pattern: title, options: .caseInsensitive) { 22 | let value = $0.title! 23 | if let result = regex.firstMatch(in:value, range:NSRange(value.startIndex..., in:value)) { 24 | return true 25 | } 26 | } 27 | return false 28 | } 29 | } 30 | 31 | } 32 | 33 | extension UIElement { 34 | 35 | var children:[UIElement] { 36 | get { 37 | guard let AXElements:[AXUIElement] = try! attribute(.children) else { 38 | return [] 39 | } 40 | let elements = AXElements.map {UIElement($0)} 41 | return elements 42 | } 43 | } 44 | 45 | var title:String? { 46 | get { 47 | if let value:String = try! attribute(.title) { 48 | return value 49 | } 50 | return nil 51 | } 52 | } 53 | 54 | var elementDescription:String? { 55 | get { 56 | if let value:String = try! attribute(.description) { 57 | return value 58 | } 59 | return nil 60 | } 61 | } 62 | 63 | var valueDescription:String? { 64 | get { 65 | if let value:String = try! attribute(.valueDescription) { 66 | return value 67 | } 68 | return nil 69 | } 70 | } 71 | 72 | var value:String? { 73 | get { 74 | if let value:Any = try! attribute(.value) { 75 | 76 | return String(describing: value) 77 | 78 | } 79 | return nil 80 | } 81 | } 82 | 83 | var label:String? { 84 | get { 85 | var roleName = "Unknown: " 86 | if let roleStr = try! role()?.rawValue { 87 | let start = roleStr.index(roleStr.startIndex, offsetBy: 2) 88 | roleName = roleStr[start...]+": " 89 | } 90 | var name = "" 91 | if title != nil { 92 | name = title! 93 | } else if elementDescription != nil { 94 | name = elementDescription! 95 | } else if valueDescription != nil { 96 | name = valueDescription! 97 | } else if value != nil { 98 | name = String(describing:value) 99 | } 100 | return name+" "+roleName 101 | } 102 | } 103 | 104 | var parent:UIElement? { 105 | get { 106 | if let parent:UIElement = try! attribute(.parent) { 107 | return parent 108 | } 109 | return nil 110 | } 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /VOCR/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import Sparkle 3 | import UserNotifications 4 | 5 | @NSApplicationMain 6 | class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate { 7 | 8 | let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) 9 | var autoUpdateManager:AutoUpdateManager? 10 | 11 | func applicationDidFinishLaunching(_ notification: Notification) { 12 | killInstance() 13 | menuNeedsUpdate(NSMenu()) 14 | Shortcuts.SetupShortcuts() 15 | if let button = statusItem.button { 16 | button.title = "VOCR" 17 | button.action = #selector(click(_:)) 18 | } 19 | NSApp.setActivationPolicy(.accessory) 20 | setupAutoLaunch() 21 | hide() 22 | Accessibility.speak("VOCR Ready!") 23 | NSSound(contentsOfFile: "/System/Library/Sounds/Blow.aiff", byReference: true)?.play() 24 | autoUpdateManager = AutoUpdateManager.shared 25 | } 26 | 27 | func killInstance() { 28 | let appId = Bundle.main.bundleIdentifier! 29 | let runningApps = NSWorkspace.shared.runningApplications 30 | for app in runningApps { 31 | if app.bundleIdentifier == appId && app != NSRunningApplication.current { 32 | app.forceTerminate() 33 | } 34 | } 35 | } 36 | 37 | func setupAutoLaunch() { 38 | let fileManager = FileManager.default 39 | let home = fileManager.homeDirectoryForCurrentUser 40 | let launchFolder = home.appendingPathComponent("Library/LaunchAgents") 41 | if !fileManager.fileExists(atPath: launchFolder.path) { 42 | try! fileManager.createDirectory(at: launchFolder, withIntermediateDirectories: false, attributes: nil) 43 | } 44 | let launchPath = "Library/LaunchAgents/com.chikim.VOCR.plist" 45 | let launchFile = home.appendingPathComponent(launchPath) 46 | if !Settings.launchOnBoot && !fileManager.fileExists(atPath: launchFile.path) { 47 | let bundle = Bundle.main 48 | let bundlePath = bundle.path(forResource: "com.chikim.VOCR", ofType: "plist") 49 | try! fileManager.copyItem(at: URL(fileURLWithPath: bundlePath!), to: launchFile) 50 | Settings.launchOnBoot = true 51 | Settings.save() 52 | } 53 | } 54 | 55 | @objc func click(_ sender: Any?) { 56 | log("Menu Clicked") 57 | } 58 | 59 | func menuNeedsUpdate(_ menu: NSMenu) { 60 | let menu = Settings.setupMenu() 61 | menu.delegate = self 62 | statusItem.menu = menu 63 | } 64 | 65 | func applicationWillTerminate(_ notification: Notification) { 66 | Settings.removeMouseMonitor() 67 | } 68 | 69 | func application(_ sender: NSApplication, openFile filename: String) -> Bool { 70 | let fileURL = URL(fileURLWithPath: filename) 71 | if let image = NSImage(contentsOf: fileURL) { 72 | var rect = CGRect(origin: .zero, size: image.size) 73 | if let cgImage = image.cgImage(forProposedRect: &rect, context: nil, hints: nil) { 74 | ask(image:cgImage) 75 | 76 | return true // Indicate success 77 | } else { 78 | return false 79 | } 80 | } 81 | return false 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /VOCR/gpt.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import Cocoa 3 | 4 | enum GPT:EngineAsking { 5 | 6 | struct Response: Decodable { 7 | struct Usage:Decodable { 8 | let prompt_tokens:Int 9 | let completion_tokens:Int 10 | let total_tokens:Int 11 | } 12 | 13 | struct Choice: Decodable { 14 | struct Message: Decodable { 15 | let content: String 16 | } 17 | 18 | let message: Message 19 | } 20 | let usage:Usage 21 | let choices: [Choice] 22 | } 23 | 24 | static func ask(image:CGImage) { 25 | GPT.describe(image:image, system:Settings.systemPrompt, prompt:Settings.prompt) { description in 26 | NSSound(contentsOfFile: "/System/Library/Sounds/Pop.aiff", byReference: true)?.play() 27 | sleep(1) 28 | Accessibility.speak(description) 29 | } 30 | } 31 | 32 | static func describe(image: CGImage, system:String, prompt:String, completion: @escaping (String) -> Void) { 33 | if Settings.GPTAPIKEY == "" { 34 | Settings.displayApiKeyDialog() 35 | } 36 | if Settings.GPTAPIKEY == "" { 37 | return 38 | } 39 | let base64_image = imageToBase64(image: image) 40 | 41 | let jsonBody: [String: Any] = [ 42 | "model": "gpt-4.1", 43 | "messages": [ 44 | [ 45 | "role": "system", 46 | "content": system 47 | ], 48 | [ 49 | "role": "user", 50 | "content": [ 51 | [ 52 | "type": "text", 53 | "text": prompt 54 | ], 55 | [ 56 | "type": "image_url", 57 | "image_url": [ 58 | "url": "data:image/jpeg;base64,\(base64_image)" 59 | ] 60 | ] 61 | ] 62 | ] 63 | ], 64 | "max_tokens": 4096 65 | ] 66 | 67 | let jsonData = try! JSONSerialization.data(withJSONObject: jsonBody, options: []) 68 | 69 | 70 | let url = URL(string: "https://api.openai.com/v1/chat/completions")! 71 | var request = URLRequest(url: url) 72 | request.setValue("Bearer \(Settings.GPTAPIKEY)", forHTTPHeaderField: "Authorization") 73 | request.httpBody = jsonData 74 | performRequest(&request, name:"GPT") { data in 75 | log("GPT-4V: \(String(data: data, encoding: .utf8)!)") 76 | do { 77 | let response = try JSONDecoder().decode(Response.self, from: data) 78 | let prompt_tokens = response.usage.prompt_tokens 79 | let completion_tokens = response.usage.completion_tokens 80 | let total_tokens = response.usage.total_tokens 81 | let cost = Float(prompt_tokens)*(200.0/1000000.0)+Float(completion_tokens)*(800.0/1000000.0) 82 | if let firstChoice = response.choices.first { 83 | var description = firstChoice.message.content 84 | description += "\nPrompt tokens: \(prompt_tokens)" 85 | description += "\nCompletion tokens: \(completion_tokens)" 86 | description += "\nTotal tokens: \(total_tokens)" 87 | description += "\nCost: \(cost) cents" 88 | copyToClipboard(description) 89 | completion(description) 90 | } 91 | } catch { 92 | Accessibility.speakWithSynthesizer("Error decoding JSON: \(error)") 93 | completion("Error: Could not parse JSON.") 94 | } 95 | } 96 | } 97 | } 98 | 99 | -------------------------------------------------------------------------------- /VOCR/Ollama.swift: -------------------------------------------------------------------------------- 1 | 2 | import Cocoa 3 | 4 | enum Ollama:EngineAsking { 5 | 6 | struct Response: Decodable { 7 | let response: String 8 | } 9 | 10 | struct ModelsContainer: Decodable { 11 | struct Model: Decodable { 12 | struct ModelDetails: Codable { 13 | let families: [String]? 14 | } 15 | let details: ModelDetails 16 | let name:String 17 | } 18 | let models:[Model] 19 | } 20 | 21 | 22 | static let ollamaAPIURL = "http://127.0.0.1:11434/api/generate" 23 | static var model:String? 24 | static func setModel() { 25 | let url = "http://127.0.0.1:11434/api/tags" 26 | var request = URLRequest(url: URL(string: url)!) 27 | performRequest(&request, method:"GET") { data in 28 | do { 29 | let response = try JSONDecoder().decode(ModelsContainer.self, from: data) 30 | var models = response.models 31 | // debugPrint(models) 32 | models = models.filter { 33 | if let families = $0.details.families, (families.contains("clip") || families.contains("mllama") || families.contains("gemma3")) { 34 | return true 35 | } else { 36 | return false 37 | } 38 | } 39 | if models.count > 1 { 40 | DispatchQueue.main.async { 41 | let alert = NSAlert() 42 | alert.alertStyle = .informational 43 | alert.messageText = "Choose a Model" 44 | for model in models { 45 | alert.addButton(withTitle: model.name) 46 | } 47 | let modalResult = alert.runModal() 48 | hide() 49 | let n = modalResult.rawValue-1000 50 | Ollama.model = models[n].name 51 | } 52 | } else if models.count == 1 { 53 | model = models[0].name 54 | } 55 | } catch { 56 | Accessibility.speakWithSynthesizer("Error decoding JSON: \(error)") 57 | } 58 | } 59 | } 60 | 61 | static func ask(image:CGImage) { 62 | describe(image:image, system:Settings.systemPrompt, prompt:Settings.prompt) { description in 63 | NSSound(contentsOfFile: "/System/Library/Sounds/Pop.aiff", byReference: true)?.play() 64 | sleep(1) 65 | Accessibility.speak(description) 66 | } 67 | } 68 | 69 | static func describe(image: CGImage, system: String, prompt: String, completion: @escaping (String) -> Void) { 70 | guard let model = model else { 71 | Accessibility.speakWithSynthesizer("Please choose a model for Ollama to use first.") 72 | return 73 | } 74 | let base64Image = imageToBase64(image: image) 75 | let jsonBody: [String: Any] = [ 76 | "model": model, 77 | "prompt": prompt, 78 | "stream": false, 79 | "images": [base64Image] 80 | ] 81 | 82 | let jsonData = try! JSONSerialization.data(withJSONObject: jsonBody, options: []) 83 | var request = URLRequest(url: URL(string: ollamaAPIURL)!) 84 | request.httpBody = jsonData 85 | performRequest(&request, name:model) { data in 86 | do { 87 | let response = try JSONDecoder().decode(Response.self, from: data) 88 | let description = response.response 89 | copyToClipboard(description) 90 | completion(description) 91 | } catch { 92 | Accessibility.speakWithSynthesizer("Error decoding JSON: \(error)") 93 | completion("Error: Could not parse JSON.") 94 | } 95 | } 96 | } 97 | 98 | } 99 | 100 | -------------------------------------------------------------------------------- /VOCR/AXUIElement Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AXUIElement Extension.swift 3 | // Inspector 4 | // 5 | // Created by Chi Kim on 10/28/18. 6 | // Copyright © 2018 Chi Kim. All rights reserved. 7 | // 8 | 9 | 10 | import ApplicationServices 11 | 12 | extension AXUIElement { 13 | 14 | func attributes() -> [String] { 15 | var cfArray: CFArray? 16 | let error = AXUIElementCopyAttributeNames(self, &cfArray) 17 | if error == .success, let names = cfArray as? [String] { 18 | return names 19 | } 20 | return [] 21 | } 22 | 23 | func parameterizedAttributes() -> [String] { 24 | var cfArray: CFArray? 25 | let error = AXUIElementCopyParameterizedAttributeNames(self, &cfArray) 26 | if error == .success, let names = cfArray as? [String] { 27 | return names 28 | } else if error == .attributeUnsupported { 29 | return ["Error attribute not supported"] 30 | } else if error == .noValue { 31 | return ["Error no value"] 32 | } else if error == .illegalArgument { 33 | return ["Error illegal arguement"] 34 | } else if error == .invalidUIElement { 35 | return ["Error invalud ui element"] 36 | } else if error == .cannotComplete { 37 | return ["Error cannot complete"] 38 | } else if error == .notImplemented { 39 | return ["Error not implemented"] 40 | } else { 41 | return ["Error Unknown"] 42 | } 43 | } 44 | 45 | 46 | 47 | 48 | 49 | func value(of:String) -> String{ 50 | var cfValue:CFTypeRef? 51 | let error = AXUIElementCopyAttributeValue(self, of as CFString, &cfValue) 52 | if error == .success { 53 | /* 54 | let axValue = cfValue as! AXValue 55 | let type = AXValueGetType(axValue) 56 | var atrPtr:UnsafeMutableRawPointer? 57 | AXValueGetValue(axValue, type, &atrPtr) 58 | if let attribute = atrPtr as? String { 59 | } 60 | 61 | let attribute = "" 62 | var attributePtr = UnsafeMutableRawPointer(Unmanaged.passUnretained(attribute as AnyObject).toOpaque()) 63 | AXValueGetValue(axValue, type, &attributePtr) 64 | if let value = Unmanaged.fromOpaque(attributePtr).takeUnretainedValue() as? String { 65 | } 66 | */ 67 | 68 | guard let axValue = cfValue as? String else { 69 | return String( reflecting:cfValue).trimmingCharacters(in: .whitespacesAndNewlines) 70 | } 71 | return axValue 72 | } else if error == .attributeUnsupported { 73 | return "Error attribute not supported" 74 | } else if error == .noValue { 75 | return "Error no value" 76 | } else if error == .illegalArgument { 77 | return "Error illegal arguement" 78 | } else if error == .invalidUIElement { 79 | return "Error invalud ui element" 80 | } else if error == .cannotComplete { 81 | return "Error cannot complete" 82 | } else if error == .notImplemented { 83 | return "Error not implemented" 84 | } else { 85 | return "Error Unknown" 86 | } 87 | } 88 | 89 | func children() -> [AXUIElement] { 90 | var children:CFTypeRef? 91 | var error:AXError? 92 | if self.value(of:"AXRole") == "AXTable" { 93 | error = AXUIElementCopyAttributeValue(self, "AXRows" as CFString, &children) 94 | } else { 95 | error = AXUIElementCopyAttributeValue(self, "AXChildren" as CFString, &children) 96 | } 97 | if error == .success, let elements = children as? [AXUIElement] { 98 | return elements 99 | } 100 | return [] 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /VOCR/AutoUpdateManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AutoUpdateManager.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/18/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Cocoa 11 | import Sparkle 12 | import UserNotifications 13 | 14 | class AutoUpdateManager: NSObject, SPUUpdaterDelegate, SPUStandardUserDriverDelegate, UNUserNotificationCenterDelegate { 15 | 16 | static let shared = AutoUpdateManager() 17 | var updaterController: SPUStandardUpdaterController? 18 | private let UPDATE_NOTIFICATION_IDENTIFIER = "VOCRUpdateCheck" 19 | var supportsGentleScheduledUpdateReminders: Bool { 20 | return true 21 | } 22 | 23 | private override init() { 24 | super.init() 25 | UNUserNotificationCenter.current().delegate = self 26 | self.updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: self, userDriverDelegate: self) 27 | if let automaticallyChecksForUpdates = self.updaterController?.updater.automaticallyChecksForUpdates, automaticallyChecksForUpdates { 28 | self.updaterController?.updater.checkForUpdatesInBackground() 29 | } 30 | } 31 | 32 | func checkForUpdates() { 33 | updaterController?.checkForUpdates(nil) 34 | } 35 | 36 | func allowedChannels(for updater: SPUUpdater) -> Set { 37 | // if Settings.preRelease { 38 | // updater.updateCheckInterval = 3600 39 | // } else { 40 | // updater.updateCheckInterval = 3600*24 41 | // } 42 | 43 | if Settings.preRelease { 44 | log("Download pre-release.") 45 | return Set(["pre"]) 46 | } else { 47 | log("No pre-release.") 48 | return Set() 49 | } 50 | } 51 | 52 | func updater(_ updater: SPUUpdater, willScheduleUpdateCheckAfterDelay delay: TimeInterval) { 53 | UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) { granted, error in 54 | // Examine granted outcome and error if desired... 55 | } 56 | } 57 | 58 | func standardUserDriverWillHandleShowingUpdate(_ handleShowingUpdate: Bool, forUpdate update: SUAppcastItem, state: SPUUserUpdateState) { 59 | NSApp.setActivationPolicy(.regular) 60 | if !state.userInitiated { 61 | NSApp.dockTile.badgeLabel = "1" 62 | do { 63 | let content = UNMutableNotificationContent() 64 | content.title = "A new update is available" 65 | content.body = "Version \(update.displayVersionString) is now available" 66 | content.sound = UNNotificationSound.default 67 | let request = UNNotificationRequest(identifier: UPDATE_NOTIFICATION_IDENTIFIER, content: content, trigger: nil) 68 | UNUserNotificationCenter.current().add(request) 69 | } 70 | } 71 | } 72 | 73 | func standardUserDriverDidReceiveUserAttention(forUpdate update: SUAppcastItem) { 74 | NSApp.dockTile.badgeLabel = "" 75 | UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [UPDATE_NOTIFICATION_IDENTIFIER]) 76 | } 77 | 78 | func standardUserDriverWillFinishUpdateSession() { 79 | NSApp.setActivationPolicy(.accessory) 80 | } 81 | 82 | func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { 83 | if response.notification.request.identifier == UPDATE_NOTIFICATION_IDENTIFIER && response.actionIdentifier == UNNotificationDefaultActionIdentifier { 84 | updaterController?.checkForUpdates(nil) 85 | } 86 | completionHandler() 87 | } 88 | 89 | } 90 | 91 | -------------------------------------------------------------------------------- /release.py: -------------------------------------------------------------------------------- 1 | token = input("Github Token:") 2 | owner = 'chigkim' 3 | repo = "VOCR" 4 | archives = "archives" 5 | gen = "~/Library/Developer/Xcode/DerivedData/VOCR-gjsqmtcgzvvuvfcpuxtfgxerxtyc/SourcePackages/artifacts/sparkle/Sparkle/bin/generate_appcast" 6 | 7 | import requests 8 | import os 9 | import codecs 10 | import xml.etree.ElementTree as ET 11 | from glob import glob 12 | import json 13 | import re 14 | import shutil 15 | 16 | def getInfo(file, key): 17 | plist_xml = open(file).read() 18 | root = ET.fromstring(plist_xml) 19 | dict_element = root.find('dict') 20 | for i, child in enumerate(dict_element): 21 | if child.tag == 'key' and child.text == key: 22 | return dict_element[i+1].text 23 | 24 | 25 | app_file = glob(f"{archives}/*.app")[0] 26 | print("App file:", app_file) 27 | app = app_file[app_file.rindex("/")+1:app_file.rindex(".app")] 28 | print("App:", app) 29 | info = app_file+"/Contents/Info.plist" 30 | tag = "v"+getInfo(info, "CFBundleShortVersionString") 31 | print("Tag:", tag) 32 | release_name = f"{repo} {tag}" 33 | print("Release:", release_name) 34 | zip = f"{archives}/{app}_{tag}.zip" 35 | cmd = f"ditto -c -k --sequesterRsrc --keepParent {app_file} {zip}" 36 | os.system(cmd) 37 | shutil.rmtree(app_file) 38 | changelog = glob(f"{archives}/*.md")[0] 39 | release_body = open(changelog).read() 40 | file_path = zip 41 | asset_name = os.path.basename(file_path) # Gets the file name from the path 42 | url_create_release = f'https://api.github.com/repos/{owner}/{repo}/releases' 43 | headers = { 44 | 'Authorization': f'token {token}', 45 | 'Content-Type': 'application/json' 46 | } 47 | data_release = { 48 | 'tag_name': tag, 49 | 'name': release_name, 50 | 'body': release_body, 51 | 'draft': False, 52 | 'prerelease': False 53 | } 54 | print(json.dumps(data_release, indent="\t")) 55 | response_release = requests.post(url_create_release, json=data_release, headers=headers) 56 | if response_release.status_code == 201: 57 | print('Release created successfully!') 58 | note = zip.replace(".zip", ".html") 59 | print(note) 60 | cmd = f"pandoc -s '{changelog}' -o '{note}'" 61 | os.system(cmd) 62 | cmd = f"{gen} {archives}" 63 | os.system(cmd) 64 | [os.remove("docs/"+file) for file in os.listdir("docs") if ".html" in file] 65 | os.rename(note, note.replace(archives, "docs")) 66 | release_info = response_release.json() 67 | upload_url = release_info['upload_url'].split('{')[0] + '?name=' + asset_name 68 | headers_asset = { 69 | 'Authorization': f'token {token}', 70 | 'Content-Type': 'application/octet-stream' 71 | } 72 | with open(file_path, 'rb') as file: 73 | data_asset = file.read() 74 | response_asset = requests.post(upload_url, headers=headers_asset, data=data_asset) 75 | if response_asset.status_code == 201: 76 | print('Asset uploaded successfully!') 77 | download = response_asset.json()['browser_download_url'] 78 | xml = codecs.open(f"{archives}/appcast.xml", "r", "utf-8").read() 79 | search = re.search(r'url="(.*?)"', xml)[1] 80 | xml = xml.replace(search, download) 81 | with codecs.open("docs/appcast.xml", "w", "utf-8") as file: 82 | file.write(xml) 83 | os.remove(f"{archives}/appcast.xml") 84 | cmd = "git add docs/*" 85 | os.system(cmd) 86 | cmd = f"git commit -a -m {tag}" 87 | os.system(cmd) 88 | else: 89 | print('Failed to upload asset:', response_asset.json()) 90 | else: 91 | print('Failed to create release:', response_release.json()) 92 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/swift,macos 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=swift,macos 3 | 4 | ### macOS ### 5 | # General 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | 10 | # Icon must end with two \r 11 | Icon 12 | 13 | # Thumbnails 14 | ._* 15 | 16 | # Files that might appear in the root of a volume 17 | .DocumentRevisions-V100 18 | .fseventsd 19 | .Spotlight-V100 20 | .TemporaryItems 21 | .Trashes 22 | .VolumeIcon.icns 23 | .com.apple.timemachine.donotpresent 24 | 25 | # Directories potentially created on remote AFP share 26 | .AppleDB 27 | .AppleDesktop 28 | Network Trash Folder 29 | Temporary Items 30 | .apdisk 31 | 32 | ### macOS Patch ### 33 | # iCloud generated files 34 | *.icloud 35 | 36 | ### Swift ### 37 | # Xcode 38 | # 39 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 40 | 41 | ## User settings 42 | xcuserdata/ 43 | 44 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 45 | *.xcscmblueprint 46 | *.xccheckout 47 | 48 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 49 | build/ 50 | DerivedData/ 51 | *.moved-aside 52 | *.pbxuser 53 | !default.pbxuser 54 | *.mode1v3 55 | !default.mode1v3 56 | *.mode2v3 57 | !default.mode2v3 58 | *.perspectivev3 59 | !default.perspectivev3 60 | 61 | ## Obj-C/Swift specific 62 | *.hmap 63 | 64 | ## App packaging 65 | *.ipa 66 | *.dSYM.zip 67 | *.dSYM 68 | 69 | ## Playgrounds 70 | timeline.xctimeline 71 | playground.xcworkspace 72 | 73 | # Swift Package Manager 74 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 75 | # Packages/ 76 | # Package.pins 77 | # Package.resolved 78 | # *.xcodeproj 79 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 80 | # hence it is not needed unless you have added a package configuration file to your project 81 | # .swiftpm 82 | 83 | .build/ 84 | 85 | # CocoaPods 86 | # We recommend against adding the Pods directory to your .gitignore. However 87 | # you should judge for yourself, the pros and cons are mentioned at: 88 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 89 | # Pods/ 90 | # Add this line if you want to avoid checking in source code from the Xcode workspace 91 | # *.xcworkspace 92 | 93 | # Carthage 94 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 95 | # Carthage/Checkouts 96 | 97 | Carthage/Build/ 98 | 99 | # Accio dependency management 100 | Dependencies/ 101 | .accio/ 102 | 103 | # fastlane 104 | # It is recommended to not store the screenshots in the git repo. 105 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 106 | # For more information about the recommended setup visit: 107 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 108 | 109 | fastlane/report.xml 110 | fastlane/Preview.html 111 | fastlane/screenshots/**/*.png 112 | fastlane/test_output 113 | 114 | # Code Injection 115 | # After new code Injection tools there's a generated folder /iOSInjectionProject 116 | # https://github.com/johnno1962/injectionforxcode 117 | 118 | iOSInjectionProject/ 119 | 120 | # End of https://www.toptal.com/developers/gitignore/api/swift,macos 121 | -------------------------------------------------------------------------------- /VOCR.xcodeproj/xcshareddata/xcschemes/VOCR.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 80 | 83 | 84 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /VOCR/OCRTextSearch.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OCRTextSearch.swift 3 | // VOCR 4 | // 5 | // Created by Victor Tsaran on 8/4/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class OCRTextSearch { 12 | static let shared = OCRTextSearch() 13 | private init() {} 14 | 15 | private var lastSearchQuery = "" 16 | 17 | func search(query: String = "", fromBeginning: Bool = false, backward: Bool = false) { 18 | guard !Navigation.displayResults.isEmpty else { 19 | print("No OCR results to search.") 20 | return 21 | } 22 | 23 | let searchQuery = query.isEmpty ? self.getLastSearchQuery() : query 24 | 25 | // Ensure Navigation.l and Navigation.w have valid starting points 26 | var startIndex = (Navigation.l >= 0 && Navigation.l < Navigation.displayResults.count) ? Navigation.l : 0 27 | var startWordIndex = (startIndex >= 0 && startIndex < Navigation.displayResults.count && Navigation.w >= 0 && Navigation.w < Navigation.displayResults[startIndex].count) ? Navigation.w : 0 28 | 29 | if fromBeginning { 30 | startIndex = backward ? Navigation.displayResults.count - 1 : 0 31 | startWordIndex = backward ? Navigation.displayResults[startIndex].count - 1 : 0 32 | } else { 33 | if backward { 34 | startWordIndex -= 1 35 | if startWordIndex < 0 { 36 | startIndex -= 1 37 | if startIndex >= 0 { 38 | startWordIndex = Navigation.displayResults[startIndex].count - 1 39 | } else { 40 | startWordIndex = 0 41 | } 42 | } 43 | } else { 44 | startWordIndex += 1 45 | if startIndex < Navigation.displayResults.count && startWordIndex >= Navigation.displayResults[startIndex].count { 46 | startIndex += 1 47 | startWordIndex = 0 48 | } 49 | } 50 | } 51 | 52 | func isMatch(line: [Observation], wordIndex: Int) -> Bool { 53 | return line[wordIndex].value.localizedCaseInsensitiveContains(searchQuery) 54 | } 55 | 56 | if backward { 57 | var lineIndex = startIndex 58 | while lineIndex >= 0 { 59 | let line = Navigation.displayResults[lineIndex] 60 | let wordCount = line.count 61 | 62 | for wordIndex in stride(from: lineIndex == startIndex ? startWordIndex : wordCount - 1, through: 0, by: -1) { 63 | if isMatch(line: line, wordIndex: wordIndex) { 64 | Navigation.l = lineIndex 65 | Navigation.w = wordIndex 66 | setMouseCoordinates(x: lineIndex, y: wordIndex) 67 | print("Found '\(searchQuery)' at line \(lineIndex + 1), word \(wordIndex + 1)") 68 | Accessibility.speak("\(Navigation.displayResults[lineIndex][wordIndex].value)") 69 | return 70 | } 71 | } 72 | lineIndex -= 1 73 | } 74 | } else { 75 | var lineIndex = startIndex 76 | while lineIndex < Navigation.displayResults.count { 77 | let line = Navigation.displayResults[lineIndex] 78 | let wordCount = line.count 79 | 80 | for wordIndex in (lineIndex == startIndex ? startWordIndex : 0).. String { 134 | return lastSearchQuery 135 | } 136 | 137 | private func setMouseCoordinates(x:Int, y:Int) { 138 | if Settings.moveMouse { 139 | CGWarpMouseCursorPosition(Navigation.convert2coordinates(Navigation.displayResults[x][y].boundingBox)) 140 | } 141 | 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /docs/VOCR_v2.3.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | changelog 8 | 170 | 171 | 172 |

Changelog

173 |
    174 |
  • Only supports MacOSX 13.0 and higher
  • 175 |
  • Automatically detects 18 language: en-US, fr-FR, it-IT, de-DE, 176 | es-ES, pt-BR, zh-Hans, zh-Hant, yue-Hans, yue-Hant, ko-KR, ja-JP, ru-RU, 177 | uk-UA, th-TH, vi-VT, ar-SA, ars-SA
  • 178 |
  • Support for llama-vision and Gemma3 model on Ollama
  • 179 |
  • Update to GPT-4.1
  • 180 |
  • Plays a sound alert before reading the response from LLMs.
  • 181 |
  • Now autoscan detects both left and right clicks; thanks @vick08
  • 183 |
  • Fixed Mac Camera; thanks @vick08
  • 185 |
186 | 187 | 188 | -------------------------------------------------------------------------------- /VOCR/ShortcutsWindowController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ShortcutWindowController.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/10/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Cocoa 11 | import HotKey 12 | 13 | class ShortcutsWindowController: NSWindowController, NSWindowDelegate, NSTableViewDelegate, NSTableViewDataSource { 14 | 15 | static let shared = ShortcutsWindowController() 16 | var tableView: NSTableView! 17 | 18 | 19 | init() { 20 | super.init(window: nil) 21 | setupWindow() 22 | setupTableView() 23 | refreshTable() 24 | window?.contentView?.needsDisplay = true 25 | } 26 | 27 | required init?(coder: NSCoder) { 28 | fatalError("init(coder:) has not been implemented") 29 | } 30 | 31 | private func setupWindow() { 32 | let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 400, height: 300), 33 | styleMask: [.titled, .closable], 34 | backing: .buffered, defer: false) 35 | self.window = window 36 | self.window?.title = "Customize Shortcuts" 37 | self.window?.delegate = self 38 | } 39 | 40 | func windowWillClose(_ notification: Notification) { 41 | NSApplication.shared.hide(nil) 42 | } 43 | 44 | private func setupTableView() { 45 | tableView = NSTableView(frame: self.window!.contentView!.bounds) 46 | tableView.delegate = self 47 | tableView.dataSource = self 48 | let nameColumn = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("NameColumn")) 49 | nameColumn.title = "Name" 50 | tableView.addTableColumn(nameColumn) 51 | let hotkeyColumn = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("HotkeyColumn")) 52 | hotkeyColumn.title = "Hotkey" 53 | tableView.addTableColumn(hotkeyColumn) 54 | self.window?.contentView?.addSubview(tableView) 55 | refreshTable() 56 | } 57 | 58 | func refreshTable() { 59 | DispatchQueue.main.async { 60 | self.tableView.reloadData() 61 | } 62 | } 63 | 64 | func numberOfRows(in tableView: NSTableView) -> Int { 65 | return Shortcuts.shortcuts.count 66 | } 67 | 68 | func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { 69 | let shortcut = Shortcuts.shortcuts[row] 70 | 71 | switch tableColumn?.identifier { 72 | case NSUserInterfaceItemIdentifier("NameColumn"): 73 | let cellView = NSTableCellView(frame: NSRect(x: 0, y: 0, width: tableColumn!.width, height: tableView.rowHeight)) 74 | let textField = NSTextField(frame: cellView.bounds) 75 | textField.stringValue = shortcut.name 76 | textField.isEditable = false 77 | textField.isBezeled = false 78 | textField.drawsBackground = false 79 | textField.autoresizingMask = [.width, .height] // Resize with the cell view 80 | cellView.addSubview(textField) 81 | 82 | return cellView 83 | 84 | case NSUserInterfaceItemIdentifier("HotkeyColumn"): 85 | let cellView = NSTableCellView(frame: NSRect(x: 0, y: 0, width: tableColumn!.width, height: tableView.rowHeight)) 86 | let button = NSButton(frame: NSRect(x: 0, y: 0, width: tableColumn!.width, height: tableView.rowHeight)) 87 | button.title = shortcut.keyName 88 | button.tag = row 89 | button.target = self 90 | button.action = #selector(reassignShortcut(_:)) 91 | cellView.addSubview(button) 92 | 93 | return cellView 94 | 95 | default: 96 | return nil 97 | } 98 | } 99 | 100 | @objc func reassignShortcut(_ sender: NSButton) { 101 | let shortcutIndex = sender.tag 102 | let recorder = ShortcutRecorderView(frame: self.window!.contentView!.bounds) 103 | recorder.onShortcutRecorded = { [weak self] event in 104 | guard let strongSelf = self else { return } 105 | Shortcuts.shortcuts[shortcutIndex].key = UInt32(event.keyCode) 106 | Shortcuts.shortcuts[shortcutIndex].modifiers = event.modifierFlags.carbonFlags 107 | Shortcuts.shortcuts[shortcutIndex].keyName = event.modifierFlags.description+event.charactersIgnoringModifiers! 108 | strongSelf.refreshTable() 109 | let data = try? JSONEncoder().encode(Shortcuts.shortcuts) 110 | UserDefaults.standard.set(data, forKey: "userShortcuts") 111 | Shortcuts.loadShortcuts() 112 | } 113 | 114 | self.window!.contentView!.addSubview(recorder) 115 | self.window!.makeFirstResponder(recorder) 116 | } 117 | 118 | 119 | override func keyDown(with event: NSEvent) { 120 | super.keyDown(with: event) 121 | 122 | if event.keyCode == 51 { // 51 is the key code for the Delete key 123 | deleteSelectedRow() 124 | } 125 | } 126 | 127 | func deleteSelectedRow() { 128 | guard tableView.selectedRow >= 0 else { return } 129 | let row = tableView.selectedRow 130 | 131 | // Remove the shortcut from the array and update UserDefaults 132 | Shortcuts.shortcuts.remove(at: row) 133 | let data = try? JSONEncoder().encode(Shortcuts.shortcuts) 134 | UserDefaults.standard.set(data, forKey: "userShortcuts") 135 | Shortcuts.registerAll() 136 | refreshTable() 137 | } 138 | 139 | } 140 | 141 | 142 | class ShortcutRecorderView: NSView { 143 | var onShortcutRecorded: ((NSEvent) -> Void)? 144 | 145 | override var acceptsFirstResponder: Bool { return true } 146 | 147 | override func keyDown(with event: NSEvent) { 148 | onShortcutRecorded?(event) 149 | self.removeFromSuperview() // Remove the view once the key is captured 150 | } 151 | } 152 | 153 | -------------------------------------------------------------------------------- /VOCR/MacCamera.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Camera.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 10/12/19. 6 | // Copyright © 2019 Chi Kim. All rights reserved. 7 | // 8 | 9 | import AVFoundation 10 | import Cocoa 11 | import UniformTypeIdentifiers 12 | 13 | class MacCamera:NSObject, AVCapturePhotoCaptureDelegate { 14 | 15 | static let shared = MacCamera() 16 | var captureSession:AVCaptureSession! 17 | var cameraOutput:AVCapturePhotoOutput! 18 | var deviceName = "Unknown Camera" 19 | 20 | func isCameraAllowed() -> Bool { 21 | let cameraPermissionStatus = AVCaptureDevice.authorizationStatus(for: .video) 22 | switch cameraPermissionStatus { 23 | case .authorized: 24 | print("Already Authorized") 25 | return true 26 | case .denied: 27 | print("denied") 28 | return false 29 | case .restricted: 30 | print("restricted") 31 | return false 32 | default: 33 | print("Ask permission") 34 | 35 | var access = false 36 | AVCaptureDevice.requestAccess(for: .video) { granted in 37 | if granted == true { 38 | print("User granted") 39 | } else { 40 | print("User denied") 41 | } 42 | access = granted 43 | } 44 | return access 45 | } 46 | } 47 | 48 | func getCamera() -> AVCaptureDevice? { 49 | let devices = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera,.externalUnknown], mediaType: .video, position: .unspecified).devices 50 | for device in devices { 51 | if Settings.camera == device.localizedName { 52 | return device 53 | } 54 | } 55 | if let device = AVCaptureDevice.default(for: .video) { 56 | return device 57 | } 58 | return nil 59 | } 60 | 61 | func takePicture() { 62 | guard let device = getCamera() else { 63 | Accessibility.speakWithSynthesizer("No camera available.") 64 | return 65 | } 66 | deviceName = device.localizedName 67 | Accessibility.speak("Using \(deviceName)") 68 | captureSession = AVCaptureSession() 69 | captureSession.sessionPreset = AVCaptureSession.Preset.photo 70 | cameraOutput = AVCapturePhotoOutput() 71 | if let input = try? AVCaptureDeviceInput(device: device) { 72 | if (captureSession.canAddInput(input)) { 73 | captureSession.addInput(input) 74 | if (captureSession.canAddOutput(cameraOutput)) { 75 | captureSession.addOutput(cameraOutput) 76 | captureSession.startRunning() 77 | let settings = AVCapturePhotoSettings() 78 | for c in stride(from: 3, to: 1, by: -1) { 79 | Accessibility.speak("\(c)") 80 | sleep(1) 81 | } 82 | Accessibility.speak("1") 83 | cameraOutput.capturePhoto(with: settings, delegate: self) 84 | } 85 | } else { 86 | print("issue here : captureSession.canAddInput") 87 | } 88 | } else { 89 | print("some problem here") 90 | } 91 | } 92 | 93 | func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { 94 | captureSession.stopRunning() 95 | print("photo captured") 96 | if let error = error { 97 | debugPrint(error) 98 | } 99 | 100 | if let dataImage = photo.fileDataRepresentation() { 101 | let dataProvider = CGDataProvider(data: dataImage as CFData) 102 | if let cgImage = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: .defaultIntent) { 103 | NSSound(contentsOfFile: "/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Shutter.aif", byReference: true)?.play() 104 | 105 | Navigation.mode = .CAMERA 106 | Navigation.appName = deviceName 107 | Navigation.cgImage = cgImage 108 | 109 | // Present menu to the user 110 | let alert = NSAlert() 111 | alert.messageText = "Choose an action" 112 | alert.addButton(withTitle: "Recognize Image") 113 | alert.addButton(withTitle: "Recognize image with LLM") 114 | alert.addButton(withTitle: "Recognize text in image") 115 | alert.addButton(withTitle: "Close") 116 | alert.window.defaultButtonCell = alert.buttons[0].cell as? NSButtonCell 117 | let response = alert.runModal() 118 | 119 | switch response { 120 | case .alertFirstButtonReturn: 121 | print("Recognizing image using VisionKit") 122 | let message = classify(cgImage: cgImage) 123 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 124 | Accessibility.speak(message) 125 | } 126 | 127 | case .alertSecondButtonReturn: 128 | print("Recognizing image with LLM") 129 | ask(image: cgImage) 130 | 131 | case .alertThirdButtonReturn: 132 | print("Recognizing text in an image using VisionKit") 133 | Navigation.displayResults = [] 134 | Navigation.cgImage = cgImage 135 | Navigation.startOCR() 136 | if Navigation.displayResults.isEmpty { 137 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 138 | Accessibility.speak("Nothing found!") } 139 | } else { 140 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 141 | Accessibility.speak("Recognition finished.") 142 | NSSound(contentsOfFile: "/System/Library/Sounds/Pop.aiff", byReference: true)?.play() } 143 | } 144 | 145 | case NSApplication.ModalResponse(rawValue: 1003): 146 | print("Close button selected") 147 | return 148 | 149 | default: 150 | print("Invalid or unexpected menu response: \(response.rawValue)") 151 | } 152 | 153 | } else { 154 | print("Error: could not create CGIImage from photo.") 155 | } 156 | 157 | } else { 158 | print("Error getting file data representation from photo") 159 | } 160 | } 161 | 162 | @discardableResult func writeCGImage(_ image: CGImage, to destinationURL: URL) -> Bool { 163 | guard let destination = CGImageDestinationCreateWithURL(destinationURL as CFURL, UTType.png.identifier as CFString, 1, nil) else { return false } 164 | CGImageDestinationAddImage(destination, image, nil) 165 | return CGImageDestinationFinalize(destination) 166 | } 167 | 168 | } 169 | -------------------------------------------------------------------------------- /VOCR/Shortcuts.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Shortcuts.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 1/12/24. 6 | // Copyright © 2024 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import HotKey 11 | 12 | struct Shortcut: Codable { 13 | var name: String 14 | var key: UInt32 15 | var modifiers:UInt32 16 | var keyName:String 17 | } 18 | 19 | enum Shortcuts { 20 | 21 | static var handlers: [String: () -> Void] = [:] 22 | static var hotkeys:[HotKey] = [] 23 | static var shortcuts: [Shortcut] = [] 24 | static var navigationActive = false 25 | static let globalShortcuts = ["Settings", "OCR Window", "OCR VOCursor", "Capture Camera", "Realtime OCR", "Ask", "Explore"] 26 | static let navigationShortcuts = ["Right", "Left", "Down", "Up", "Beginning", "End", "Top", "Bottom", "Next Character", "Previous Character", "Report Location", "Identify Object", "Find Text", "Find Next", "Find Previous", "Exit Navigation"] 27 | static let allShortcuts = globalShortcuts+navigationShortcuts 28 | 29 | static func SetupShortcuts() { 30 | handlers["Settings"] = settingsHandler 31 | handlers["OCR Window"] = { 32 | Navigation.mode = .WINDOW 33 | Navigation.startOCR() 34 | } 35 | handlers["OCR VOCursor"] = { 36 | if !Accessibility.isVoiceOverRunning() { 37 | return 38 | } 39 | Navigation.mode = .VOCURSOR 40 | Navigation.startOCR() 41 | } 42 | handlers["Capture Camera"] = { 43 | if MacCamera.shared.isCameraAllowed() { 44 | MacCamera.shared.takePicture() 45 | } 46 | } 47 | handlers["Realtime OCR"] = realTimeHandler 48 | handlers["Explore"] = Navigation.explore 49 | handlers["Ask"] = { 50 | ask() 51 | } 52 | handlers["Report Location"] = Navigation.location 53 | handlers["Identify Object"] = Navigation.identifyObject 54 | handlers["Right"] = Navigation.right 55 | handlers["Left"] = Navigation.left 56 | handlers["Up"] = Navigation.up 57 | handlers["Down"] = Navigation.down 58 | handlers["Top"] = Navigation.top 59 | handlers["Bottom"] = Navigation.bottom 60 | handlers["Beginning"] = Navigation.beginning 61 | handlers["End"] = Navigation.end 62 | handlers["Next Character"] = Navigation.nextCharacter 63 | handlers["Previous Character"] = Navigation.previousCharacter 64 | handlers["Find Text"] = OCRTextSearch.shared.showSearchDialog 65 | handlers["Find Next"] = { 66 | OCRTextSearch.shared.search(fromBeginning: false, backward: false) 67 | } 68 | handlers["Find Previous"] = { 69 | OCRTextSearch.shared.search(fromBeginning: false, backward: true) 70 | } 71 | handlers["Exit Navigation"] = { 72 | Accessibility.speak("Exit VOCR navigation.") 73 | deactivateNavigationShortcuts() 74 | } 75 | 76 | loadShortcuts() 77 | } 78 | 79 | static func getDefaults() -> Data? { 80 | var data:Data? 81 | let bundle = Bundle.main 82 | if let bundlePath = bundle.path(forResource: "Shortcuts", ofType: "json") { 83 | data = try! Data(contentsOf: URL(fileURLWithPath: bundlePath)) 84 | } 85 | return data 86 | } 87 | 88 | static func loadDefaults() { 89 | if let data = getDefaults() { 90 | UserDefaults.standard.removeObject(forKey: "userShortcuts") 91 | UserDefaults.standard.set(data, forKey: "userShortcuts") 92 | } 93 | } 94 | 95 | static func merge() -> [Shortcut]? { 96 | if let defaultData = getDefaults(), 97 | let defaultShortcuts = try? JSONDecoder().decode([Shortcut].self, from: defaultData), 98 | let userData = UserDefaults.standard.data(forKey: "userShortcuts"), 99 | var userShortcuts = try? JSONDecoder().decode([Shortcut].self, from: userData) { 100 | for shortcut in defaultShortcuts { 101 | if !userShortcuts.contains(where: { $0.name == shortcut.name }) { 102 | userShortcuts.append(shortcut) 103 | } 104 | } 105 | 106 | if let mergedData = try? JSONEncoder().encode(userShortcuts) { 107 | UserDefaults.standard.set(mergedData, forKey: "userShortcuts") 108 | } 109 | return userShortcuts 110 | } 111 | return nil 112 | } 113 | 114 | static func loadShortcuts() { 115 | if UserDefaults.standard.data(forKey: "userShortcuts") == nil { 116 | loadDefaults() 117 | } 118 | 119 | if let data = UserDefaults.standard.data(forKey: "userShortcuts"), 120 | let mergedShortcuts = merge() { 121 | shortcuts = mergedShortcuts 122 | for shortcut in shortcuts { 123 | log("\(shortcut.name), \(shortcut.keyName), \(shortcut.modifiers), \(shortcut.key)") 124 | } 125 | registerAll() 126 | } 127 | } 128 | 129 | static func registerAll() { 130 | hotkeys.removeAll() 131 | register(names:globalShortcuts) 132 | if navigationActive { 133 | register(names:navigationShortcuts) 134 | } 135 | } 136 | 137 | static func register(names:[String]) { 138 | for shortcut in shortcuts { 139 | if names.contains(shortcut.name) { 140 | let hotkey = HotKey(carbonKeyCode:shortcut.key, carbonModifiers:shortcut.modifiers) 141 | hotkey.keyDownHandler = handlers[shortcut.name] 142 | hotkeys.append(hotkey) 143 | } 144 | } 145 | } 146 | 147 | static func deregister(names:[String]) { 148 | for shortcut in shortcuts { 149 | if names.contains(shortcut.name) { 150 | let kc = KeyCombo(carbonKeyCode: shortcut.key, carbonModifiers: shortcut.modifiers) 151 | hotkeys.removeAll { ($0.keyCombo == kc) } 152 | } 153 | } 154 | } 155 | 156 | static func deactivateNavigationShortcuts() { 157 | navigationActive = false 158 | deregister(names:navigationShortcuts) 159 | } 160 | 161 | static func activateNavigationShortcuts() { 162 | navigationActive = true 163 | register(names:navigationShortcuts) 164 | } 165 | 166 | static func settingsHandler() { 167 | let mouseLocation = NSEvent.mouseLocation 168 | let rect = CGRect(x: mouseLocation.x, y: mouseLocation.y, width: 1, height: 1) 169 | Settings.setupMenu().popUp(positioning: nil, at: rect.origin, in: nil) 170 | } 171 | static func realTimeHandler() { 172 | if RealTime.run { 173 | Accessibility.speakWithSynthesizer("Stopping RealTime OCR.") 174 | RealTime.run = false 175 | } else { 176 | Accessibility.speakWithSynthesizer("RealTime OCR started.") 177 | RealTime.run = true 178 | RealTime.continuousOCR() 179 | } 180 | 181 | } 182 | } 183 | 184 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | Enhancing Accessibility with Seamless Screen Recognition 2 | 3 | ## Welcome to VOCR 4 | 5 | Discover the cutting-edge capabilities of VOCR, your ultimate OCR and AI-powered screen recognition tool designed to enhance your digital accessibility experience. Beyond the simple navigation feature with OCR, VOCR seamlessly integrates with VoiceOver, enabling users to effortlessly capture and recognize screen content with intuitive and customizable shortcuts. With features like Real-Time OCR, users can continuously monitor and read live content, such as subtitles. The ASK AI functionality allows you to leverage advanced AI models, including OpenAI GPT to ask detailed questions about images and receive insightful answers. It also supports local vision language models via Ollama for your privacy. Explore with AI takes it a step further by analyzing images, identifying different areas, and providing comprehensive descriptions. 6 | 7 | VOCR's robust suite of features offers unparalleled control and precision, making it an indispensable tool for users seeking a seamless, efficient, and highly functional OCR solution. Whether you're navigating inaccessible applications or curious about images, VOCR empowers you to do more with ease and confidence. 8 | 9 | [![Youtube Demo: VOCR 2.0 for Mac w/Chi Kim](https://img.youtube.com/vi/_9EIYUPyXao/maxresdefault.jpg)](https://www.youtube.com/watch?v=_9EIYUPyXao) 10 | 11 | {% include youtube.html id="_9EIYUPyXao" %} 12 | 13 | ## **WARNING**: USE AT YOUR OWN RISK! 14 | 15 | VOCR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, expressed or implied, of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please see the [GNU General Public License](http://www.gnu.org/licenses/) for more details. 16 | 17 | ## Download 18 | 19 | Here is the direct link to download [VOCR v2.0.1](https://github.com/chigkim/VOCR/releases/download/v2.0.1/VOCR_v2.0.1.zip). 20 | 21 | ## Setup 22 | 23 | To ensure VOCR works properly, it is crucial to follow every step precisely. Missing even one step could prevent VOCR from functioning correctly. 24 | 25 | 1. After uncompressing the downloaded zip file, move the application to your Applications folder and run it. 26 | 2. Confirm VOCR is running in the menu bar by pressing vo+m twice. 27 | 3. In VoiceOver Utility, under the General category, check the box for "Allow VoiceOver to be controlled with AppleScript." 28 | 4. If active, turn off the screen curtain with vo+shift+f11. Note that the screen curtain must be off for the app to work properly. 29 | 5. Hide VoiceOver visuals with vo+command+f11 if they are displayed. If not hidden, elements like the VoiceOver caption panel will be recognized along with other screen content. 30 | 6. Press command+shift+control+w. You should receive a notification asking for accessibility permission. If VoiceOver does not automatically focus on the window, press vo+f1 twice to display the list of currently running apps; the system dialog should be in this list. 31 | 7. After granting accessibility permission, press command+shift+control+w again to receive a notification requesting permission for VOCR to take a screenshot. If you do not receive the alert, locate the system dialog as described previously. 32 | 8. If you cannot locate the system dialog, go to System Settings, Privacy & Security, then choose Screen Recording, and find the VOCR app. 33 | 9. After granting accessibility permission, restart the app as prompted. 34 | 10. Verify the app is in the menu bar by pressing vo+m twice. 35 | 11. Press command+shift+control+w. You should hear a beep and a voice prompt saying "finished." 36 | 12. You can now navigate the recognized results using command+control+arrows. Refer to the shortcuts section below for more information. 37 | 13. When navigating results for the first time, an alert will prompt you to allow VOCR to control VoiceOver for speaking announcements. 38 | 14. Press Escape to exit VOCR's navigation mode and free up navigation shortcuts. 39 | 40 | ## OCR VoiceOver Cursor 41 | 42 | This feature is useful for capturing specific portions of a screen, such as a video player on a webpage or images on social media. 43 | 44 | 1. Move your VoiceOver cursor to the element you want to recognize. 45 | 2. Press command+shift+control+v. 46 | * The first time you use this feature, you will receive an alert to allow VOCR to run AppleScript. 47 | 3. After granting permission, press command+shift+control+v again. 48 | 49 | ## Real-Time OCR 50 | 51 | Press Command+Shift+Control+R after scanning a window or using VOCursor to start or stop real-time OCR. When activated, VOCR will continuously scan and report only new content. This is useful for reading live content such as subtitles. 52 | 53 | ## Setup AI Model 54 | 55 | You can host your own vision language model using Ollama or utilize OpenAI GPT to ask questions about images captured with VOCR. 56 | 57 | ### To use the OpenAI GPT model: 58 | 59 | 1. [Purchase API credits](https://platform.openai.com/settings/organization/billing/overview) for your account. 60 | 2. Create an [OpenAI API key](https://platform.openai.com/account/api-keys). 61 | 3. Enter your OpenAI API key in the VOCR Menu: Settings > Engine > OpenAI API Key. 62 | 63 | Note: It may take several hours for your API to become active after purchasing credits. 64 | 65 | The usage cost from VOCR is an estimate. For the official usage and cost, please refer to the [Usage Dashboard](https://platform.openai.com/usage) on OpenAI website. 66 | 67 | ### To utilize a local vision language model with Ollama: 68 | 69 | Ollama is free and private, but it is less accurate and requires a lot of computing power. I recommend M1 chip or later with minimum 16GB memory. 70 | 71 | 1. Download and install [Ollama](https://ollama.ai/). 72 | 2. Download a multimodal (vision-language) model by executing the following command in your terminal: 73 | 74 | ``` 75 | ollama pull llava 76 | ``` 77 | 78 | Note that there are also `llava:13b` and `llava:34b` models, which offer higher accuracy but require more storage, memory, and computing power. 79 | 80 | You may also want to try a related app called [VOLlama](https://chigkim.github.io/VOLlama/). It is an accessible chat client for Ollama, allowing you to easily interact with an open-source large language model that runs locally on your computer. 81 | 82 | ## ASK AI 83 | 84 | After the setting up OpenAI and/or Ollama: 85 | 86 | 1. Choose Ollama or GPT in VOCR Menu > Settings > Engine. 87 | 2. Scan a window/VOCursor or capture an image from a camera. 88 | 3. Press Command+Shift+Control+A to ask the selected model a question about the image. 89 | 90 | The response will be copied to the clipboard so you can review in case you miss it. 91 | 92 | Also you can select an image file in Finder, bring up the contextual menu with VO+Shift+M, go to 'Open with,' and choose VOCR to ask a question about the image. 93 | 94 | ## Explore with AI 95 | 96 | 1. Choose GPT in the VOCR Menu > Settings > Engine. 97 | 2. Provide your OpenAI API key in VOCR Menu > Settings > Engine > OpenAI API Key. 98 | 3. Scan a window or use VOCursor. 99 | 4. Press Command+Shift+Control+E. 100 | 101 | VOCR will ask GPT to analyze the image, identify various areas, and describe the contents of each. You can navigate the results using the shortcuts Command + Control + Arrows. 102 | 103 | Note: This feature is experimental and often produces inaccurate descriptions of locations and content. 104 | 105 | ## Global Shortcuts 106 | 107 | These shortcuts work at all times: 108 | 109 | * VOCR Menu: Command+Shift+Control+S 110 | * OCR Window: Command+Shift+Control+W 111 | * OCR VoiceOver Cursor: Command+Shift+Control+V 112 | * Camera Capture: Command+Shift+Control+C 113 | * Toggle Real-Time OCR: Command+Shift+Control+R 114 | * Ask AI: Command+Shift+Control+A 115 | * Explore with AI: Command+Shift+Control+E 116 | 117 | ## Navigation Shortcuts 118 | 119 | These shortcuts only work when navigation is active after a scan: 120 | 121 | * Move down/up: Command+Control+Down/Up Arrow 122 | * Move left/right: Command+Control+Left/Right Arrow 123 | * Previous/next character: Command+Shift+Control+Left/Right Arrow 124 | * Go to top/bottom: Command+Control+Page Up/Down 125 | * Go to beginning/end horizontally: Command+Control+Home/End 126 | * Exit navigation: Escape 127 | * Location: Command+Control+L (Reports current coordinates) 128 | * Identify Object: Command+Control+I (Identifies current object with AI when object detection is enabled in settings) 129 | 130 | ## Settings 131 | 132 | Access the VOCR Menu with Command+Control+Shift+S. This menu contains all settings and operations. 133 | 134 | * Target Window: Allows you to scan a different window than the current one. 135 | * Autoscan: Automatically scans after clicking an item with VO+Shift+Space. 136 | * Detect Object: Locates objects with no text such as icons. 137 | * Use Last Prompt: Reuses the last prompt when asking AI with Command+Shift+Control+A. 138 | * Move Mouse: Moves the mouse cursor when you navigate. 139 | * Positional Audio: Provides audio feedback as the mouse cursor moves. Frequency changes correspond to vertical location, and audio panning corresponds to horizontal position. If you don't hear the audio feedback, go to Settings > Sound Output. 140 | * Reset Position: When disabled, the cursor will not reset to the top-left corner after every new scan. 141 | * Launch on Login: Automatically runs VOCR when you log in. 142 | * Log: Starts writing logs to VOCR.txt in your Documents folder. 143 | * Sound Output: Choose a sound device for audio positional feedback. 144 | * Choose Camera: Select the camera to use for capturing an image. 145 | * Shortcuts: Customize shortcuts. 146 | * Engine: Choose between GPT or Ollama. 147 | 148 | Note that Llama.cpp temporarily suspended support for the vision language model on their server. 149 | 150 | ## Operation 151 | 152 | When you open the VOCR menu, few operations are available after a scan: 153 | 154 | * Save Last Image 155 | * Save OCR Result 156 | * Updates 157 | 158 | ## Troubleshooting 159 | 160 | * If you hear "nothing found" you likely need to turn off the VoiceOver screen curtain with vo+shift+f11 or adjust accessibility and screen recording permissions in System Settings > Privacy & Security. 161 | * If you do not hear anything after using the "OCR VoiceOver Cursor" feature, you probably need to grant VOCR permissions to: send Apple Events. 162 | 163 | Usually, relaunching VOCR and reissuing the command retriggers the alerts to reappear in the system dialogs as described above. 164 | 165 | Lastly, please enjoy using VOCR! -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Enhancing Accessibility with Seamless Screen Recognition 2 | 3 | ## Welcome to VOCR 4 | 5 | Discover the cutting-edge capabilities of VOCR, your ultimate OCR and AI-powered screen recognition tool designed to enhance your digital accessibility experience. Beyond the simple navigation feature with OCR, VOCR seamlessly integrates with VoiceOver, enabling users to effortlessly capture and recognize screen content with intuitive and customizable shortcuts. With features like Real-Time OCR, users can continuously monitor and read live content, such as subtitles. The ASK AI functionality allows you to leverage advanced AI models, including OpenAI GPT to ask detailed questions about images and receive insightful answers. It also supports local vision language models via Ollama for your privacy. Explore with AI takes it a step further by analyzing images, identifying different areas, and providing comprehensive descriptions. 6 | 7 | VOCR's robust suite of features offers unparalleled control and precision, making it an indispensable tool for users seeking a seamless, efficient, and highly functional OCR solution. Whether you're navigating inaccessible applications or curious about images, VOCR empowers you to do more with ease and confidence. 8 | 9 | [![Youtube Demo: VOCR 2.0 for Mac w/Chi Kim](https://img.youtube.com/vi/_9EIYUPyXao/maxresdefault.jpg)](https://www.youtube.com/watch?v=_9EIYUPyXao) 10 | 11 | ## **WARNING**: USE AT YOUR OWN RISK! 12 | 13 | VOCR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, expressed or implied, of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please see the [GNU General Public License](http://www.gnu.org/licenses/) for more details. 14 | 15 | ## Download 16 | 17 | Here is the direct link to download [VOCR v2.0.1](https://github.com/chigkim/VOCR/releases/download/v2.0.1/VOCR_v2.0.1.zip). 18 | 19 | ## Setup 20 | 21 | To ensure VOCR works properly, it is crucial to follow every step precisely. Missing even one step could prevent VOCR from functioning correctly. 22 | 23 | 1. After uncompressing the downloaded zip file, move the application to your Applications folder and run it. 24 | 2. Confirm VOCR is running in the menu bar by pressing vo+m twice. 25 | 3. In VoiceOver Utility, under the General category, check the box for "Allow VoiceOver to be controlled with AppleScript." 26 | 4. If active, turn off the screen curtain with vo+shift+f11. Note that the screen curtain must be off for the app to work properly. 27 | 5. Hide VoiceOver visuals with vo+command+f11 if they are displayed. If not hidden, elements like the VoiceOver caption panel will be recognized along with other screen content. 28 | 6. Press command+shift+control+w. You should receive a notification asking for accessibility permission. If VoiceOver does not automatically focus on the window, press vo+f1 twice to display the list of currently running apps; the system dialog should be in this list. 29 | 7. After granting accessibility permission, press command+shift+control+w again to receive a notification requesting permission for VOCR to take a screenshot. If you do not receive the alert, locate the system dialog as described previously. 30 | 8. If you cannot locate the system dialog, go to System Settings, Privacy & Security, then choose Screen Recording, and find the VOCR app. 31 | 9. After granting accessibility permission, restart the app as prompted. 32 | 10. Verify the app is in the menu bar by pressing vo+m twice. 33 | 11. Press command+shift+control+w. You should hear a beep and a voice prompt saying "finished." 34 | 12. You can now navigate the recognized results using command+control+arrows. Refer to the shortcuts section below for more information. 35 | 13. When navigating results for the first time, an alert will prompt you to allow VOCR to control VoiceOver for speaking announcements. 36 | 14. Press Escape to exit VOCR's navigation mode and free up navigation shortcuts. 37 | 38 | ## OCR VoiceOver Cursor 39 | 40 | This feature is useful for capturing specific portions of a screen, such as a video player on a webpage or images on social media. 41 | 42 | 1. Move your VoiceOver cursor to the element you want to recognize. 43 | 2. Press command+shift+control+v. 44 | * The first time you use this feature, you will receive an alert to allow VOCR to run AppleScript. 45 | 3. After granting permission, press command+shift+control+v again. 46 | 47 | ## Real-Time OCR 48 | 49 | Press Command+Shift+Control+R after scanning a window or using VOCursor to start or stop real-time OCR. When activated, VOCR will continuously scan and report only new content. This is useful for reading live content such as subtitles. 50 | 51 | ## Setup AI Model 52 | 53 | You can host your own vision language model using Ollama or utilize OpenAI GPT to ask questions about images captured with VOCR. 54 | 55 | ### To use the OpenAI GPT model: 56 | 57 | 1. [Purchase API credits](https://platform.openai.com/settings/organization/billing/overview) for your account. 58 | 2. Create an [OpenAI API key](https://platform.openai.com/account/api-keys). 59 | 3. Enter your OpenAI API key in the VOCR Menu: Settings > Engine > OpenAI API Key. 60 | 61 | Note: It may take several hours for your API to become active after purchasing credits. 62 | 63 | The usage cost from VOCR is an estimate. For the official usage and cost, please refer to the [Usage Dashboard](https://platform.openai.com/usage) on OpenAI website. 64 | 65 | ### To utilize a local vision language model with Ollama: 66 | 67 | Ollama is free and private, but it is less accurate and requires a lot of computing power. I recommend M1 chip or later with minimum 16GB memory. 68 | 69 | 1. Download and install [Ollama](https://ollama.ai/). 70 | 2. Download a multimodal (vision-language) model by executing the following command in your terminal: 71 | 72 | ``` 73 | ollama pull llava 74 | ``` 75 | 76 | Note that there are also `llava:13b` and `llava:34b` models, which offer higher accuracy but require more storage, memory, and computing power. 77 | 78 | You may also want to try a related app called [VOLlama](https://chigkim.github.io/VOLlama/). It is an accessible chat client for Ollama, allowing you to easily interact with an open-source large language model that runs locally on your computer. 79 | 80 | ## ASK AI 81 | 82 | After the setting up OpenAI and/or Ollama: 83 | 84 | 1. Choose Ollama or GPT in VOCR Menu > Settings > Engine. 85 | 2. Scan a window/VOCursor or capture an image from a camera. 86 | 3. Press Command+Shift+Control+A to ask the selected model a question about the image. 87 | 88 | The response will be copied to the clipboard so you can review in case you miss it. 89 | 90 | Also you can select an image file in Finder, bring up the contextual menu with VO+Shift+M, go to 'Open with,' and choose VOCR to ask a question about the image. 91 | 92 | ## Explore with AI 93 | 94 | 1. Choose GPT in the VOCR Menu > Settings > Engine. 95 | 2. Provide your OpenAI API key in VOCR Menu > Settings > Engine > OpenAI API Key. 96 | 3. Scan a window or use VOCursor. 97 | 4. Press Command+Shift+Control+E. 98 | 99 | VOCR will ask GPT to analyze the image, identify various areas, and describe the contents of each. You can navigate the results using the shortcuts Command + Control + Arrows. 100 | 101 | Note: This feature is experimental and often produces inaccurate descriptions of locations and content. 102 | 103 | ## Global Shortcuts 104 | 105 | These shortcuts work at all times: 106 | 107 | * VOCR Menu: Command+Shift+Control+S 108 | * OCR Window: Command+Shift+Control+W 109 | * OCR VoiceOver Cursor: Command+Shift+Control+V 110 | * Camera Capture: Command+Shift+Control+C 111 | * Toggle Real-Time OCR: Command+Shift+Control+R 112 | * Ask AI: Command+Shift+Control+A 113 | * Explore with AI: Command+Shift+Control+E 114 | 115 | ## Navigation Shortcuts 116 | 117 | These shortcuts only work when navigation is active after a scan: 118 | 119 | * Move down/up: Command+Control+Down/Up Arrow 120 | * Move left/right: Command+Control+Left/Right Arrow 121 | * Previous/next character: Command+Shift+Control+Left/Right Arrow 122 | * Go to top/bottom: Command+Control+Page Up/Down 123 | * Go to beginning/end horizontally: Command+Control+Home/End 124 | * Exit navigation: Escape 125 | * Location: Command+Control+L (Reports current coordinates) 126 | * Identify Object: Command+Control+I (Identifies current object with AI when object detection is enabled in settings) 127 | 128 | ## Settings 129 | 130 | Access the VOCR Menu with Command+Control+Shift+S. This menu contains all settings and operations. 131 | 132 | * Target Window: Allows you to scan a different window than the current one. 133 | * Autoscan: Automatically scans after clicking an item with VO+Shift+Space. 134 | * Detect Object: Locates objects with no text such as icons. 135 | * Use Last Prompt: Reuses the last prompt when asking AI with Command+Shift+Control+A. 136 | * Move Mouse: Moves the mouse cursor when you navigate. 137 | * Positional Audio: Provides audio feedback as the mouse cursor moves. Frequency changes correspond to vertical location, and audio panning corresponds to horizontal position. If you don't hear the audio feedback, go to Settings > Sound Output. 138 | * Reset Position: When disabled, the cursor will not reset to the top-left corner after every new scan. 139 | * Launch on Login: Automatically runs VOCR when you log in. 140 | * Log: Starts writing logs to VOCR.txt in your Documents folder. 141 | * Sound Output: Choose a sound device for audio positional feedback. 142 | * Choose Camera: Select the camera to use for capturing an image. 143 | * Shortcuts: Customize shortcuts. 144 | * Engine: Choose between GPT or Ollama. 145 | 146 | Note that Llama.cpp temporarily suspended support for the vision language model on their server. 147 | 148 | ## Operation 149 | 150 | When you open the VOCR menu, few operations are available after a scan: 151 | 152 | * Save Last Image 153 | * Save OCR Result 154 | * Updates 155 | 156 | ## Troubleshooting 157 | 158 | * If you hear "nothing found" you likely need to turn off the VoiceOver screen curtain with vo+shift+f11 or adjust accessibility and screen recording permissions in System Settings > Privacy & Security. 159 | * If you do not hear anything after using the "OCR VoiceOver Cursor" feature, you probably need to grant VOCR permissions to: send Apple Events. 160 | 161 | Usually, relaunching VOCR and reissuing the command retriggers the alerts to reappear in the system dialogs as described above. 162 | 163 | Lastly, please enjoy using VOCR! -------------------------------------------------------------------------------- /VOCR/Utils.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Utils.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 10/2/22. 6 | // Copyright © 2022 Chi Kim. All rights reserved. 7 | // 8 | 9 | 10 | import os 11 | import Vision 12 | import AVFoundation 13 | import Cocoa 14 | import AXSwift 15 | 16 | let logger = FileLogger.shared 17 | var task:URLSessionDataTask? 18 | func log(_ object: T, _ level:OSLogType = .info) { 19 | logger.log("\(String(describing: object))") 20 | } 21 | 22 | func performRequest(_ request:inout URLRequest, method:String="POST", name:String?=nil, completion: @escaping (Data) -> Void) { 23 | request.httpMethod = method 24 | request.timeoutInterval = 600 25 | request.setValue("application/json", forHTTPHeaderField: "Content-Type") 26 | task?.cancel() 27 | task = URLSession.shared.dataTask(with: request) { data, response, error in 28 | if let error = error { 29 | if error.localizedDescription != "cancelled" { 30 | Accessibility.speakWithSynthesizer("Connection error: \(error.localizedDescription)") 31 | } 32 | return 33 | } 34 | 35 | guard let httpResponse = response as? HTTPURLResponse else { 36 | Accessibility.speakWithSynthesizer("Invalid response from server.") 37 | return 38 | } 39 | 40 | guard httpResponse.statusCode == 200 else { 41 | Accessibility.speakWithSynthesizer("HTTP Error: Status code \(httpResponse.statusCode)") 42 | return 43 | } 44 | 45 | guard let data = data else { 46 | Accessibility.speakWithSynthesizer("No data received from server.") 47 | return 48 | } 49 | log(String(data: data, encoding: .utf8)) 50 | completion(data) 51 | } 52 | if let name = name { 53 | Accessibility.speakWithSynthesizer("Getting response from \(name)... Please wait...") 54 | } 55 | task?.resume() 56 | } 57 | 58 | func hide() { 59 | let windows = NSApplication.shared.windows 60 | NSApplication.shared.hide(nil) 61 | windows[1].close() 62 | } 63 | 64 | func askPrompt(value:String) -> String? { 65 | let alert = NSAlert() 66 | alert.messageText = "Prompt" 67 | alert.addButton(withTitle: "Ok") 68 | alert.addButton(withTitle: "Cancel") 69 | let inputTextField = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24)) 70 | inputTextField.stringValue = value 71 | alert.accessoryView = inputTextField 72 | DispatchQueue.main.async { 73 | alert.window.makeFirstResponder(inputTextField) 74 | } 75 | 76 | let response = alert.runModal() 77 | hide() 78 | if response == .alertFirstButtonReturn { 79 | let prompt = inputTextField.stringValue 80 | return prompt 81 | } 82 | return nil 83 | } 84 | 85 | func grabImage() -> CGImage? { 86 | var rect:CGRect? 87 | if Navigation.mode == .WINDOW { 88 | rect = Navigation.getWindow() 89 | } else if Navigation.mode == .VOCURSOR { 90 | rect = Navigation.getVOCursor() 91 | } 92 | if let rect = rect, 93 | let screenshot = TakeScreensShots(rect:rect) { 94 | return screenshot 95 | } else if Navigation.mode == .CAMERA { 96 | return Navigation.cgImage 97 | } else { 98 | Accessibility.speakWithSynthesizer("Faild to access \(Navigation.appName), \(Navigation.windowName)") 99 | } 100 | return nil 101 | } 102 | 103 | func ask(image:CGImage?=nil) { 104 | if Settings.engine == .ollama && Ollama.model == nil { 105 | Ollama.setModel() 106 | return 107 | } 108 | let cgImage = image ?? grabImage() 109 | guard let cgImage = cgImage else { return } 110 | if !Settings.useLastPrompt { 111 | if let prompt = askPrompt(value:Settings.prompt) { 112 | Settings.prompt = prompt 113 | } else { 114 | return 115 | } 116 | } 117 | 118 | getEngine(for: Settings.engine).ask(image: cgImage) 119 | } 120 | 121 | func imageToBase64(image: CGImage) -> String { 122 | let bitmapRep = NSBitmapImageRep(cgImage: image) 123 | guard let imageData = bitmapRep.representation(using: .jpeg, properties: [:]) else { 124 | fatalError("Could not convert image to JPEG.") 125 | } 126 | let base64_image = imageData.base64EncodedString(options: []) 127 | return base64_image 128 | } 129 | 130 | func copyToClipboard(_ string: String) { 131 | let pasteboard = NSPasteboard.general 132 | pasteboard.clearContents() 133 | pasteboard.setString(string, forType: .string) 134 | } 135 | 136 | func extractString(text: String, startDelimiter: String, endDelimiter: String) -> String? { 137 | guard let startRange = text.range(of: startDelimiter) else { 138 | return nil // No start delimiter found 139 | } 140 | 141 | // Define the search start for the next delimiter to be right after the first delimiter 142 | let searchStartIndex = startRange.upperBound 143 | 144 | // Find the range of the next delimiter after the first delimiter 145 | guard let endRange = text.range(of: endDelimiter, range: searchStartIndex.. CGImage? { 178 | var cgImageOutput : CGImage? = nil 179 | if let dataProvider = cgImageInput.dataProvider { 180 | if let data : CFData = dataProvider.data { 181 | let length = CFDataGetLength(data) 182 | 183 | let bytes = UnsafeMutablePointer.allocate(capacity: length) 184 | CFDataGetBytes(data, CFRange(location: 0, length: length), bytes) 185 | if let ctx = CGContext(data: bytes, width: cgImageInput.width, height: cgImageInput.height, bitsPerComponent: cgImageInput.bitsPerComponent, bytesPerRow: cgImageInput.bytesPerRow, space: cgImageInput.colorSpace!, bitmapInfo: cgImageInput.bitmapInfo.rawValue) { 186 | ctx.setFillColor(color.cgColor) 187 | ctx.setStrokeColor(color.cgColor) 188 | ctx.setLineWidth(3.0) 189 | log("Drawing boxes:") 190 | let rects = boxes.map { VNImageRectForNormalizedRect($0.boundingBox, cgImageInput.width, cgImageInput.height) } 191 | for box in rects { 192 | log("\(box.debugDescription)") 193 | ctx.stroke(box, width: 3.0) 194 | } 195 | cgImageOutput = (ctx.makeImage()) 196 | if cgImageOutput == nil { 197 | log("Failed to make image from CGContext.") 198 | } 199 | } else { 200 | log("Could not create context. Try different image parameters.") 201 | } 202 | bytes.deallocate() 203 | } else { 204 | log("Could not get dataProvider.data") 205 | } 206 | } else { 207 | log ("Could not get cgImage.dataProvider") 208 | } 209 | return cgImageOutput 210 | } 211 | 212 | func report(_ element:UIElement?) { 213 | log("\(element!.label!)") 214 | for atr in try! element!.attributesAsStrings() { 215 | log(atr) 216 | do { 217 | if let value:AnyObject = try element!.attribute(atr) { 218 | var valueStr = "" 219 | if atr == "AXChildren", let children = value as? [AXUIElement] { 220 | for child in children { 221 | valueStr += "\(UIElement(child).label!)" 222 | } 223 | } else { 224 | valueStr = "\(value)" 225 | } 226 | let text = "\(atr): \(valueStr)" 227 | log(text) 228 | } 229 | } catch let error { 230 | log("\(error)") 231 | } 232 | } 233 | } 234 | 235 | func resizeCGImage(_ cgImage: CGImage, toWidth width: Int, toHeight height: Int) -> CGImage? { 236 | let context = CGContext(data: nil, 237 | width: width, 238 | height: height, 239 | bitsPerComponent: cgImage.bitsPerComponent, 240 | bytesPerRow: 0, // letting Core Graphics determine the row bytes 241 | space: cgImage.colorSpace ?? CGColorSpaceCreateDeviceRGB(), 242 | bitmapInfo: cgImage.bitmapInfo.rawValue) 243 | 244 | context?.interpolationQuality = .high 245 | context?.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height)) 246 | 247 | return context?.makeImage() 248 | } 249 | 250 | func TakeScreensShots(rect:CGRect) -> CGImage? { 251 | var displayCount: UInt32 = 0 252 | var result = CGGetActiveDisplayList(0, nil, &displayCount) 253 | if (result != CGError.success) { 254 | log("error: \(result)") 255 | return nil 256 | } 257 | let allocated = Int(displayCount) 258 | let activeDisplays = UnsafeMutablePointer.allocate(capacity: allocated) 259 | result = CGGetActiveDisplayList(displayCount, activeDisplays, &displayCount) 260 | 261 | if (result != CGError.success) { 262 | log("error: \(result)") 263 | return nil 264 | } 265 | if let cgImage = CGDisplayCreateImage(activeDisplays[0], rect:rect) { 266 | log("Original: \(cgImage.width), \(cgImage.height)") 267 | Navigation.cgImage = cgImage 268 | return cgImage 269 | } 270 | return nil 271 | } 272 | 273 | func performOCR(cgImage:CGImage) -> [Observation] { 274 | let textRecognitionRequest = VNRecognizeTextRequest() 275 | textRecognitionRequest.recognitionLevel = VNRequestTextRecognitionLevel.accurate 276 | textRecognitionRequest.minimumTextHeight = 0 277 | textRecognitionRequest.automaticallyDetectsLanguage = true 278 | textRecognitionRequest.usesLanguageCorrection = true 279 | textRecognitionRequest.customWords = [] 280 | textRecognitionRequest.usesCPUOnly = false 281 | textRecognitionRequest.cancel() 282 | do { 283 | try debugPrint("\(textRecognitionRequest.supportedRecognitionLanguages().count), \(textRecognitionRequest.supportedRecognitionLanguages())") 284 | } catch { 285 | 286 | } 287 | let rectDetectRequest = VNDetectRectanglesRequest() 288 | rectDetectRequest.maximumObservations = 1000 289 | rectDetectRequest.minimumConfidence = 0.0 290 | rectDetectRequest.minimumAspectRatio = 0.0 291 | rectDetectRequest.minimumSize = 0.0 292 | rectDetectRequest.cancel() 293 | 294 | let requestHandler = VNImageRequestHandler(cgImage: cgImage, options: [:]) 295 | do { 296 | try requestHandler.perform([textRecognitionRequest, rectDetectRequest]) 297 | } catch _ {} 298 | guard let texts = textRecognitionRequest.results else { 299 | return [] 300 | } 301 | var result = texts.map {Observation($0)} 302 | if Settings.detectObject { 303 | guard let boxes = rectDetectRequest.results else { 304 | return [] 305 | } 306 | 307 | var boxesNoText:[Observation] = [] 308 | var boxesText:[Observation] = [] 309 | for box in boxes { 310 | var intersectsFlag: Bool = false 311 | for text in texts { 312 | if box.boundingBox.intersects(text.boundingBox) { 313 | let obs = Observation(box, value:"Text: "+text.topCandidates(1)[0].string) 314 | boxesText.append(obs) 315 | intersectsFlag = true 316 | break 317 | } 318 | } 319 | if !intersectsFlag { 320 | let obs = Observation(box, value:"OBJECT") 321 | boxesNoText.append(obs) 322 | result.append(obs) 323 | } 324 | } 325 | 326 | log("Box Count: \(boxes.count)") 327 | log("Text Count: \(texts.count)") 328 | log("boxesNoText Count: \(boxesNoText.count)") 329 | log("boxesText count: \(boxesText.count)") 330 | /* 331 | var pointBoxes: [CGRect] = [] 332 | for point in texts { 333 | // log("point: ", point) 334 | pointBoxes.append(CGRect(x: point.boundingBox.minX-0.1, y: point.boundingBox.minY-0.1, width: 0.2, height: 0.2)) 335 | } 336 | */ 337 | 338 | // var boxImage = drawBoxes(cgImage, boxes:boxesText, color:NSColor.green)! 339 | // var boxImage = drawBoxes(cgImage, boxes:boxesNoText, color:NSColor.red)! 340 | // try? saveImage(boxImage) 341 | } 342 | return result 343 | } 344 | 345 | func classify(cgImage:CGImage) -> String { 346 | var message = "" 347 | var categories: [String: VNConfidence] = [:] 348 | let handler = VNImageRequestHandler(cgImage:cgImage, options: [:]) 349 | let request = VNClassifyImageRequest() 350 | try? handler.perform([request]) 351 | guard let observations = request.results else { 352 | return message 353 | } 354 | categories = observations 355 | .filter { $0.hasMinimumRecall(0.1, forPrecision: 0.9) } 356 | .reduce(into: [String: VNConfidence]()) { dict, observation in dict[observation.identifier] = observation.confidence } 357 | let classes = categories.sorted(by: {($0.value>$1.value)}) 358 | log("Classes: \(classes)") 359 | var count = classes.count 360 | if count>0 { 361 | if count>5 { 362 | count = 5 363 | } 364 | 365 | for c in 0.. String? { 376 | let bundle = Bundle.main 377 | let script = bundle.url(forResource: file, withExtension: "scpt") 378 | log("\(script!)") 379 | var error:NSDictionary? 380 | if let scriptObject = NSAppleScript(contentsOf: script!, error: &error) { 381 | var outputError:NSDictionary? 382 | if let output = scriptObject.executeAndReturnError(&outputError).stringValue { 383 | log("\(output)") 384 | return output 385 | } else { 386 | log("Output Error: \(String(describing: outputError))") 387 | } 388 | } 389 | return nil 390 | } 391 | 392 | 393 | -------------------------------------------------------------------------------- /VOCR/Navigation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Navigation.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 10/12/19. 6 | // Copyright © 2019 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Vision 11 | import Cocoa 12 | 13 | enum Navigation { 14 | 15 | enum Mode: Int, CaseIterable { 16 | case WINDOW = 0 17 | case VOCURSOR = 1 18 | case CAMERA = 2 19 | func next() -> Mode { 20 | let allCases = Mode.allCases 21 | let nextIndex = (self.rawValue + 1) % allCases.count 22 | return allCases[nextIndex] 23 | } 24 | 25 | func name() -> String { 26 | switch (self) { 27 | case.WINDOW: 28 | return "Window" 29 | case .VOCURSOR: 30 | return "VOCursor" 31 | case .CAMERA: 32 | return "Camera" 33 | } 34 | } 35 | } 36 | 37 | static var mode = Mode.WINDOW 38 | 39 | static var displayResults:[[Observation]] = [] 40 | static var cgPosition = CGPoint() 41 | static var cgSize = CGSize() 42 | static var cgImage:CGImage? 43 | static var windowName = "Unknown Window" 44 | static var appName = "Unknown App" 45 | static var l = -1 46 | static var w = -1 47 | static var c = -1 48 | 49 | static func getWindow() -> CGRect? { 50 | let currentApp = NSWorkspace.shared.frontmostApplication 51 | appName = currentApp!.localizedName! 52 | let windows = currentApp?.windows() 53 | 54 | /* 55 | // filter main window. 56 | windows = windows!.filter { 57 | var ref:CFTypeRef? 58 | AXUIElementCopyAttributeValue($0, "AXMain" as CFString, &ref) 59 | if let value = ref as? Int, value == 1 { 60 | return true 61 | } 62 | return false 63 | } 64 | */ 65 | 66 | if (windows!.isEmpty) { 67 | return nil 68 | } 69 | var window = windows![0] 70 | 71 | if Settings.targetWindow && windows!.count > 1 { 72 | let alert = NSAlert() 73 | alert.alertStyle = .informational 74 | alert.messageText = "Target Window" 75 | alert.informativeText = "Choose an window to scan." 76 | for window in windows! { 77 | var title = window.value(of: "AXTitle") 78 | if (title == "") { 79 | title = "Untitled" 80 | } 81 | title += String(window.hashValue) 82 | alert.addButton(withTitle: title) 83 | } 84 | alert.addButton(withTitle: "Close") 85 | let modalResult = alert.runModal() 86 | hide() 87 | let r = modalResult.rawValue-1000 88 | window = windows![r] 89 | } 90 | 91 | // report(UIElement(window)) 92 | windowName = window.value(of: "AXTitle") 93 | log("Window information: \(appName) - \(windowName)") 94 | var position:CFTypeRef? 95 | var size:CFTypeRef? 96 | AXUIElementCopyAttributeValue(window, "AXPosition" as CFString, &position) 97 | AXUIElementCopyAttributeValue(window, "AXSize" as CFString, &size) 98 | 99 | if position != nil && size != nil { 100 | var windowPosition = CGPoint() 101 | var windowSize = CGSize() 102 | AXValueGetValue(position as! AXValue, AXValueType.cgPoint, &windowPosition) 103 | AXValueGetValue(size as! AXValue, AXValueType.cgSize, &windowSize) 104 | let rect = CGRect(origin: windowPosition, size: windowSize) 105 | log(rect) 106 | return rect 107 | } else { 108 | log("Failed to get position or size") 109 | } 110 | return nil 111 | } 112 | 113 | static func setWindow() { 114 | if let rect = getWindow() { 115 | cgPosition = rect.origin 116 | cgSize = rect.size 117 | } 118 | } 119 | 120 | static func getVOCursor() -> CGRect? { 121 | if let output = runAppleScript(file: "VOCursor") { 122 | let strings = output.split(separator: ",") 123 | let cgFloats = strings.compactMap { CGFloat(Double($0) ?? 0) } 124 | let position = CGPoint(x: cgFloats[0], y: cgFloats[1]) 125 | let size = CGSize(width:(cgFloats[2]-cgFloats[0]), height: (cgFloats[3]-cgFloats[1])) 126 | appName = "VOCursor" 127 | windowName = "" 128 | return CGRect(origin: position, size: size) 129 | } 130 | return nil 131 | } 132 | static func setVOCursor() { 133 | if let rect = getVOCursor() { 134 | cgPosition = rect.origin 135 | cgSize = rect.size 136 | } 137 | } 138 | 139 | static func prepare() { 140 | if !Accessibility.isTrusted(ask:true) { 141 | log("Accessibility not enabled.") 142 | return 143 | } 144 | windowName = "Unknown Window" 145 | appName = "Unknown App" 146 | cgPosition = CGPoint() 147 | cgSize = CGSize() 148 | cgImage = nil 149 | if Settings.positionReset { 150 | l = -1 151 | w = -1 152 | c = -1 153 | } 154 | displayResults = [] 155 | Shortcuts.deactivateNavigationShortcuts() 156 | NSSound(contentsOfFile: "/System/Library/Sounds/Pop.aiff", byReference: true)?.play() 157 | if mode == .WINDOW { 158 | setWindow() 159 | } else { 160 | setVOCursor() 161 | } 162 | if cgSize != CGSize() { 163 | if let image = TakeScreensShots(rect:CGRect(origin: cgPosition, size: cgSize)) { 164 | cgImage = image 165 | } else { 166 | Accessibility.speak("Faild to take a screenshot of \(appName), \(windowName)") 167 | } 168 | } else { 169 | Accessibility.speak("Faild to access \(appName), \(windowName)") 170 | } 171 | } 172 | 173 | static func startOCR() { 174 | if (mode != .CAMERA) { 175 | prepare() } 176 | guard let image = cgImage else { return } 177 | let result = performOCR(cgImage:image) 178 | if result.count == 0 { 179 | Accessibility.speak("Nothing found") 180 | return 181 | } 182 | process(result) 183 | Accessibility.speak("Finished scanning \(appName), \(windowName)") 184 | Shortcuts.activateNavigationShortcuts() 185 | } 186 | 187 | 188 | static func explore() { 189 | prepare() 190 | // guard let image = cgImage, let image = resizeCGImage(image, toWidth: Int(Navigation.cgSize.width), toHeight:Int(Navigation.cgSize.height)) else { return } 191 | // log("Resized:", image.width, image.height) 192 | guard let image = cgImage else { return } 193 | 194 | let system = "You are a helpful assistant. Your response should be in JSON format." 195 | let prompt = "Process the provided image by segmenting it into distinct areas with related items. Output a JSON format description for each segmented area. The JSON should include: 'label' (a concise string name), 'uid' (a unique integer identifier), 'description' (a brief explanation of the area), 'content' (a string with examples of objects within the area), and 'boundingBox' (coordinates as an array: bottom_left_x, bottom_left_y, width, height). Ensure the boundingBox coordinates are normalized between 0.0 and 1.0 relative to the image's resolution (\(image.width) width and \(image.height) height), with the origin at the bottom left (0.0, 0.0). The response should start with ```json and end with ```, containing only the JSON string without inline comments or extra notes. Precision in the 'boundingBox' coordinates is crucial; even one minor inaccuracy can have severe and irreversible consequences for users." 196 | getEngine(for: Settings.engine).describe(image:image, system:system, prompt:prompt, completion: exploreHandler) 197 | } 198 | 199 | static func exploreHandler(description:String) { 200 | guard let json = extractString(text:description, startDelimiter: "```json\n", endDelimiter: "\n```") else { 201 | Accessibility.speakWithSynthesizer("Cannot extract JSON string from the response. Try again.") 202 | return 203 | } 204 | if let elements = self.decode(message:json) { 205 | let result = elements.map {Observation($0)} 206 | self.process(result) 207 | Shortcuts.activateNavigationShortcuts() 208 | Accessibility.speak("Finished scanning \(self.appName), \(self.windowName)") 209 | 210 | // DispatchQueue.main.async { 211 | // if let cgImage = cgImage { 212 | // let boxImage = drawBoxes(cgImage, boxes:result, color:NSColor.red)! 213 | // try? saveImage(boxImage) 214 | // } 215 | // } 216 | 217 | } else { 218 | Accessibility.speakWithSynthesizer("Cannot parse the JSON string. Try again.") 219 | } 220 | } 221 | 222 | static func decode(message:String) -> [GPTObservation]? { 223 | let jsonData = message.data(using: .utf8)! 224 | do { 225 | let elements = try JSONDecoder().decode([GPTObservation].self, from: jsonData) 226 | for element in elements { 227 | log("Label: \(element.label), UID: \(element.uid), Bounding Box: \(element.boundingBox)") 228 | } 229 | return elements 230 | } catch { 231 | log("Error decoding JSON: \(error)") 232 | } 233 | return nil 234 | } 235 | 236 | static func process(_ results:[Observation]) { 237 | let sorted = results.sorted(by: sort) 238 | var line:[Observation] = [] 239 | var y = sorted[0].boundingBox.midY 240 | for r in sorted { 241 | // log("\(r.value): \(r.boundingBox.debugDescription)") 242 | if abs(r.boundingBox.midY-y)>0.01 { 243 | displayResults.append(line) 244 | line = [] 245 | y = r.boundingBox.midY 246 | } 247 | line.append(r) 248 | } 249 | displayResults.append(line) 250 | } 251 | 252 | static func convert2coordinates(_ rect:CGRect) -> CGPoint { 253 | if let image = cgImage { 254 | log("Box: \(VNImageRectForNormalizedRect(rect, image.width, image.height).debugDescription)") 255 | } 256 | let box = CGRect(x:rect.minX, y:1-rect.maxY, width:rect.width, height:rect.height) 257 | var center = CGPoint(x:box.midX, y:box.midY) 258 | log("\(center.debugDescription)") 259 | if Settings.positionalAudio { 260 | let frequency = 100+1000*(1-Float(center.y)) 261 | let pan = Float(Double(center.x).normalize(from: 0...1, into: -1...1)) 262 | Player.shared.play(frequency, pan) 263 | } 264 | center = VNImagePointForNormalizedPoint(center, Int(cgSize.width), Int(cgSize.height)) 265 | log("\(center.debugDescription)") 266 | center.x += cgPosition.x 267 | center.y += cgPosition.y 268 | return center 269 | } 270 | 271 | static func sort(_ a:Observation, _ b:Observation) -> Bool { 272 | if a.boundingBox.midY-b.boundingBox.midY>0.01 { 273 | return true 274 | } else if b.boundingBox.midY-a.boundingBox.midY>0.01 { 275 | return false 276 | } 277 | if a.boundingBox.midX= displayResults.count { 295 | l = displayResults.count-1 296 | } 297 | if w < 0 { 298 | w = 0 299 | } else if w >= displayResults[l].count { 300 | w = displayResults[l].count-1 301 | } 302 | } 303 | 304 | static func identifyObject() { 305 | if displayResults[l][w].value == "OBJECT" { 306 | if let image = cgImage { 307 | var rect = displayResults[l][w].boundingBox 308 | rect = CGRect(x:rect.minX, y:1-rect.maxY, width:rect.width, height:rect.height) 309 | rect = VNImageRectForNormalizedRect(rect, image.width, image.height) 310 | 311 | log("\(rect.debugDescription)") 312 | if let croppedImage = image.cropping(to: rect) { 313 | ask(image: croppedImage) 314 | // try! saveImage(croppedImage) 315 | // classify(cgImage:croppedImage) 316 | } 317 | } 318 | } 319 | } 320 | 321 | static func right() { 322 | if displayResults.count == 0 { 323 | return 324 | } 325 | w += 1 326 | c = -1 327 | correctLimit() 328 | log("\(l), \(w)") 329 | if Settings.moveMouse { 330 | CGWarpMouseCursorPosition(convert2coordinates(displayResults[l][w].boundingBox)) 331 | } 332 | Accessibility.speak(displayResults[l][w].value) 333 | // identifyObject() 334 | } 335 | 336 | static func left() { 337 | if displayResults.count == 0 { 338 | return 339 | } 340 | w -= 1 341 | c = -1 342 | correctLimit() 343 | log("\(l), \(w)") 344 | if Settings.moveMouse { 345 | CGWarpMouseCursorPosition(convert2coordinates(displayResults[l][w].boundingBox)) 346 | } 347 | Accessibility.speak(displayResults[l][w].value) 348 | // identifyObject() 349 | } 350 | 351 | static func down() { 352 | if displayResults.count == 0 { 353 | return 354 | } 355 | l += 1 356 | w = 0 357 | c = -1 358 | correctLimit() 359 | log("\(l), \(w)") 360 | if Settings.moveMouse { 361 | CGWarpMouseCursorPosition(convert2coordinates(displayResults[l][w].boundingBox)) 362 | } 363 | var line = "" 364 | for r in displayResults[l] { 365 | line += " \(r.value)" 366 | } 367 | Accessibility.speak(line) 368 | } 369 | 370 | static func up() { 371 | if displayResults.count == 0 { 372 | return 373 | } 374 | l -= 1 375 | w = 0 376 | c = -1 377 | correctLimit() 378 | log("\(l), \(w)") 379 | if Settings.moveMouse { 380 | CGWarpMouseCursorPosition(convert2coordinates(displayResults[l][w].boundingBox)) 381 | } 382 | var line = "" 383 | for r in displayResults[l] { 384 | line += " \(r.value)" 385 | } 386 | Accessibility.speak(line) 387 | } 388 | 389 | static func top() { 390 | if displayResults.count == 0 { 391 | return 392 | } 393 | l = 1 394 | w = 0 395 | up() 396 | } 397 | 398 | static func bottom() { 399 | if displayResults.count == 0 { 400 | return 401 | } 402 | l = displayResults.count-2 403 | w = 0 404 | down() 405 | } 406 | 407 | static func beginning() { 408 | if displayResults.count == 0 { 409 | return 410 | } 411 | w = 1 412 | left() 413 | } 414 | 415 | static func end() { 416 | if displayResults.count == 0 { 417 | return 418 | } 419 | w = displayResults[l].count-2 420 | right() 421 | } 422 | 423 | static func nextCharacter() { 424 | if displayResults.count == 0 { 425 | return 426 | } 427 | correctLimit() 428 | if let obs = displayResults[l][w].vnObservation { 429 | let candidate = obs.topCandidates(1)[0] 430 | var str = candidate.string 431 | c += 1 432 | if c >= str.count { 433 | c = str.count-1 434 | } 435 | do { 436 | let start = str.index(str.startIndex,offsetBy:c) 437 | let end = str.index(str.startIndex,offsetBy:c+1) 438 | let range = start.. String { 499 | var text = "" 500 | for line in displayResults { 501 | for word in line { 502 | text += word.value+" " 503 | } 504 | text = text.dropLast()+"\n" 505 | } 506 | return text 507 | } 508 | 509 | } 510 | 511 | -------------------------------------------------------------------------------- /VOCR/Settings.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Settings.swift 3 | // VOCR 4 | // 5 | // Created by Chi Kim on 10/14/19. 6 | // Copyright © 2019 Chi Kim. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import AudioKit 11 | import AVFoundation 12 | 13 | enum Settings { 14 | 15 | static private var eventMonitor: Any? 16 | static var positionReset = true 17 | static var positionalAudio = false 18 | static var moveMouse = true 19 | static var launchOnBoot = true 20 | static var autoScan = false 21 | static var targetWindow = false 22 | static var detectObject = true 23 | static var windowRealtime = true 24 | static var useLastPrompt = false 25 | static var prompt = "Analyze the image in a comprehensive and detailed manner." 26 | static var systemPrompt = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions." 27 | static var GPTAPIKEY = "" 28 | static var mode = "OCR" 29 | static let target = MenuHandler() 30 | static var engine: Engines = .ollama 31 | static var writeLog = false 32 | static var preRelease = false 33 | static var camera = "Unknown" 34 | 35 | static var allSettings: [(title: String, action: Selector, value: Bool)] { 36 | return [ 37 | ("Target Window", #selector(MenuHandler.toggleSetting(_:)), targetWindow), 38 | ("Auto Scan", #selector(MenuHandler.toggleAutoScan(_:)), autoScan), 39 | ("Detect Objects", #selector(MenuHandler.toggleSetting(_:)), detectObject), 40 | ("Use Last Prompt", #selector(MenuHandler.toggleSetting(_:)), useLastPrompt), 41 | ("Reset Position on Scan", #selector(MenuHandler.toggleSetting(_:)), positionReset), 42 | ("Positional Audio", #selector(MenuHandler.toggleSetting(_:)), positionalAudio), 43 | ("Move Mouse", #selector(MenuHandler.toggleSetting(_:)), moveMouse), 44 | ("Launch on Login", #selector(MenuHandler.toggleLaunch(_:)), launchOnBoot), 45 | ("Log", #selector(MenuHandler.toggleLaunch(_:)), writeLog), 46 | ] 47 | } 48 | 49 | static func setupMenu() -> NSMenu { 50 | load() 51 | let menu = NSMenu() 52 | let settingsMenu = NSMenu() 53 | for setting in allSettings { 54 | let menuItem = NSMenuItem(title: setting.title, action: setting.action, keyEquivalent: "") 55 | menuItem.target = target 56 | menuItem.state = setting.value ? .on : .off 57 | settingsMenu.addItem(menuItem) 58 | } 59 | 60 | if Settings.autoScan { 61 | installMouseMonitor() 62 | } 63 | 64 | let engineMenu = NSMenu() 65 | 66 | let gptItem = NSMenuItem(title: "GPT", action: #selector(target.selectModel(_:)), keyEquivalent: "") 67 | gptItem.target = target 68 | gptItem.tag = Engines.gpt.rawValue 69 | engineMenu.addItem(gptItem) 70 | 71 | let ollamaItem = NSMenuItem(title: "Ollama", action: #selector(target.selectModel(_:)), keyEquivalent: "") 72 | ollamaItem.target = target 73 | ollamaItem.tag = Engines.ollama.rawValue 74 | engineMenu.addItem(ollamaItem) 75 | 76 | let llamaCppItem = NSMenuItem(title: "LlamaCpp", action: #selector(target.selectModel(_:)), keyEquivalent: "") 77 | llamaCppItem.target = target 78 | llamaCppItem.tag = Engines.llamaCpp.rawValue 79 | engineMenu.addItem(llamaCppItem) 80 | 81 | for item in engineMenu.items { 82 | item.state = (item.tag == Settings.engine.rawValue) ? .on : .off 83 | } 84 | 85 | let enterAPIKeyMenuItem = NSMenuItem(title: "OpenAI API Key...", action: #selector(target.presentApiKeyInputDialog(_:)), keyEquivalent: "") 86 | enterAPIKeyMenuItem.target = target 87 | engineMenu.addItem(enterAPIKeyMenuItem) 88 | 89 | let systemPromptMenuItem = NSMenuItem(title: "Set System Prompt...", action: #selector(target.presentSystemPromptDialog(_:)), keyEquivalent: "") 90 | systemPromptMenuItem.target = target 91 | engineMenu.addItem(systemPromptMenuItem) 92 | 93 | 94 | let engineMenuItem = NSMenuItem(title: "Engine", action: nil, keyEquivalent: "") 95 | engineMenuItem.submenu = engineMenu 96 | settingsMenu.addItem(engineMenuItem) 97 | 98 | let soundOutputMenuItem = NSMenuItem(title: "Sound Output...", action: #selector(target.chooseOutput(_:)), keyEquivalent: "") 99 | soundOutputMenuItem.target = target 100 | settingsMenu.addItem(soundOutputMenuItem) 101 | 102 | let cameraMenuItem = NSMenuItem(title: "Choose Camera...", action: #selector(target.chooseCamera(_:)), keyEquivalent: "") 103 | cameraMenuItem.target = target 104 | settingsMenu.addItem(cameraMenuItem) 105 | 106 | let shortcutsMenuItem = NSMenuItem(title: "Shortcuts...", action: #selector(target.openShortcutsWindow(_:)), keyEquivalent: "") 107 | shortcutsMenuItem.target = target 108 | settingsMenu.addItem(shortcutsMenuItem) 109 | 110 | let newShortcutMenuItem = NSMenuItem(title: "New Shortcuts", action: #selector(target.addShortcut(_:)), keyEquivalent: "") 111 | newShortcutMenuItem.target = target 112 | // settingsMenu.addItem(newShortcutMenuItem) 113 | 114 | let settingsMenuItem = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "") 115 | settingsMenuItem.submenu = settingsMenu 116 | menu.addItem(settingsMenuItem) 117 | 118 | if Navigation.cgImage != nil { 119 | let saveScreenshotMenuItem = NSMenuItem(title: "Save Latest Image", action: #selector(target.saveLastImage(_:)), keyEquivalent: "s") 120 | saveScreenshotMenuItem.target = target 121 | menu.addItem(saveScreenshotMenuItem) 122 | } 123 | 124 | if Navigation.displayResults.count>1 { 125 | let saveMenuItem = NSMenuItem(title: "Save OCR Result...", action: #selector(target.saveResult(_:)), keyEquivalent: "") 126 | saveMenuItem.target = target 127 | menu.addItem(saveMenuItem) 128 | } 129 | 130 | let updateMenu = NSMenu() 131 | let aboutMenuItem = NSMenuItem(title: "About...", action: #selector(target.displayAboutWindow(_:)), keyEquivalent: "") 132 | aboutMenuItem.target = target 133 | updateMenu.addItem(aboutMenuItem) 134 | 135 | let checkForUpdatesItem = NSMenuItem(title: "Check for Updates", action: #selector(target.checkForUpdates), keyEquivalent: "") 136 | checkForUpdatesItem.target = target 137 | updateMenu.addItem(checkForUpdatesItem) 138 | 139 | let autoCheckItem = NSMenuItem(title: "Automatically Chek for Updates", action: #selector(target.toggleSetting(_:)), keyEquivalent: "") 140 | autoCheckItem.target = target 141 | updateMenu.addItem(autoCheckItem) 142 | 143 | let autoUpdateItem = NSMenuItem(title: "Automatically Install Updates", action: #selector(target.toggleSetting(_:)), keyEquivalent: "") 144 | autoUpdateItem.target = target 145 | updateMenu.addItem(autoUpdateItem) 146 | 147 | if let updater = AutoUpdateManager.shared.updaterController?.updater { 148 | autoCheckItem.state = (updater.automaticallyChecksForUpdates) ? .on : .off 149 | autoUpdateItem.state = (updater.automaticallyDownloadsUpdates) ? .on : .off 150 | } 151 | 152 | let preReleaseItem = NSMenuItem(title: "Download Pre-release", action: #selector(target.toggleSetting(_:)), keyEquivalent: "") 153 | preReleaseItem.target = target 154 | updateMenu.addItem(preReleaseItem) 155 | preReleaseItem.state = (Settings.preRelease) ? .on : .off 156 | 157 | let updateMenuItem = NSMenuItem(title: "Updates", action: nil, keyEquivalent: "") 158 | updateMenuItem.submenu = updateMenu 159 | menu.addItem(updateMenuItem) 160 | 161 | if Shortcuts.navigationActive { 162 | let dismissMenuItem = NSMenuItem(title: "Dismiss Menu", action: #selector(target.dismiss(_:)), keyEquivalent: "z") 163 | dismissMenuItem.target = target 164 | menu.addItem(dismissMenuItem) 165 | } 166 | 167 | menu.addItem(NSMenuItem(title: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")) 168 | return menu 169 | } 170 | 171 | static func installMouseMonitor() { 172 | self.eventMonitor = NSEvent.addGlobalMonitorForEvents( 173 | matching: [NSEvent.EventTypeMask.leftMouseDown, NSEvent.EventTypeMask.rightMouseDown], 174 | handler: { (event: NSEvent) in 175 | switch event.type { 176 | case .leftMouseDown: 177 | log("Left mouse click detected.") 178 | if Shortcuts.navigationActive { 179 | Thread.sleep(forTimeInterval: 0.5) 180 | Navigation.startOCR() 181 | } 182 | case .rightMouseDown: 183 | log("Right mouse click detected.") 184 | if Shortcuts.navigationActive { 185 | Thread.sleep(forTimeInterval: 0.5) 186 | Navigation.startOCR() 187 | } 188 | default: 189 | break 190 | } 191 | }) 192 | } 193 | 194 | static func removeMouseMonitor() { 195 | if let eventMonitor = self.eventMonitor { 196 | NSEvent.removeMonitor(eventMonitor) 197 | } 198 | } 199 | 200 | static func displayApiKeyDialog() { 201 | let alert = NSAlert() 202 | alert.messageText = "OpenAI API Key" 203 | alert.informativeText = "Type your OpenAI API key below:" 204 | alert.addButton(withTitle: "Save") 205 | alert.addButton(withTitle: "Cancel") 206 | let inputTextField = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24)) 207 | inputTextField.placeholderString = "API Key" 208 | inputTextField.stringValue = Settings.GPTAPIKEY 209 | alert.accessoryView = inputTextField 210 | let response = alert.runModal() 211 | hide() 212 | if response == .alertFirstButtonReturn { // OK button 213 | let apiKey = inputTextField.stringValue 214 | Settings.GPTAPIKEY = apiKey 215 | if let data = apiKey.data(using: .utf8) { 216 | let status = KeychainManager.store(key: "com.chikim.VOCR.OAIApiKey", data: data) 217 | if status == noErr { 218 | log("API key stored successfully.") 219 | } else { 220 | log("Failed to store API key with error: \(status)") 221 | } 222 | } 223 | 224 | } 225 | } 226 | 227 | static func displaySystemPromptDialog() { 228 | if let prompt = askPrompt(value:Settings.systemPrompt) { 229 | Settings.systemPrompt = prompt 230 | Settings.save() 231 | } 232 | } 233 | 234 | static func load() { 235 | let defaults = UserDefaults.standard 236 | Settings.positionReset = defaults.bool(forKey:"positionReset") 237 | Settings.positionalAudio = defaults.bool(forKey:"positionalAudio") 238 | Settings.launchOnBoot = defaults.bool(forKey:"launchOnBoot") 239 | Settings.autoScan = defaults.bool(forKey:"autoScan") 240 | Settings.detectObject = defaults.bool(forKey:"detectObject") 241 | Settings.engine = Engines(rawValue: defaults.integer(forKey:"engine"))! 242 | Settings.useLastPrompt = defaults.bool(forKey:"useLastPrompt") 243 | Settings.targetWindow = defaults.bool(forKey:"targetWindow") 244 | Settings.preRelease = defaults.bool(forKey:"preRelease") 245 | if let retrievedData = KeychainManager.retrieve(key: "com.chikim.VOCR.OAIApiKey"), 246 | let retrievedApiKey = String(data: retrievedData, encoding: .utf8) { 247 | Settings.GPTAPIKEY = retrievedApiKey 248 | } else { 249 | log("Failed to retrieve API key.") 250 | } 251 | if let mode = defaults.string(forKey: "mode") { 252 | Settings.mode = mode 253 | } 254 | if let camera = defaults.string(forKey: "camera") { 255 | Settings.camera = camera 256 | } 257 | if let prompt = defaults.string(forKey: "prompt") { 258 | Settings.prompt = prompt 259 | } 260 | if let systemPrompt = defaults.string(forKey: "systemPrompt") { 261 | Settings.systemPrompt = systemPrompt 262 | } 263 | 264 | } 265 | 266 | static func save() { 267 | let defaults = UserDefaults.standard 268 | defaults.set(Settings.positionReset, forKey:"positionReset") 269 | defaults.set(Settings.positionalAudio, forKey:"positionalAudio") 270 | defaults.set(Settings.launchOnBoot, forKey:"launchOnBoot") 271 | defaults.set(Settings.autoScan, forKey:"autoScan") 272 | defaults.set(Settings.detectObject, forKey:"detectObject") 273 | defaults.set(Settings.preRelease, forKey:"preRelease") 274 | defaults.set(Settings.engine.rawValue, forKey:"engine") 275 | defaults.set(Settings.useLastPrompt, forKey:"useLastPrompt") 276 | defaults.set(Settings.targetWindow, forKey:"targetWindow") 277 | defaults.set(Settings.prompt, forKey:"prompt") 278 | defaults.set(Settings.systemPrompt, forKey:"systemPrompt") 279 | defaults.set(Settings.mode, forKey:"mode") 280 | defaults.set(Settings.camera, forKey:"camera") 281 | } 282 | 283 | 284 | } 285 | 286 | class MenuHandler: NSObject { 287 | @objc func toggleSetting(_ sender: NSMenuItem) { 288 | hide() 289 | sender.state = (sender.state == .off) ? .on : .off 290 | switch sender.title { 291 | case "Target Window": 292 | Settings.targetWindow = sender.state == .on 293 | case "Detect Objects": 294 | Settings.detectObject = sender.state == .on 295 | case "Auto Scan": 296 | Settings.autoScan = sender.state == .on 297 | case "Reset Position on Scan": 298 | Settings.positionReset = sender.state == .on 299 | case "Positional Audio": 300 | Settings.positionalAudio = sender.state == .on 301 | case "Use Last Prompt": 302 | Settings.useLastPrompt = sender.state == .on 303 | case "Move Mouse": 304 | Settings.moveMouse = sender.state == .on 305 | case "Launch on Login": 306 | Settings.launchOnBoot = sender.state == .on 307 | case "Log": 308 | Settings.writeLog = sender.state == .on 309 | case "Download Pre-release": 310 | Settings.preRelease = sender.state == .on 311 | case "Automatically Chek for Updates": 312 | if let updater = AutoUpdateManager.shared.updaterController?.updater { 313 | updater.automaticallyChecksForUpdates = sender.state == .on 314 | } 315 | case "Automatically Install Updates": 316 | if let updater = AutoUpdateManager.shared.updaterController?.updater { 317 | updater.automaticallyDownloadsUpdates = sender.state == .on 318 | } 319 | default: break 320 | } 321 | 322 | Settings.save() 323 | } 324 | 325 | 326 | @objc func toggleAutoScan(_ sender: NSMenuItem) { 327 | toggleSetting(sender) 328 | if Settings.autoScan { 329 | Settings.installMouseMonitor() 330 | } else { 331 | Settings.removeMouseMonitor() 332 | } 333 | } 334 | 335 | 336 | @objc func toggleLaunch(_ sender: NSMenuItem) { 337 | toggleSetting(sender) 338 | let fileManager = FileManager.default 339 | let home = fileManager.homeDirectoryForCurrentUser 340 | let launchPath = "Library/LaunchAgents/com.chikim.VOCR.plist" 341 | let launchFile = home.appendingPathComponent(launchPath) 342 | if Settings.launchOnBoot { 343 | if !fileManager.fileExists(atPath: launchFile.path) { 344 | let bundle = Bundle.main 345 | let bundlePath = bundle.path(forResource: "com.chikim.VOCR", ofType: "plist") 346 | try! fileManager.copyItem(at: URL(fileURLWithPath: bundlePath!), to: launchFile) 347 | } else { 348 | try!fileManager.removeItem(at: launchFile) 349 | } 350 | } 351 | } 352 | 353 | @objc func presentApiKeyInputDialog(_ sender: AnyObject?) { 354 | Settings.displayApiKeyDialog() 355 | } 356 | 357 | @objc func presentSystemPromptDialog(_ sender: AnyObject?) { 358 | Settings.displaySystemPromptDialog() 359 | } 360 | 361 | @objc func displayAboutWindow(_ sender: Any?) { 362 | let storyboardName = NSStoryboard.Name(stringLiteral: "Main") 363 | let storyboard = NSStoryboard(name: storyboardName, bundle: nil) 364 | let storyboardID = NSStoryboard.SceneIdentifier(stringLiteral: "aboutWindowStoryboardID") 365 | if let aboutWindowController = storyboard.instantiateController(withIdentifier: storyboardID) as? NSWindowController { 366 | NSApplication.shared.activate(ignoringOtherApps: true) 367 | aboutWindowController.showWindow(nil) 368 | } 369 | } 370 | 371 | @objc func chooseOutput(_ sender: Any?) { 372 | let alert = NSAlert() 373 | alert.alertStyle = .informational 374 | alert.messageText = "Sound Output" 375 | alert.informativeText = "Choose an Output for positional audio feedback." 376 | let devices = AudioEngine.outputDevices 377 | for device in devices { 378 | alert.addButton(withTitle: device.name) 379 | } 380 | 381 | let modalResult = alert.runModal() 382 | hide() 383 | let n = modalResult.rawValue-1000 384 | Player.shared.engine.stop() 385 | try! Player.shared.engine.setDevice(AudioEngine.outputDevices[n]) 386 | try! Player.shared.engine.start() 387 | } 388 | 389 | @objc func chooseCamera(_ sender: Any?) { 390 | let devices = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera,.externalUnknown], mediaType: .video, position: .unspecified).devices 391 | if devices.count>1 { 392 | let alert = NSAlert() 393 | alert.alertStyle = .informational 394 | alert.messageText = "Camera" 395 | alert.informativeText = "Choose a camera for VOCR to use." 396 | for device in devices { 397 | alert.addButton(withTitle: device.localizedName) 398 | } 399 | let modalResult = alert.runModal() 400 | hide() 401 | let n = modalResult.rawValue-1000 402 | Settings.camera = devices[n].localizedName 403 | Settings.save() 404 | } 405 | } 406 | 407 | @objc func saveResult(_ sender: NSMenuItem) { 408 | let savePanel = NSSavePanel() 409 | savePanel.allowedContentTypes = [.text] 410 | savePanel.allowsOtherFileTypes = false 411 | savePanel.begin { (result) in 412 | hide() 413 | if result.rawValue == NSApplication.ModalResponse.OK.rawValue { 414 | if let url = savePanel.url { 415 | let text = Navigation.text() 416 | try! text.write(to: url, atomically: false, encoding: .utf8) 417 | } 418 | } 419 | let windows = NSApplication.shared.windows 420 | NSApplication.shared.hide(nil) 421 | windows[1].close() 422 | } 423 | } 424 | 425 | @objc func selectMode(_ sender: NSMenuItem) { 426 | guard let menu = sender.menu else { return } 427 | for item in menu.items { 428 | item.state = (item.title == sender.title) ? .on : .off 429 | } 430 | Settings.mode = sender.title 431 | Settings.save() 432 | } 433 | 434 | @objc func dismiss(_ sender: NSMenuItem) { 435 | 436 | } 437 | 438 | @objc func saveLastImage(_ sender: NSMenuItem) { 439 | if let cgImage = Navigation.cgImage { 440 | try! saveImage(cgImage) 441 | } 442 | } 443 | 444 | @objc func openShortcutsWindow(_ sender: NSMenuItem) { 445 | ShortcutsWindowController.shared.showWindow(nil) 446 | NSApp.activate(ignoringOtherApps: true) 447 | } 448 | 449 | @objc func addShortcut(_ sender: NSMenuItem) { 450 | let alert = NSAlert() 451 | alert.messageText = "New Shortcut" 452 | alert.addButton(withTitle: "Create") 453 | alert.addButton(withTitle: "Cancel") 454 | let inputTextField = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24)) 455 | inputTextField.placeholderString = "Shortcut Name" 456 | alert.accessoryView = inputTextField 457 | let response = alert.runModal() 458 | hide() 459 | if response == .alertFirstButtonReturn { // OK button 460 | Shortcuts.shortcuts.append(Shortcut(name: inputTextField.stringValue, key: UInt32(0), modifiers: UInt32(0), keyName:"Unassigned")) 461 | let data = try? JSONEncoder().encode(Shortcuts.shortcuts) 462 | UserDefaults.standard.set(data, forKey: "userShortcuts") 463 | Shortcuts.loadShortcuts() 464 | } 465 | } 466 | 467 | @objc func selectModel(_ sender: NSMenuItem) { 468 | Settings.engine = Engines(rawValue: sender.tag)! 469 | if Settings.engine == .ollama { 470 | Ollama.setModel() 471 | } 472 | Settings.save() 473 | } 474 | 475 | @objc func checkForUpdates() { 476 | AutoUpdateManager.shared.checkForUpdates() 477 | } 478 | 479 | } 480 | 481 | -------------------------------------------------------------------------------- /VOCR.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6D4816BE2C7EE946005E6C64 /* OCRTextSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4816BD2C7EE946005E6C64 /* OCRTextSearch.swift */; }; 11 | EA0C88682B4F8F4B00F2E920 /* ShortcutsWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0C88672B4F8F4B00F2E920 /* ShortcutsWindowController.swift */; }; 12 | EA1158CE2B51EBC000B2C716 /* Shortcuts.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1158CD2B51EBC000B2C716 /* Shortcuts.swift */; }; 13 | EA14F2E02B50B30300011F82 /* LlamaCpp.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA14F2DF2B50B30300011F82 /* LlamaCpp.swift */; }; 14 | EA1AC96A2B4C51FA00D3543F /* VOCursor.scpt in Resources */ = {isa = PBXBuildFile; fileRef = EA1AC9692B4C51FA00D3543F /* VOCursor.scpt */; }; 15 | EA1F642C2352503D0089C967 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F642B2352503D0089C967 /* Player.swift */; }; 16 | EA2D4F092B5215CD001D6D24 /* Shortcuts.json in Resources */ = {isa = PBXBuildFile; fileRef = EA2D4F082B5215CD001D6D24 /* Shortcuts.json */; }; 17 | EA2DA1AD232EB1D600D31031 /* Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA2DA1AB232EB1D600D31031 /* Accessibility.swift */; }; 18 | EA2DA1AF232EB22300D31031 /* NSRunningApplication Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA2DA1AE232EB22300D31031 /* NSRunningApplication Extension.swift */; }; 19 | EA3F43712B476759005453C2 /* gpt.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3F43702B476759005453C2 /* gpt.swift */; }; 20 | EA3F43732B4857F9005453C2 /* Observation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3F43722B4857F9005453C2 /* Observation.swift */; }; 21 | EA42F44F2A2A04440010BC39 /* AXSwift in Frameworks */ = {isa = PBXBuildFile; productRef = EA42F44E2A2A04440010BC39 /* AXSwift */; }; 22 | EA42F4512A2A05410010BC39 /* UIElement Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA42F4502A2A05410010BC39 /* UIElement Extension.swift */; }; 23 | EA5581EF2B5AF6F800408F92 /* KeychainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5581EE2B5AF6F800408F92 /* KeychainManager.swift */; }; 24 | EA5C7ACC2351BB6D00D84042 /* Navigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5C7ACB2351BB6D00D84042 /* Navigation.swift */; }; 25 | EA5C7AD02351C8DE00D84042 /* AXUIElement Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5C7ACF2351C8DE00D84042 /* AXUIElement Extension.swift */; }; 26 | EA5C7AD92351D81100D84042 /* VOScreenshot.scpt in Resources */ = {isa = PBXBuildFile; fileRef = EA5C7AD82351D81100D84042 /* VOScreenshot.scpt */; }; 27 | EA60A3B12B4D7FF0001F6EEA /* RealTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA60A3B02B4D7FF0001F6EEA /* RealTime.swift */; }; 28 | EA688D452355BDC500F722C7 /* Bundle Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA688D442355BDC500F722C7 /* Bundle Extension.swift */; }; 29 | EA78235B2B56E75E004B141B /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = EA78235A2B56E75E004B141B /* Sparkle */; }; 30 | EA8AD6412352B4A000D26871 /* Double Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA8AD6402352B4A000D26871 /* Double Extension.swift */; }; 31 | EA9AF47D2B54BD3A001B1BBE /* Ollama.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9AF47C2B54BD3A001B1BBE /* Ollama.swift */; }; 32 | EA9AF47F2B54D03D001B1BBE /* Engines.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9AF47E2B54D03D001B1BBE /* Engines.swift */; }; 33 | EA9EB89E28EA5B0A00FE6210 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9EB89D28EA5B0A00FE6210 /* Utils.swift */; }; 34 | EAAD42AE298596FB00BE5D98 /* com.chikim.VOCR.plist in Resources */ = {isa = PBXBuildFile; fileRef = EAAD42AD298596FB00BE5D98 /* com.chikim.VOCR.plist */; }; 35 | EAC1C94B2B59D96200FBE97D /* AutoUpdateManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC1C94A2B59D96200FBE97D /* AutoUpdateManager.swift */; }; 36 | EAC9ECD92BFB8D6200D61F00 /* MacCamera.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9ECD82BFB8D6200D61F00 /* MacCamera.swift */; }; 37 | EAD0E5A92B57942F004E69AD /* FileLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD0E5A82B57942F004E69AD /* FileLogger.swift */; }; 38 | EAD9AAE62731075600473054 /* HotKey in Frameworks */ = {isa = PBXBuildFile; productRef = EAD9AAE52731075600473054 /* HotKey */; }; 39 | EAD9AAE927310A3900473054 /* SoundpipeAudioKit in Frameworks */ = {isa = PBXBuildFile; productRef = EAD9AAE827310A3900473054 /* SoundpipeAudioKit */; }; 40 | EAD9CFD22355E11600E7F594 /* say.scpt in Resources */ = {isa = PBXBuildFile; fileRef = EAD9CFD12355E11600E7F594 /* say.scpt */; }; 41 | EADE59B5232EB09A00E2F65A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE59B4232EB09A00E2F65A /* AppDelegate.swift */; }; 42 | EADE59B7232EB09A00E2F65A /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE59B6232EB09A00E2F65A /* AboutViewController.swift */; }; 43 | EADE59B9232EB09A00E2F65A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EADE59B8232EB09A00E2F65A /* Assets.xcassets */; }; 44 | EADE59BC232EB09A00E2F65A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EADE59BA232EB09A00E2F65A /* Main.storyboard */; }; 45 | EAF9C3C82354A66200D4D77C /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF9C3C72354A66200D4D77C /* Settings.swift */; }; 46 | /* End PBXBuildFile section */ 47 | 48 | /* Begin PBXFileReference section */ 49 | 6D4816BD2C7EE946005E6C64 /* OCRTextSearch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OCRTextSearch.swift; sourceTree = ""; }; 50 | EA0C88672B4F8F4B00F2E920 /* ShortcutsWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutsWindowController.swift; sourceTree = ""; }; 51 | EA1158CD2B51EBC000B2C716 /* Shortcuts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shortcuts.swift; sourceTree = ""; }; 52 | EA14F2DF2B50B30300011F82 /* LlamaCpp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LlamaCpp.swift; sourceTree = ""; }; 53 | EA1AC9692B4C51FA00D3543F /* VOCursor.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = VOCursor.scpt; sourceTree = ""; }; 54 | EA1F642B2352503D0089C967 /* Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = ""; }; 55 | EA2D4F082B5215CD001D6D24 /* Shortcuts.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Shortcuts.json; sourceTree = ""; }; 56 | EA2DA1AB232EB1D600D31031 /* Accessibility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Accessibility.swift; sourceTree = ""; }; 57 | EA2DA1AE232EB22300D31031 /* NSRunningApplication Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSRunningApplication Extension.swift"; sourceTree = ""; }; 58 | EA3F43702B476759005453C2 /* gpt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = gpt.swift; sourceTree = ""; }; 59 | EA3F43722B4857F9005453C2 /* Observation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Observation.swift; sourceTree = ""; }; 60 | EA42F4502A2A05410010BC39 /* UIElement Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIElement Extension.swift"; sourceTree = ""; }; 61 | EA5581EE2B5AF6F800408F92 /* KeychainManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainManager.swift; sourceTree = ""; }; 62 | EA5C7ACB2351BB6D00D84042 /* Navigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Navigation.swift; sourceTree = ""; }; 63 | EA5C7ACF2351C8DE00D84042 /* AXUIElement Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AXUIElement Extension.swift"; sourceTree = ""; }; 64 | EA5C7AD82351D81100D84042 /* VOScreenshot.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = VOScreenshot.scpt; sourceTree = ""; }; 65 | EA60A3B02B4D7FF0001F6EEA /* RealTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealTime.swift; sourceTree = ""; }; 66 | EA688D442355BDC500F722C7 /* Bundle Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle Extension.swift"; sourceTree = ""; }; 67 | EA8AD6402352B4A000D26871 /* Double Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Double Extension.swift"; sourceTree = ""; }; 68 | EA9AF47C2B54BD3A001B1BBE /* Ollama.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Ollama.swift; sourceTree = ""; }; 69 | EA9AF47E2B54D03D001B1BBE /* Engines.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Engines.swift; sourceTree = ""; }; 70 | EA9EB89D28EA5B0A00FE6210 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 71 | EAAD42AD298596FB00BE5D98 /* com.chikim.VOCR.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = com.chikim.VOCR.plist; sourceTree = ""; }; 72 | EAC1C94A2B59D96200FBE97D /* AutoUpdateManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoUpdateManager.swift; sourceTree = ""; }; 73 | EAC9ECD82BFB8D6200D61F00 /* MacCamera.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacCamera.swift; sourceTree = ""; }; 74 | EAD0E5A82B57942F004E69AD /* FileLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileLogger.swift; sourceTree = ""; }; 75 | EAD9CFD12355E11600E7F594 /* say.scpt */ = {isa = PBXFileReference; lastKnownFileType = file; path = say.scpt; sourceTree = ""; }; 76 | EADE59B1232EB09A00E2F65A /* VOCR.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VOCR.app; sourceTree = BUILT_PRODUCTS_DIR; }; 77 | EADE59B4232EB09A00E2F65A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 78 | EADE59B6232EB09A00E2F65A /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = ""; }; 79 | EADE59B8232EB09A00E2F65A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 80 | EADE59BB232EB09A00E2F65A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 81 | EADE59BD232EB09A00E2F65A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 82 | EADE59BE232EB09A00E2F65A /* VOCR.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = VOCR.entitlements; sourceTree = ""; }; 83 | EAF9C3C72354A66200D4D77C /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; 84 | /* End PBXFileReference section */ 85 | 86 | /* Begin PBXFrameworksBuildPhase section */ 87 | EADE59AE232EB09A00E2F65A /* Frameworks */ = { 88 | isa = PBXFrameworksBuildPhase; 89 | buildActionMask = 2147483647; 90 | files = ( 91 | EA42F44F2A2A04440010BC39 /* AXSwift in Frameworks */, 92 | EA78235B2B56E75E004B141B /* Sparkle in Frameworks */, 93 | EAD9AAE927310A3900473054 /* SoundpipeAudioKit in Frameworks */, 94 | EAD9AAE62731075600473054 /* HotKey in Frameworks */, 95 | ); 96 | runOnlyForDeploymentPostprocessing = 0; 97 | }; 98 | /* End PBXFrameworksBuildPhase section */ 99 | 100 | /* Begin PBXGroup section */ 101 | EA1F63FA2352496E0089C967 /* Frameworks */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | ); 105 | name = Frameworks; 106 | sourceTree = ""; 107 | }; 108 | EA5C7AD72351D81100D84042 /* Scripts */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | EA1AC9692B4C51FA00D3543F /* VOCursor.scpt */, 112 | EAD9CFD12355E11600E7F594 /* say.scpt */, 113 | EA5C7AD82351D81100D84042 /* VOScreenshot.scpt */, 114 | ); 115 | path = Scripts; 116 | sourceTree = ""; 117 | }; 118 | EADE59A8232EB09A00E2F65A = { 119 | isa = PBXGroup; 120 | children = ( 121 | EA2D4F082B5215CD001D6D24 /* Shortcuts.json */, 122 | EAAD42AD298596FB00BE5D98 /* com.chikim.VOCR.plist */, 123 | EA5C7AD72351D81100D84042 /* Scripts */, 124 | EADE59B3232EB09A00E2F65A /* VOCR */, 125 | EADE59B2232EB09A00E2F65A /* Products */, 126 | EA1F63FA2352496E0089C967 /* Frameworks */, 127 | ); 128 | sourceTree = ""; 129 | }; 130 | EADE59B2232EB09A00E2F65A /* Products */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | EADE59B1232EB09A00E2F65A /* VOCR.app */, 134 | ); 135 | name = Products; 136 | sourceTree = ""; 137 | }; 138 | EADE59B3232EB09A00E2F65A /* VOCR */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | EAC9ECD82BFB8D6200D61F00 /* MacCamera.swift */, 142 | EADE59B6232EB09A00E2F65A /* AboutViewController.swift */, 143 | EA2DA1AB232EB1D600D31031 /* Accessibility.swift */, 144 | EADE59B4232EB09A00E2F65A /* AppDelegate.swift */, 145 | EADE59B8232EB09A00E2F65A /* Assets.xcassets */, 146 | EA5C7ACF2351C8DE00D84042 /* AXUIElement Extension.swift */, 147 | EA688D442355BDC500F722C7 /* Bundle Extension.swift */, 148 | EA8AD6402352B4A000D26871 /* Double Extension.swift */, 149 | EA9AF47E2B54D03D001B1BBE /* Engines.swift */, 150 | EAD0E5A82B57942F004E69AD /* FileLogger.swift */, 151 | EA3F43702B476759005453C2 /* gpt.swift */, 152 | EADE59BD232EB09A00E2F65A /* Info.plist */, 153 | EA14F2DF2B50B30300011F82 /* LlamaCpp.swift */, 154 | EADE59BA232EB09A00E2F65A /* Main.storyboard */, 155 | EA5C7ACB2351BB6D00D84042 /* Navigation.swift */, 156 | EA2DA1AE232EB22300D31031 /* NSRunningApplication Extension.swift */, 157 | EA3F43722B4857F9005453C2 /* Observation.swift */, 158 | 6D4816BD2C7EE946005E6C64 /* OCRTextSearch.swift */, 159 | EA9AF47C2B54BD3A001B1BBE /* Ollama.swift */, 160 | EA1F642B2352503D0089C967 /* Player.swift */, 161 | EA60A3B02B4D7FF0001F6EEA /* RealTime.swift */, 162 | EAF9C3C72354A66200D4D77C /* Settings.swift */, 163 | EA1158CD2B51EBC000B2C716 /* Shortcuts.swift */, 164 | EA0C88672B4F8F4B00F2E920 /* ShortcutsWindowController.swift */, 165 | EA42F4502A2A05410010BC39 /* UIElement Extension.swift */, 166 | EA9EB89D28EA5B0A00FE6210 /* Utils.swift */, 167 | EADE59BE232EB09A00E2F65A /* VOCR.entitlements */, 168 | EAC1C94A2B59D96200FBE97D /* AutoUpdateManager.swift */, 169 | EA5581EE2B5AF6F800408F92 /* KeychainManager.swift */, 170 | ); 171 | path = VOCR; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXGroup section */ 175 | 176 | /* Begin PBXNativeTarget section */ 177 | EADE59B0232EB09A00E2F65A /* VOCR */ = { 178 | isa = PBXNativeTarget; 179 | buildConfigurationList = EADE59C1232EB09A00E2F65A /* Build configuration list for PBXNativeTarget "VOCR" */; 180 | buildPhases = ( 181 | EADE59AD232EB09A00E2F65A /* Sources */, 182 | EADE59AE232EB09A00E2F65A /* Frameworks */, 183 | EADE59AF232EB09A00E2F65A /* Resources */, 184 | ); 185 | buildRules = ( 186 | ); 187 | dependencies = ( 188 | ); 189 | name = VOCR; 190 | packageProductDependencies = ( 191 | EAD9AAE52731075600473054 /* HotKey */, 192 | EAD9AAE827310A3900473054 /* SoundpipeAudioKit */, 193 | EA42F44E2A2A04440010BC39 /* AXSwift */, 194 | EA78235A2B56E75E004B141B /* Sparkle */, 195 | ); 196 | productName = VOCR; 197 | productReference = EADE59B1232EB09A00E2F65A /* VOCR.app */; 198 | productType = "com.apple.product-type.application"; 199 | }; 200 | /* End PBXNativeTarget section */ 201 | 202 | /* Begin PBXProject section */ 203 | EADE59A9232EB09A00E2F65A /* Project object */ = { 204 | isa = PBXProject; 205 | attributes = { 206 | BuildIndependentTargetsInParallel = YES; 207 | LastSwiftUpdateCheck = 1100; 208 | LastUpgradeCheck = 1620; 209 | ORGANIZATIONNAME = "Chi Kim"; 210 | TargetAttributes = { 211 | EADE59B0232EB09A00E2F65A = { 212 | CreatedOnToolsVersion = 11.0; 213 | }; 214 | }; 215 | }; 216 | buildConfigurationList = EADE59AC232EB09A00E2F65A /* Build configuration list for PBXProject "VOCR" */; 217 | compatibilityVersion = "Xcode 9.3"; 218 | developmentRegion = en; 219 | hasScannedForEncodings = 0; 220 | knownRegions = ( 221 | en, 222 | Base, 223 | ); 224 | mainGroup = EADE59A8232EB09A00E2F65A; 225 | packageReferences = ( 226 | EAD9AAE42731075600473054 /* XCRemoteSwiftPackageReference "HotKey" */, 227 | EAD9AAE727310A3900473054 /* XCRemoteSwiftPackageReference "SoundpipeAudioKit" */, 228 | EA42F44D2A2A04440010BC39 /* XCRemoteSwiftPackageReference "AXSwift" */, 229 | EA7823592B56E75E004B141B /* XCRemoteSwiftPackageReference "Sparkle" */, 230 | ); 231 | productRefGroup = EADE59B2232EB09A00E2F65A /* Products */; 232 | projectDirPath = ""; 233 | projectRoot = ""; 234 | targets = ( 235 | EADE59B0232EB09A00E2F65A /* VOCR */, 236 | ); 237 | }; 238 | /* End PBXProject section */ 239 | 240 | /* Begin PBXResourcesBuildPhase section */ 241 | EADE59AF232EB09A00E2F65A /* Resources */ = { 242 | isa = PBXResourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | EADE59B9232EB09A00E2F65A /* Assets.xcassets in Resources */, 246 | EAD9CFD22355E11600E7F594 /* say.scpt in Resources */, 247 | EA1AC96A2B4C51FA00D3543F /* VOCursor.scpt in Resources */, 248 | EA2D4F092B5215CD001D6D24 /* Shortcuts.json in Resources */, 249 | EA5C7AD92351D81100D84042 /* VOScreenshot.scpt in Resources */, 250 | EADE59BC232EB09A00E2F65A /* Main.storyboard in Resources */, 251 | EAAD42AE298596FB00BE5D98 /* com.chikim.VOCR.plist in Resources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | /* End PBXResourcesBuildPhase section */ 256 | 257 | /* Begin PBXSourcesBuildPhase section */ 258 | EADE59AD232EB09A00E2F65A /* Sources */ = { 259 | isa = PBXSourcesBuildPhase; 260 | buildActionMask = 2147483647; 261 | files = ( 262 | EADE59B7232EB09A00E2F65A /* AboutViewController.swift in Sources */, 263 | EA8AD6412352B4A000D26871 /* Double Extension.swift in Sources */, 264 | EA5C7AD02351C8DE00D84042 /* AXUIElement Extension.swift in Sources */, 265 | EAC1C94B2B59D96200FBE97D /* AutoUpdateManager.swift in Sources */, 266 | EADE59B5232EB09A00E2F65A /* AppDelegate.swift in Sources */, 267 | EA688D452355BDC500F722C7 /* Bundle Extension.swift in Sources */, 268 | EA3F43712B476759005453C2 /* gpt.swift in Sources */, 269 | EAD0E5A92B57942F004E69AD /* FileLogger.swift in Sources */, 270 | EA2DA1AF232EB22300D31031 /* NSRunningApplication Extension.swift in Sources */, 271 | EA3F43732B4857F9005453C2 /* Observation.swift in Sources */, 272 | EA1158CE2B51EBC000B2C716 /* Shortcuts.swift in Sources */, 273 | EA14F2E02B50B30300011F82 /* LlamaCpp.swift in Sources */, 274 | EA9EB89E28EA5B0A00FE6210 /* Utils.swift in Sources */, 275 | EA2DA1AD232EB1D600D31031 /* Accessibility.swift in Sources */, 276 | EA42F4512A2A05410010BC39 /* UIElement Extension.swift in Sources */, 277 | EA60A3B12B4D7FF0001F6EEA /* RealTime.swift in Sources */, 278 | EA5C7ACC2351BB6D00D84042 /* Navigation.swift in Sources */, 279 | EA5581EF2B5AF6F800408F92 /* KeychainManager.swift in Sources */, 280 | EA9AF47D2B54BD3A001B1BBE /* Ollama.swift in Sources */, 281 | 6D4816BE2C7EE946005E6C64 /* OCRTextSearch.swift in Sources */, 282 | EAF9C3C82354A66200D4D77C /* Settings.swift in Sources */, 283 | EAC9ECD92BFB8D6200D61F00 /* MacCamera.swift in Sources */, 284 | EA1F642C2352503D0089C967 /* Player.swift in Sources */, 285 | EA0C88682B4F8F4B00F2E920 /* ShortcutsWindowController.swift in Sources */, 286 | EA9AF47F2B54D03D001B1BBE /* Engines.swift in Sources */, 287 | ); 288 | runOnlyForDeploymentPostprocessing = 0; 289 | }; 290 | /* End PBXSourcesBuildPhase section */ 291 | 292 | /* Begin PBXVariantGroup section */ 293 | EADE59BA232EB09A00E2F65A /* Main.storyboard */ = { 294 | isa = PBXVariantGroup; 295 | children = ( 296 | EADE59BB232EB09A00E2F65A /* Base */, 297 | ); 298 | name = Main.storyboard; 299 | sourceTree = ""; 300 | }; 301 | /* End PBXVariantGroup section */ 302 | 303 | /* Begin XCBuildConfiguration section */ 304 | EADE59BF232EB09A00E2F65A /* Debug */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ALWAYS_SEARCH_USER_PATHS = NO; 308 | CLANG_ANALYZER_NONNULL = YES; 309 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 310 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 311 | CLANG_CXX_LIBRARY = "libc++"; 312 | CLANG_ENABLE_MODULES = YES; 313 | CLANG_ENABLE_OBJC_ARC = YES; 314 | CLANG_ENABLE_OBJC_WEAK = YES; 315 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 316 | CLANG_WARN_BOOL_CONVERSION = YES; 317 | CLANG_WARN_COMMA = YES; 318 | CLANG_WARN_CONSTANT_CONVERSION = YES; 319 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 320 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 321 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 322 | CLANG_WARN_EMPTY_BODY = YES; 323 | CLANG_WARN_ENUM_CONVERSION = YES; 324 | CLANG_WARN_INFINITE_RECURSION = YES; 325 | CLANG_WARN_INT_CONVERSION = YES; 326 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 327 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 328 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 329 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 330 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 331 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 332 | CLANG_WARN_STRICT_PROTOTYPES = YES; 333 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 334 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 335 | CLANG_WARN_UNREACHABLE_CODE = YES; 336 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 337 | COPY_PHASE_STRIP = NO; 338 | DEAD_CODE_STRIPPING = YES; 339 | DEBUG_INFORMATION_FORMAT = dwarf; 340 | ENABLE_STRICT_OBJC_MSGSEND = YES; 341 | ENABLE_TESTABILITY = YES; 342 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 343 | GCC_C_LANGUAGE_STANDARD = gnu11; 344 | GCC_DYNAMIC_NO_PIC = NO; 345 | GCC_NO_COMMON_BLOCKS = YES; 346 | GCC_OPTIMIZATION_LEVEL = 0; 347 | GCC_PREPROCESSOR_DEFINITIONS = ( 348 | "DEBUG=1", 349 | "$(inherited)", 350 | ); 351 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 352 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 353 | GCC_WARN_UNDECLARED_SELECTOR = YES; 354 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 355 | GCC_WARN_UNUSED_FUNCTION = YES; 356 | GCC_WARN_UNUSED_VARIABLE = YES; 357 | MACOSX_DEPLOYMENT_TARGET = 12.0; 358 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 359 | MTL_FAST_MATH = YES; 360 | ONLY_ACTIVE_ARCH = YES; 361 | OTHER_LDFLAGS = "-lc++"; 362 | SDKROOT = macosx; 363 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 364 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 365 | }; 366 | name = Debug; 367 | }; 368 | EADE59C0232EB09A00E2F65A /* Release */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | ALWAYS_SEARCH_USER_PATHS = NO; 372 | CLANG_ANALYZER_NONNULL = YES; 373 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 374 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 375 | CLANG_CXX_LIBRARY = "libc++"; 376 | CLANG_ENABLE_MODULES = YES; 377 | CLANG_ENABLE_OBJC_ARC = YES; 378 | CLANG_ENABLE_OBJC_WEAK = YES; 379 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 380 | CLANG_WARN_BOOL_CONVERSION = YES; 381 | CLANG_WARN_COMMA = YES; 382 | CLANG_WARN_CONSTANT_CONVERSION = YES; 383 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 384 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 385 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 386 | CLANG_WARN_EMPTY_BODY = YES; 387 | CLANG_WARN_ENUM_CONVERSION = YES; 388 | CLANG_WARN_INFINITE_RECURSION = YES; 389 | CLANG_WARN_INT_CONVERSION = YES; 390 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 391 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 392 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 393 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 394 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 395 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 396 | CLANG_WARN_STRICT_PROTOTYPES = YES; 397 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 398 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 399 | CLANG_WARN_UNREACHABLE_CODE = YES; 400 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 401 | COPY_PHASE_STRIP = NO; 402 | DEAD_CODE_STRIPPING = YES; 403 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 404 | ENABLE_NS_ASSERTIONS = NO; 405 | ENABLE_STRICT_OBJC_MSGSEND = YES; 406 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 407 | GCC_C_LANGUAGE_STANDARD = gnu11; 408 | GCC_NO_COMMON_BLOCKS = YES; 409 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 410 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 411 | GCC_WARN_UNDECLARED_SELECTOR = YES; 412 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 413 | GCC_WARN_UNUSED_FUNCTION = YES; 414 | GCC_WARN_UNUSED_VARIABLE = YES; 415 | MACOSX_DEPLOYMENT_TARGET = 12.0; 416 | MTL_ENABLE_DEBUG_INFO = NO; 417 | MTL_FAST_MATH = YES; 418 | OTHER_LDFLAGS = "-lc++"; 419 | SDKROOT = macosx; 420 | SWIFT_COMPILATION_MODE = wholemodule; 421 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 422 | }; 423 | name = Release; 424 | }; 425 | EADE59C2232EB09A00E2F65A /* Debug */ = { 426 | isa = XCBuildConfiguration; 427 | buildSettings = { 428 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 429 | CODE_SIGN_ENTITLEMENTS = VOCR/VOCR.entitlements; 430 | CODE_SIGN_IDENTITY = "Apple Development"; 431 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 432 | CODE_SIGN_STYLE = Automatic; 433 | COMBINE_HIDPI_IMAGES = YES; 434 | CURRENT_PROJECT_VERSION = 50; 435 | DEAD_CODE_STRIPPING = YES; 436 | DEVELOPMENT_TEAM = 9N598S2535; 437 | ENABLE_HARDENED_RUNTIME = YES; 438 | FRAMEWORK_SEARCH_PATHS = "$(inherited)"; 439 | INFOPLIST_FILE = VOCR/Info.plist; 440 | INFOPLIST_KEY_CFBundleDisplayName = VOCR; 441 | INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; 442 | LD_RUNPATH_SEARCH_PATHS = ( 443 | "$(inherited)", 444 | "@executable_path/../Frameworks", 445 | ); 446 | MACOSX_DEPLOYMENT_TARGET = 13.0; 447 | MARKETING_VERSION = 2.3.1; 448 | PRODUCT_BUNDLE_IDENTIFIER = com.chikim.VOCR; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | SWIFT_VERSION = 5.0; 451 | }; 452 | name = Debug; 453 | }; 454 | EADE59C3232EB09A00E2F65A /* Release */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 458 | CODE_SIGN_ENTITLEMENTS = VOCR/VOCR.entitlements; 459 | CODE_SIGN_IDENTITY = "Apple Development"; 460 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 461 | CODE_SIGN_STYLE = Automatic; 462 | COMBINE_HIDPI_IMAGES = YES; 463 | CURRENT_PROJECT_VERSION = 50; 464 | DEAD_CODE_STRIPPING = YES; 465 | DEVELOPMENT_TEAM = 9N598S2535; 466 | ENABLE_HARDENED_RUNTIME = YES; 467 | FRAMEWORK_SEARCH_PATHS = "$(inherited)"; 468 | INFOPLIST_FILE = VOCR/Info.plist; 469 | INFOPLIST_KEY_CFBundleDisplayName = VOCR; 470 | INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; 471 | LD_RUNPATH_SEARCH_PATHS = ( 472 | "$(inherited)", 473 | "@executable_path/../Frameworks", 474 | ); 475 | MACOSX_DEPLOYMENT_TARGET = 13.0; 476 | MARKETING_VERSION = 2.3.1; 477 | PRODUCT_BUNDLE_IDENTIFIER = com.chikim.VOCR; 478 | PRODUCT_NAME = "$(TARGET_NAME)"; 479 | SWIFT_VERSION = 5.0; 480 | }; 481 | name = Release; 482 | }; 483 | /* End XCBuildConfiguration section */ 484 | 485 | /* Begin XCConfigurationList section */ 486 | EADE59AC232EB09A00E2F65A /* Build configuration list for PBXProject "VOCR" */ = { 487 | isa = XCConfigurationList; 488 | buildConfigurations = ( 489 | EADE59BF232EB09A00E2F65A /* Debug */, 490 | EADE59C0232EB09A00E2F65A /* Release */, 491 | ); 492 | defaultConfigurationIsVisible = 0; 493 | defaultConfigurationName = Release; 494 | }; 495 | EADE59C1232EB09A00E2F65A /* Build configuration list for PBXNativeTarget "VOCR" */ = { 496 | isa = XCConfigurationList; 497 | buildConfigurations = ( 498 | EADE59C2232EB09A00E2F65A /* Debug */, 499 | EADE59C3232EB09A00E2F65A /* Release */, 500 | ); 501 | defaultConfigurationIsVisible = 0; 502 | defaultConfigurationName = Release; 503 | }; 504 | /* End XCConfigurationList section */ 505 | 506 | /* Begin XCRemoteSwiftPackageReference section */ 507 | EA42F44D2A2A04440010BC39 /* XCRemoteSwiftPackageReference "AXSwift" */ = { 508 | isa = XCRemoteSwiftPackageReference; 509 | repositoryURL = "https://github.com/tmandry/AXSwift"; 510 | requirement = { 511 | branch = main; 512 | kind = branch; 513 | }; 514 | }; 515 | EA7823592B56E75E004B141B /* XCRemoteSwiftPackageReference "Sparkle" */ = { 516 | isa = XCRemoteSwiftPackageReference; 517 | repositoryURL = "https://github.com/sparkle-project/Sparkle"; 518 | requirement = { 519 | kind = upToNextMajorVersion; 520 | minimumVersion = 2.0.0; 521 | }; 522 | }; 523 | EAD9AAE42731075600473054 /* XCRemoteSwiftPackageReference "HotKey" */ = { 524 | isa = XCRemoteSwiftPackageReference; 525 | repositoryURL = "https://github.com/soffes/HotKey"; 526 | requirement = { 527 | kind = upToNextMajorVersion; 528 | minimumVersion = 0.1.3; 529 | }; 530 | }; 531 | EAD9AAE727310A3900473054 /* XCRemoteSwiftPackageReference "SoundpipeAudioKit" */ = { 532 | isa = XCRemoteSwiftPackageReference; 533 | repositoryURL = "https://github.com/AudioKit/SoundpipeAudioKit.git"; 534 | requirement = { 535 | kind = upToNextMajorVersion; 536 | minimumVersion = 5.0.0; 537 | }; 538 | }; 539 | /* End XCRemoteSwiftPackageReference section */ 540 | 541 | /* Begin XCSwiftPackageProductDependency section */ 542 | EA42F44E2A2A04440010BC39 /* AXSwift */ = { 543 | isa = XCSwiftPackageProductDependency; 544 | package = EA42F44D2A2A04440010BC39 /* XCRemoteSwiftPackageReference "AXSwift" */; 545 | productName = AXSwift; 546 | }; 547 | EA78235A2B56E75E004B141B /* Sparkle */ = { 548 | isa = XCSwiftPackageProductDependency; 549 | package = EA7823592B56E75E004B141B /* XCRemoteSwiftPackageReference "Sparkle" */; 550 | productName = Sparkle; 551 | }; 552 | EAD9AAE52731075600473054 /* HotKey */ = { 553 | isa = XCSwiftPackageProductDependency; 554 | package = EAD9AAE42731075600473054 /* XCRemoteSwiftPackageReference "HotKey" */; 555 | productName = HotKey; 556 | }; 557 | EAD9AAE827310A3900473054 /* SoundpipeAudioKit */ = { 558 | isa = XCSwiftPackageProductDependency; 559 | package = EAD9AAE727310A3900473054 /* XCRemoteSwiftPackageReference "SoundpipeAudioKit" */; 560 | productName = SoundpipeAudioKit; 561 | }; 562 | /* End XCSwiftPackageProductDependency section */ 563 | }; 564 | rootObject = EADE59A9232EB09A00E2F65A /* Project object */; 565 | } 566 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------