Skip to content

Commit

Permalink
If VO not running, speak with speech synthesizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
chigkim committed May 24, 2024
1 parent a2b1b83 commit a8db631
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions VOCR/Accessibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,22 @@ enum Accessibility {
}
}

static func isVoiceOverRunning() -> Bool {
let runningApplications = NSWorkspace.shared.runningApplications
for app in runningApplications {
if app.localizedName == "VoiceOver" {
return true
}
}
return false
}

static func speak(_ message:String) {
if !isVoiceOverRunning() {
speakWithSynthesizer(message)
return
}

let bundle = Bundle.main
let url = bundle.url(forResource: "say", withExtension: "scpt")
let parameters = NSAppleEventDescriptor.list()
Expand All @@ -45,6 +60,7 @@ enum Accessibility {
if let scriptObject = NSAppleScript(contentsOf: url!, error: &error) {
var outputError:NSDictionary?
if let output = scriptObject.executeAppleEvent(event, error: &outputError).stringValue {
debugPrint(outputError)
log("Speak: \(output)")
} else {
log("Output Error: \(String(describing: outputError))")
Expand Down

0 comments on commit a8db631

Please sign in to comment.