Fix speech tools: add -parse-as-library for @main, handle async supportedLocales (macOS 26 may be async)
This commit is contained in:
@@ -181,6 +181,7 @@ async function buildAndRunTranscriber({ audioPath, locale = "en-US" }) {
|
|||||||
fputsStderr(`Compiling transcriber for ${audioPath}...\n`);
|
fputsStderr(`Compiling transcriber for ${audioPath}...\n`);
|
||||||
const compileCmd = await execFileAsync("/usr/bin/swiftc", [
|
const compileCmd = await execFileAsync("/usr/bin/swiftc", [
|
||||||
"-O",
|
"-O",
|
||||||
|
"-parse-as-library",
|
||||||
swiftFile,
|
swiftFile,
|
||||||
"-o", binFile,
|
"-o", binFile,
|
||||||
"-framework", "AVFoundation",
|
"-framework", "AVFoundation",
|
||||||
@@ -258,18 +259,28 @@ export async function speechListLocales() {
|
|||||||
const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "speech-locale-"));
|
const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "speech-locale-"));
|
||||||
const swiftFile = path.join(tmpDir, "ListLocales.swift");
|
const swiftFile = path.join(tmpDir, "ListLocales.swift");
|
||||||
const binFile = path.join(tmpDir, "list_bin");
|
const binFile = path.join(tmpDir, "list_bin");
|
||||||
const swiftSrc = String.raw`
|
const swiftSrc = `import Speech
|
||||||
import Speech
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@main
|
@main
|
||||||
struct L {
|
struct L {
|
||||||
static func main() async {
|
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] = [
|
let payload: [String: Any] = [
|
||||||
"isAvailable": SpeechTranscriber.isAvailable,
|
"isAvailable": isAvail,
|
||||||
"supported": SpeechTranscriber.supportedLocales.map{$0.identifier}.sorted(),
|
"supported": supported,
|
||||||
"installed": SpeechTranscriber.installedLocales.map{$0.identifier}.sorted(),
|
"installed": installed,
|
||||||
"macOS": ProcessInfo.processInfo.operatingSystemVersionString,
|
"macOS": ProcessInfo.processInfo.operatingSystemVersionString,
|
||||||
"maxReserved": AssetInventory.maximumReservedLocales,
|
"maxReserved": AssetInventory.maximumReservedLocales,
|
||||||
"reserved": AssetInventory.reservedLocales.map { $0.identifier }
|
"reserved": AssetInventory.reservedLocales.map { $0.identifier }
|
||||||
@@ -281,13 +292,13 @@ struct L {
|
|||||||
`;
|
`;
|
||||||
await writeFile(swiftFile, swiftSrc, "utf8");
|
await writeFile(swiftFile, swiftSrc, "utf8");
|
||||||
try {
|
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 });
|
const { stdout } = await execFileAsync(binFile, [], { timeout: 15_000 });
|
||||||
await cleanup(tmpDir);
|
await cleanup(tmpDir);
|
||||||
return JSON.parse(stdout);
|
return JSON.parse(stdout);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await cleanup(tmpDir);
|
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 || ""}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user