The best way to control Claude Code, Codex and more from any computer or phone
| 1 | // t3-apple-speech available -> {"value":"en-US,fr-FR,..."} |
| 2 | // t3-apple-speech prepare <locale> -> {"value":"en-US"} (resolved locale) |
| 3 | // t3-apple-speech transcribe <locale> <wav-path> -> {"value":"..."} (transcript) |
| 4 | // Exit codes are consumed by AppleSpeech.ts; failures print one message line to stderr. |
| 5 | |
| 6 | import Foundation |
| 7 | |
| 8 | private enum ExitCode: Int32 { |
| 9 | case failure = 1 |
| 10 | case unsupportedLocale = 2 |
| 11 | case unavailable = 3 |
| 12 | case usage = 64 |
| 13 | } |
| 14 | |
| 15 | @main |
| 16 | struct AppleSpeech { |
| 17 | static func main() async { |
| 18 | let arguments = Array(CommandLine.arguments.dropFirst()) |
| 19 | do { |
| 20 | switch (arguments.first, arguments.count) { |
| 21 | case ("available", 1): |
| 22 | try write(try await AppleSpeechEngine.supportedLocales().joined(separator: ",")) |
| 23 | case ("prepare", 2): |
| 24 | try write(try await AppleSpeechEngine.prepare(arguments[1])) |
| 25 | case ("transcribe", 3): |
| 26 | try write(try await AppleSpeechEngine.transcribe(arguments[1], file: URL(fileURLWithPath: arguments[2]))) |
| 27 | default: |
| 28 | fail(.usage, "Unknown command.") |
| 29 | } |
| 30 | } catch let failure as AppleSpeechEngine.Failure { |
| 31 | switch failure { |
| 32 | case .unsupportedLocale: fail(.unsupportedLocale, failure.localizedDescription) |
| 33 | case .unavailable: fail(.unavailable, failure.localizedDescription) |
| 34 | case .unknownAssetStatus: fail(.failure, failure.localizedDescription) |
| 35 | } |
| 36 | } catch { |
| 37 | fail(.failure, error.localizedDescription) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private static func write(_ value: String) throws { |
| 42 | FileHandle.standardOutput.write(try JSONSerialization.data(withJSONObject: ["value": value])) |
| 43 | } |
| 44 | |
| 45 | private static func fail(_ code: ExitCode, _ message: String) -> Never { |
| 46 | FileHandle.standardError.write(Data((message + "\n").utf8)) |
| 47 | exit(code.rawValue) |
| 48 | } |
| 49 | } |