- Adicionado estrutura completa do projeto - Configurado MCP server para Premiere Pro - Adicionado documentação e skills - Configurado Gitignore para o projeto
45 lines
2.1 KiB
Swift
45 lines
2.1 KiB
Swift
import AppKit
|
|
import Foundation
|
|
import Speech
|
|
|
|
final class AppDelegate: NSObject, NSApplicationDelegate {
|
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
guard CommandLine.arguments.count >= 3 else { finalizar("uso: arquivo locale [somente_no_dispositivo]", 2); return }
|
|
let url = URL(fileURLWithPath: CommandLine.arguments[1])
|
|
let locale = Locale(identifier: CommandLine.arguments[2])
|
|
let somenteNoDispositivo = CommandLine.arguments.count > 3 && CommandLine.arguments[3] == "true"
|
|
guard let recognizer = SFSpeechRecognizer(locale: locale), recognizer.isAvailable else {
|
|
finalizar("Apple Speech indisponível para o locale solicitado", 3); return
|
|
}
|
|
SFSpeechRecognizer.requestAuthorization { status in
|
|
guard status == .authorized else { self.finalizar("Permissão do Apple Speech não concedida", 4); return }
|
|
let request = SFSpeechURLRecognitionRequest(url: url)
|
|
request.shouldReportPartialResults = false
|
|
if somenteNoDispositivo && recognizer.supportsOnDeviceRecognition { request.requiresOnDeviceRecognition = true }
|
|
recognizer.recognitionTask(with: request) { result, error in
|
|
if let result = result, result.isFinal {
|
|
let segmentos = result.bestTranscription.segments.map {
|
|
["inicio": $0.timestamp, "fim": $0.timestamp + $0.duration,
|
|
"texto": $0.substring, "confianca": $0.confidence] as [String: Any]
|
|
}
|
|
let data = try! JSONSerialization.data(withJSONObject: ["segmentos": segmentos])
|
|
print(String(data: data, encoding: .utf8)!)
|
|
}
|
|
if error != nil || result?.isFinal == true { self.finalizar(nil, 0) }
|
|
}
|
|
}
|
|
}
|
|
|
|
private func finalizar(_ mensagem: String?, _ codigo: Int32) {
|
|
if let mensagem { fputs(mensagem + "\n", stderr) }
|
|
NSApplication.shared.terminate(nil)
|
|
exit(codigo)
|
|
}
|
|
}
|
|
|
|
let app = NSApplication.shared
|
|
let delegate = AppDelegate()
|
|
app.delegate = delegate
|
|
app.setActivationPolicy(.accessory)
|
|
app.run()
|