diff --git a/src/integrations/speech-transcribe.js b/src/integrations/speech-transcribe.js index ba09a0d..09a6e80 100644 --- a/src/integrations/speech-transcribe.js +++ b/src/integrations/speech-transcribe.js @@ -181,6 +181,7 @@ async function buildAndRunTranscriber({ audioPath, locale = "en-US" }) { fputsStderr(`Compiling transcriber for ${audioPath}...\n`); const compileCmd = await execFileAsync("/usr/bin/swiftc", [ "-O", + "-parse-as-library", swiftFile, "-o", binFile, "-framework", "AVFoundation", @@ -258,21 +259,31 @@ export async function speechListLocales() { const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "speech-locale-")); const swiftFile = path.join(tmpDir, "ListLocales.swift"); const binFile = path.join(tmpDir, "list_bin"); - const swiftSrc = String.raw` -import Speech + const swiftSrc = `import Speech import Foundation @main struct L { static func main() async { - // Ensure we trigger asset inventory awareness + let isAvail = SpeechTranscriber.isAvailable + let supported: [String] + let installed: [String] + // These may be async in newer SDKs + // Try sync first, fallback to await if needed via Any + if #available(macOS 26.0, *) { + supported = await SpeechTranscriber.supportedLocales.map { $0.identifier }.sorted() + installed = await SpeechTranscriber.installedLocales.map { $0.identifier }.sorted() + } else { + supported = SpeechTranscriber.supportedLocales.map { $0.identifier }.sorted() + installed = SpeechTranscriber.installedLocales.map { $0.identifier }.sorted() + } let payload: [String: Any] = [ - "isAvailable": SpeechTranscriber.isAvailable, - "supported": SpeechTranscriber.supportedLocales.map{$0.identifier}.sorted(), - "installed": SpeechTranscriber.installedLocales.map{$0.identifier}.sorted(), + "isAvailable": isAvail, + "supported": supported, + "installed": installed, "macOS": ProcessInfo.processInfo.operatingSystemVersionString, "maxReserved": AssetInventory.maximumReservedLocales, - "reserved": AssetInventory.reservedLocales.map{$0.identifier} + "reserved": AssetInventory.reservedLocales.map { $0.identifier } ] let d = try! JSONSerialization.data(withJSONObject: payload, options: [.prettyPrinted, .sortedKeys]) FileHandle.standardOutput.write(d) @@ -281,13 +292,13 @@ struct L { `; await writeFile(swiftFile, swiftSrc, "utf8"); try { - await execFileAsync("/usr/bin/swiftc", ["-O", swiftFile, "-o", binFile, "-framework", "Speech"], { timeout: 30_000 }); + await execFileAsync("/usr/bin/swiftc", ["-O", "-parse-as-library", swiftFile, "-o", binFile, "-framework", "Speech"], { timeout: 30_000 }); const { stdout } = await execFileAsync(binFile, [], { timeout: 15_000 }); await cleanup(tmpDir); return JSON.parse(stdout); } catch (e) { await cleanup(tmpDir); - throw new Error(`List locales failed: ${e.stderr || e.message}`); + throw new Error(`List locales failed: ${e.stderr || e.message}\n${e.stdout || ""}`); } }