Created
April 15, 2020 18:01
-
-
Save JotaroS/566ee7b33c043a278b870331a4bae536 to your computer and use it in GitHub Desktop.
easy speech recognition with command-line based swift app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import AppKit | |
class Dispatcher: NSObject, NSSpeechRecognizerDelegate { | |
var stop: Bool | |
override init () {stop = false} | |
func speechRecognizer(_ sender: NSSpeechRecognizer, didRecognizeCommand command: String) | |
{ | |
print("command: \(command)") | |
stop = true | |
} | |
} | |
let dispatcher = Dispatcher() | |
let recognizer = NSSpeechRecognizer()! | |
recognizer.delegate = dispatcher | |
recognizer.commands = ["rock", "paper", "scissors"] | |
recognizer.startListening() | |
recognizer.displayedCommandsTitle = "test" | |
let loop = RunLoop.current | |
let mode = loop.currentMode ?? RunLoop.Mode.default | |
while loop.run(mode:mode, before: Date(timeIntervalSinceNow: 0.1)) | |
&& !dispatcher.stop {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment