增加语音对话功能
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { isWindows } from "./os";
|
||||
|
||||
/**
|
||||
* Normalize user-provided executable path for the current OS.
|
||||
* - Expands ~ on macOS/Linux via PathUtils (when available)
|
||||
* - Ensures .exe suffix on Windows when missing
|
||||
*/
|
||||
export function normalizeExecutablePath(input: string): string {
|
||||
const trimmed = (input || "").trim();
|
||||
if (!trimmed) return "";
|
||||
|
||||
const path = trimmed;
|
||||
|
||||
if (isWindows() && !/\.(exe|cmd|bat)$/i.test(path)) {
|
||||
return `${path}.exe`;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/** Join path segments using Zotero PathUtils (cross-platform). */
|
||||
export function joinPath(...parts: string[]): string {
|
||||
return PathUtils.join(...parts.filter(Boolean));
|
||||
}
|
||||
|
||||
/** Convert local file path to file:// URL for <audio src>. */
|
||||
export function pathToFileUrl(filePath: string): string {
|
||||
const normalized = filePath.replace(/\\/g, "/");
|
||||
if (normalized.startsWith("file://")) return normalized;
|
||||
if (/^[A-Za-z]:\//.test(normalized)) {
|
||||
return `file:///${encodeURI(normalized)}`;
|
||||
}
|
||||
return `file://${encodeURI(normalized)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user