وویس تایپینگ سانی اوکس مک
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

85 lines
2.7 KiB

import Foundation
import AppIntents
@available(macOS 13.0, *)
public struct StartRecordingIntent: AppIntent {
public static var title: LocalizedStringResource = "Start Recording"
public static var description = IntentDescription("Starts voice recording with Soniox Voice")
public static var openAppWhenRun: Bool = false
public init() {}
@MainActor
public func perform() async throws -> some IntentResult {
print("StartRecordingIntent: Executing startRecording via AppIntent...")
// 1. In-process direct execution if running in the main app
if let app = AppDelegate.shared {
app.startRecording()
}
// 2. Out-of-process IPC notification (for when Shortcuts runner executes this)
DistributedNotificationCenter.default().postNotificationName(
NSNotification.Name("com.soniox.voice.start"),
object: nil,
userInfo: nil,
deliverImmediately: true
)
return .result()
}
}
@available(macOS 13.0, *)
public struct StopRecordingIntent: AppIntent {
public static var title: LocalizedStringResource = "Stop Recording"
public static var description = IntentDescription("Stops active voice recording and finalizes text paste")
public static var openAppWhenRun: Bool = false
public init() {}
@MainActor
public func perform() async throws -> some IntentResult {
print("StopRecordingIntent: Executing stopRecording via AppIntent...")
if let app = AppDelegate.shared {
app.stopRecording()
}
DistributedNotificationCenter.default().postNotificationName(
NSNotification.Name("com.soniox.voice.stop"),
object: nil,
userInfo: nil,
deliverImmediately: true
)
return .result()
}
}
@available(macOS 13.0, *)
public struct ToggleRecordingIntent: AppIntent {
public static var title: LocalizedStringResource = "Toggle Recording"
public static var description = IntentDescription("Toggles voice recording on or off")
public static var openAppWhenRun: Bool = false
public init() {}
@MainActor
public func perform() async throws -> some IntentResult {
print("ToggleRecordingIntent: Executing toggleRecording via AppIntent...")
if let app = AppDelegate.shared {
app.toggleRecording()
}
DistributedNotificationCenter.default().postNotificationName(
NSNotification.Name("com.soniox.voice.toggle"),
object: nil,
userInfo: nil,
deliverImmediately: true
)
return .result()
}
}