@storyteller-platform/ghost-story 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +611 -0
- package/README.md +18 -0
- package/dist/api/APIOptions.cjs +16 -0
- package/dist/api/APIOptions.d.cts +18 -0
- package/dist/api/APIOptions.d.ts +18 -0
- package/dist/api/APIOptions.js +0 -0
- package/dist/api/Recognition.cjs +263 -0
- package/dist/api/Recognition.d.cts +77 -0
- package/dist/api/Recognition.d.ts +77 -0
- package/dist/api/Recognition.js +233 -0
- package/dist/api/VoiceActivityDetection.cjs +77 -0
- package/dist/api/VoiceActivityDetection.d.cts +24 -0
- package/dist/api/VoiceActivityDetection.d.ts +24 -0
- package/dist/api/VoiceActivityDetection.js +43 -0
- package/dist/audio/AudioConverter.cjs +331 -0
- package/dist/audio/AudioConverter.d.cts +53 -0
- package/dist/audio/AudioConverter.d.ts +53 -0
- package/dist/audio/AudioConverter.js +310 -0
- package/dist/audio/AudioFormat.cjs +151 -0
- package/dist/audio/AudioFormat.d.cts +25 -0
- package/dist/audio/AudioFormat.d.ts +25 -0
- package/dist/audio/AudioFormat.js +123 -0
- package/dist/audio/AudioSource.cjs +119 -0
- package/dist/audio/AudioSource.d.cts +33 -0
- package/dist/audio/AudioSource.d.ts +33 -0
- package/dist/audio/AudioSource.js +88 -0
- package/dist/audio/index.cjs +74 -0
- package/dist/audio/index.d.cts +6 -0
- package/dist/audio/index.d.ts +6 -0
- package/dist/audio/index.js +54 -0
- package/dist/cli/bin.cjs +277 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +275 -0
- package/dist/cli/config.cjs +347 -0
- package/dist/cli/config.d.cts +33 -0
- package/dist/cli/config.d.ts +33 -0
- package/dist/cli/config.js +285 -0
- package/dist/cli/install.cjs +334 -0
- package/dist/cli/install.d.cts +62 -0
- package/dist/cli/install.d.ts +62 -0
- package/dist/cli/install.js +316 -0
- package/dist/cli/whisper-server.cjs +172 -0
- package/dist/cli/whisper-server.d.cts +24 -0
- package/dist/cli/whisper-server.d.ts +24 -0
- package/dist/cli/whisper-server.js +152 -0
- package/dist/config.cjs +60 -0
- package/dist/config.d.cts +12 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +32 -0
- package/dist/convert.cjs +88 -0
- package/dist/convert.d.cts +12 -0
- package/dist/convert.d.ts +12 -0
- package/dist/convert.js +63 -0
- package/dist/encodings/Ascii.cjs +75 -0
- package/dist/encodings/Ascii.d.cts +13 -0
- package/dist/encodings/Ascii.d.ts +13 -0
- package/dist/encodings/Ascii.js +48 -0
- package/dist/encodings/Base64.cjs +155 -0
- package/dist/encodings/Base64.d.cts +5 -0
- package/dist/encodings/Base64.d.ts +5 -0
- package/dist/encodings/Base64.js +129 -0
- package/dist/encodings/TextEncodingsCommon.cjs +16 -0
- package/dist/encodings/TextEncodingsCommon.d.cts +6 -0
- package/dist/encodings/TextEncodingsCommon.d.ts +6 -0
- package/dist/encodings/TextEncodingsCommon.js +0 -0
- package/dist/index.cjs +153 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +140 -0
- package/dist/recognition/AmazonTranscribeSTT.cjs +188 -0
- package/dist/recognition/AmazonTranscribeSTT.d.cts +21 -0
- package/dist/recognition/AmazonTranscribeSTT.d.ts +21 -0
- package/dist/recognition/AmazonTranscribeSTT.js +160 -0
- package/dist/recognition/AzureCognitiveServicesSTT.cjs +124 -0
- package/dist/recognition/AzureCognitiveServicesSTT.d.cts +21 -0
- package/dist/recognition/AzureCognitiveServicesSTT.d.ts +21 -0
- package/dist/recognition/AzureCognitiveServicesSTT.js +95 -0
- package/dist/recognition/DeepgramSTT.cjs +172 -0
- package/dist/recognition/DeepgramSTT.d.cts +23 -0
- package/dist/recognition/DeepgramSTT.d.ts +23 -0
- package/dist/recognition/DeepgramSTT.js +153 -0
- package/dist/recognition/GoogleCloudSTT.cjs +125 -0
- package/dist/recognition/GoogleCloudSTT.d.cts +35 -0
- package/dist/recognition/GoogleCloudSTT.d.ts +35 -0
- package/dist/recognition/GoogleCloudSTT.js +107 -0
- package/dist/recognition/OpenAICloudSTT.cjs +180 -0
- package/dist/recognition/OpenAICloudSTT.d.cts +29 -0
- package/dist/recognition/OpenAICloudSTT.d.ts +29 -0
- package/dist/recognition/OpenAICloudSTT.js +150 -0
- package/dist/recognition/WhisperCppSTT.cjs +296 -0
- package/dist/recognition/WhisperCppSTT.d.cts +40 -0
- package/dist/recognition/WhisperCppSTT.d.ts +40 -0
- package/dist/recognition/WhisperCppSTT.js +275 -0
- package/dist/recognition/WhisperServerSTT.cjs +119 -0
- package/dist/recognition/WhisperServerSTT.d.cts +24 -0
- package/dist/recognition/WhisperServerSTT.d.ts +24 -0
- package/dist/recognition/WhisperServerSTT.js +105 -0
- package/dist/utilities/FileSystem.cjs +54 -0
- package/dist/utilities/FileSystem.d.cts +3 -0
- package/dist/utilities/FileSystem.d.ts +3 -0
- package/dist/utilities/FileSystem.js +20 -0
- package/dist/utilities/Locale.cjs +46 -0
- package/dist/utilities/Locale.d.cts +9 -0
- package/dist/utilities/Locale.d.ts +9 -0
- package/dist/utilities/Locale.js +20 -0
- package/dist/utilities/ObjectUtilities.cjs +41 -0
- package/dist/utilities/ObjectUtilities.d.cts +3 -0
- package/dist/utilities/ObjectUtilities.d.ts +3 -0
- package/dist/utilities/ObjectUtilities.js +7 -0
- package/dist/utilities/Timeline.cjs +120 -0
- package/dist/utilities/Timeline.d.cts +23 -0
- package/dist/utilities/Timeline.d.ts +23 -0
- package/dist/utilities/Timeline.js +94 -0
- package/dist/utilities/Timing.cjs +287 -0
- package/dist/utilities/Timing.d.cts +64 -0
- package/dist/utilities/Timing.d.ts +64 -0
- package/dist/utilities/Timing.js +256 -0
- package/dist/utilities/WhisperTimeline.cjs +344 -0
- package/dist/utilities/WhisperTimeline.d.cts +86 -0
- package/dist/utilities/WhisperTimeline.d.ts +86 -0
- package/dist/utilities/WhisperTimeline.js +313 -0
- package/dist/vad/ActiveGate.cjs +357 -0
- package/dist/vad/ActiveGate.d.cts +53 -0
- package/dist/vad/ActiveGate.d.ts +53 -0
- package/dist/vad/ActiveGate.js +329 -0
- package/dist/vad/ActiveGateOg.cjs +1366 -0
- package/dist/vad/ActiveGateOg.d.cts +33 -0
- package/dist/vad/ActiveGateOg.d.ts +33 -0
- package/dist/vad/ActiveGateOg.js +1341 -0
- package/dist/vad/Silero.cjs +174 -0
- package/dist/vad/Silero.d.cts +25 -0
- package/dist/vad/Silero.d.ts +25 -0
- package/dist/vad/Silero.js +153 -0
- package/package.json +125 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { chmodSync, existsSync, statSync } from "node:fs";
|
|
3
|
+
import {
|
|
4
|
+
getInstallDir,
|
|
5
|
+
getInstalledVariant,
|
|
6
|
+
getModelPath,
|
|
7
|
+
getWhisperServerExecutablePath,
|
|
8
|
+
isVariantCompatibleWithCurrentPlatform
|
|
9
|
+
} from "./config.js";
|
|
10
|
+
import { installBinary, installModel } from "./install.js";
|
|
11
|
+
const defaultServerOptions = {
|
|
12
|
+
model: "tiny.en",
|
|
13
|
+
port: 8080,
|
|
14
|
+
host: "0.0.0.0",
|
|
15
|
+
threads: 4,
|
|
16
|
+
processors: 4,
|
|
17
|
+
convert: true,
|
|
18
|
+
autoInstall: true
|
|
19
|
+
};
|
|
20
|
+
class IncompatibleBinaryError extends Error {
|
|
21
|
+
constructor(installedVariant) {
|
|
22
|
+
super(
|
|
23
|
+
`Installed binary "${installedVariant}" is not compatible with the current platform. Reinstall with a compatible variant or use --force to attempt running anyway.`
|
|
24
|
+
);
|
|
25
|
+
this.installedVariant = installedVariant;
|
|
26
|
+
this.name = "IncompatibleBinaryError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function spawnWhisperServer(options) {
|
|
30
|
+
const installedVariant = getInstalledVariant();
|
|
31
|
+
if (installedVariant && !options.force) {
|
|
32
|
+
if (!isVariantCompatibleWithCurrentPlatform(installedVariant)) {
|
|
33
|
+
throw new IncompatibleBinaryError(installedVariant);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const installDir = options.variant ? getInstallDir(options.variant) : getInstallDir();
|
|
37
|
+
const modelPath = getModelPath(options.model);
|
|
38
|
+
console.log("Setting up whisper.cpp server...");
|
|
39
|
+
console.log(` Model: ${options.model}`);
|
|
40
|
+
console.log(` Port: ${options.port}`);
|
|
41
|
+
console.log(` Host: ${options.host}`);
|
|
42
|
+
console.log(` Threads: ${options.threads}`);
|
|
43
|
+
console.log(` Processors: ${options.processors}`);
|
|
44
|
+
if (installedVariant) {
|
|
45
|
+
console.log(` Variant: ${installedVariant}`);
|
|
46
|
+
}
|
|
47
|
+
console.log("");
|
|
48
|
+
const serverPath = getWhisperServerExecutablePath(installDir);
|
|
49
|
+
if (options.autoInstall) {
|
|
50
|
+
if (!existsSync(serverPath)) {
|
|
51
|
+
console.log("Installing whisper.cpp binary...");
|
|
52
|
+
await installBinary({
|
|
53
|
+
variant: options.variant,
|
|
54
|
+
printOutput: true,
|
|
55
|
+
force: options.force
|
|
56
|
+
});
|
|
57
|
+
console.log("");
|
|
58
|
+
}
|
|
59
|
+
if (existsSync(serverPath) && !(statSync(serverPath).mode & 73)) {
|
|
60
|
+
console.log("Making whisper.cpp binary executable...");
|
|
61
|
+
chmodSync(serverPath, 493);
|
|
62
|
+
}
|
|
63
|
+
if (!existsSync(modelPath)) {
|
|
64
|
+
console.log(`Installing model ${options.model}...`);
|
|
65
|
+
await installModel({ model: options.model, printOutput: true });
|
|
66
|
+
console.log("");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!existsSync(serverPath)) {
|
|
70
|
+
console.error(`Server executable not found at ${serverPath}`);
|
|
71
|
+
console.error("Run 'storywhisper install binary' to install whisper.cpp");
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
if (!existsSync(modelPath)) {
|
|
75
|
+
console.error(`Model not found at ${modelPath}`);
|
|
76
|
+
console.error(
|
|
77
|
+
`Run 'storywhisper install model ${options.model}' to install the model`
|
|
78
|
+
);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
console.log("Starting whisper server...");
|
|
82
|
+
console.log(` Executable: ${serverPath}`);
|
|
83
|
+
console.log(` Model: ${modelPath}`);
|
|
84
|
+
console.log("");
|
|
85
|
+
const serverArgs = [
|
|
86
|
+
"-m",
|
|
87
|
+
modelPath,
|
|
88
|
+
"--host",
|
|
89
|
+
options.host,
|
|
90
|
+
"--port",
|
|
91
|
+
String(options.port),
|
|
92
|
+
"-t",
|
|
93
|
+
String(options.threads),
|
|
94
|
+
"-p",
|
|
95
|
+
String(options.processors),
|
|
96
|
+
"--inference-path",
|
|
97
|
+
"/audio/transcriptions",
|
|
98
|
+
"--suppress-nst",
|
|
99
|
+
"--flash-attn"
|
|
100
|
+
];
|
|
101
|
+
if (options.convert) {
|
|
102
|
+
serverArgs.push("--convert");
|
|
103
|
+
}
|
|
104
|
+
if (options.vadModelPath) {
|
|
105
|
+
serverArgs.push("--vad", "--vad-model", options.vadModelPath);
|
|
106
|
+
if (options.vadThreshold !== void 0) {
|
|
107
|
+
serverArgs.push("--vad-threshold", String(options.vadThreshold));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const server = spawn(serverPath, serverArgs, {
|
|
112
|
+
stdio: "inherit",
|
|
113
|
+
cwd: installDir
|
|
114
|
+
});
|
|
115
|
+
server.on("error", (err) => {
|
|
116
|
+
console.error("Failed to start server:", err.message);
|
|
117
|
+
if (err.message.includes("ENOEXEC")) {
|
|
118
|
+
const variant = getInstalledVariant();
|
|
119
|
+
console.error(
|
|
120
|
+
`The installed binary${variant ? ` (${variant})` : ""} cannot be executed on this platform.`
|
|
121
|
+
);
|
|
122
|
+
console.error(
|
|
123
|
+
"Reinstall with a compatible variant: storywhisper install binary --force"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
process.exit(1);
|
|
127
|
+
});
|
|
128
|
+
server.on("exit", (code, signal) => {
|
|
129
|
+
if (signal) {
|
|
130
|
+
console.log(`Server terminated by signal: ${signal}`);
|
|
131
|
+
} else {
|
|
132
|
+
console.log(`Server exited with code: ${code}`);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
process.on("SIGINT", () => {
|
|
136
|
+
console.log("\nShutting down server...");
|
|
137
|
+
server.kill("SIGTERM");
|
|
138
|
+
});
|
|
139
|
+
process.on("SIGTERM", () => {
|
|
140
|
+
server.kill("SIGTERM");
|
|
141
|
+
});
|
|
142
|
+
return server;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error("Failed to start server:", error);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
IncompatibleBinaryError,
|
|
150
|
+
defaultServerOptions,
|
|
151
|
+
spawnWhisperServer
|
|
152
|
+
};
|
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var config_exports = {};
|
|
20
|
+
__export(config_exports, {
|
|
21
|
+
getConfig: () => getConfig,
|
|
22
|
+
getConversionMode: () => getConversionMode,
|
|
23
|
+
isTimingEnabled: () => isTimingEnabled,
|
|
24
|
+
setConversionMode: () => setConversionMode,
|
|
25
|
+
setTimingEnabled: () => setTimingEnabled
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(config_exports);
|
|
28
|
+
const config = {
|
|
29
|
+
conversionMode: getConversionModeFromEnv(),
|
|
30
|
+
enableTiming: true
|
|
31
|
+
// process.env["GHOST_STORY_TIMING"] ? process.env["GHOST_STORY_TIMING"] === "true" : true,
|
|
32
|
+
};
|
|
33
|
+
function getConversionModeFromEnv() {
|
|
34
|
+
const envValue = process.env["GHOST_STORY_CONVERSION_MODE"];
|
|
35
|
+
if (envValue === "streaming") return "streaming";
|
|
36
|
+
return "file-first";
|
|
37
|
+
}
|
|
38
|
+
function getConfig() {
|
|
39
|
+
return { ...config };
|
|
40
|
+
}
|
|
41
|
+
function setConversionMode(mode) {
|
|
42
|
+
config.conversionMode = mode;
|
|
43
|
+
}
|
|
44
|
+
function setTimingEnabled(enabled) {
|
|
45
|
+
config.enableTiming = enabled;
|
|
46
|
+
}
|
|
47
|
+
function getConversionMode() {
|
|
48
|
+
return config.conversionMode;
|
|
49
|
+
}
|
|
50
|
+
function isTimingEnabled() {
|
|
51
|
+
return config.enableTiming;
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
getConfig,
|
|
56
|
+
getConversionMode,
|
|
57
|
+
isTimingEnabled,
|
|
58
|
+
setConversionMode,
|
|
59
|
+
setTimingEnabled
|
|
60
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type ConversionMode = "file-first" | "streaming";
|
|
2
|
+
interface GhostStoryConfig {
|
|
3
|
+
conversionMode: ConversionMode;
|
|
4
|
+
enableTiming: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function getConfig(): GhostStoryConfig;
|
|
7
|
+
declare function setConversionMode(mode: ConversionMode): void;
|
|
8
|
+
declare function setTimingEnabled(enabled: boolean): void;
|
|
9
|
+
declare function getConversionMode(): ConversionMode;
|
|
10
|
+
declare function isTimingEnabled(): boolean;
|
|
11
|
+
|
|
12
|
+
export { type ConversionMode, getConfig, getConversionMode, isTimingEnabled, setConversionMode, setTimingEnabled };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type ConversionMode = "file-first" | "streaming";
|
|
2
|
+
interface GhostStoryConfig {
|
|
3
|
+
conversionMode: ConversionMode;
|
|
4
|
+
enableTiming: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function getConfig(): GhostStoryConfig;
|
|
7
|
+
declare function setConversionMode(mode: ConversionMode): void;
|
|
8
|
+
declare function setTimingEnabled(enabled: boolean): void;
|
|
9
|
+
declare function getConversionMode(): ConversionMode;
|
|
10
|
+
declare function isTimingEnabled(): boolean;
|
|
11
|
+
|
|
12
|
+
export { type ConversionMode, getConfig, getConversionMode, isTimingEnabled, setConversionMode, setTimingEnabled };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const config = {
|
|
2
|
+
conversionMode: getConversionModeFromEnv(),
|
|
3
|
+
enableTiming: true
|
|
4
|
+
// process.env["GHOST_STORY_TIMING"] ? process.env["GHOST_STORY_TIMING"] === "true" : true,
|
|
5
|
+
};
|
|
6
|
+
function getConversionModeFromEnv() {
|
|
7
|
+
const envValue = process.env["GHOST_STORY_CONVERSION_MODE"];
|
|
8
|
+
if (envValue === "streaming") return "streaming";
|
|
9
|
+
return "file-first";
|
|
10
|
+
}
|
|
11
|
+
function getConfig() {
|
|
12
|
+
return { ...config };
|
|
13
|
+
}
|
|
14
|
+
function setConversionMode(mode) {
|
|
15
|
+
config.conversionMode = mode;
|
|
16
|
+
}
|
|
17
|
+
function setTimingEnabled(enabled) {
|
|
18
|
+
config.enableTiming = enabled;
|
|
19
|
+
}
|
|
20
|
+
function getConversionMode() {
|
|
21
|
+
return config.conversionMode;
|
|
22
|
+
}
|
|
23
|
+
function isTimingEnabled() {
|
|
24
|
+
return config.enableTiming;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
getConfig,
|
|
28
|
+
getConversionMode,
|
|
29
|
+
isTimingEnabled,
|
|
30
|
+
setConversionMode,
|
|
31
|
+
setTimingEnabled
|
|
32
|
+
};
|
package/dist/convert.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var convert_exports = {};
|
|
20
|
+
__export(convert_exports, {
|
|
21
|
+
fileToFormat: () => fileToFormat,
|
|
22
|
+
fileToWav: () => fileToWav
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(convert_exports);
|
|
25
|
+
var import_node_os = require("node:os");
|
|
26
|
+
var import_node_path = require("node:path");
|
|
27
|
+
var import_ffmpeg_stream = require("ffmpeg-stream");
|
|
28
|
+
var import_AudioFormat = require("./audio/AudioFormat.cjs");
|
|
29
|
+
async function fileToWav(file, options = {}) {
|
|
30
|
+
const converter = new import_ffmpeg_stream.Converter();
|
|
31
|
+
const outputPath = (0, import_node_path.join)((0, import_node_os.tmpdir)(), `vad-${Date.now()}.wav`);
|
|
32
|
+
converter.createInputFromFile(file);
|
|
33
|
+
converter.createOutputToFile(outputPath, {
|
|
34
|
+
f: "wav",
|
|
35
|
+
ar: String(options.sampleRate ?? 16e3),
|
|
36
|
+
ac: String(options.channels ?? 1)
|
|
37
|
+
});
|
|
38
|
+
await converter.run();
|
|
39
|
+
return outputPath;
|
|
40
|
+
}
|
|
41
|
+
async function fileToFormat(file, targetFormat, options = {}) {
|
|
42
|
+
const converter = new import_ffmpeg_stream.Converter();
|
|
43
|
+
const ext = (0, import_AudioFormat.formatToExtension)(targetFormat);
|
|
44
|
+
const outputPath = (0, import_node_path.join)((0, import_node_os.tmpdir)(), `convert-${Date.now()}${ext}`);
|
|
45
|
+
converter.createInputFromFile(file);
|
|
46
|
+
converter.createOutputToFile(outputPath, getFormatOptions(targetFormat, options));
|
|
47
|
+
await converter.run();
|
|
48
|
+
return outputPath;
|
|
49
|
+
}
|
|
50
|
+
function getFormatOptions(format, options) {
|
|
51
|
+
const opts = {};
|
|
52
|
+
switch (format) {
|
|
53
|
+
case "wav":
|
|
54
|
+
opts["f"] = "wav";
|
|
55
|
+
opts["acodec"] = "pcm_s16le";
|
|
56
|
+
break;
|
|
57
|
+
case "flac":
|
|
58
|
+
opts["f"] = "flac";
|
|
59
|
+
opts["acodec"] = "flac";
|
|
60
|
+
break;
|
|
61
|
+
case "opus":
|
|
62
|
+
opts["f"] = "ogg";
|
|
63
|
+
opts["acodec"] = "libopus";
|
|
64
|
+
break;
|
|
65
|
+
case "ogg":
|
|
66
|
+
opts["f"] = "ogg";
|
|
67
|
+
opts["acodec"] = "libvorbis";
|
|
68
|
+
break;
|
|
69
|
+
case "mp3":
|
|
70
|
+
opts["f"] = "mp3";
|
|
71
|
+
opts["acodec"] = "libmp3lame";
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
opts["f"] = format;
|
|
75
|
+
}
|
|
76
|
+
if (options.sampleRate) {
|
|
77
|
+
opts["ar"] = String(options.sampleRate);
|
|
78
|
+
}
|
|
79
|
+
if (options.channels) {
|
|
80
|
+
opts["ac"] = String(options.channels);
|
|
81
|
+
}
|
|
82
|
+
return opts;
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
fileToFormat,
|
|
87
|
+
fileToWav
|
|
88
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AudioFormat } from './audio/AudioFormat.cjs';
|
|
2
|
+
|
|
3
|
+
declare function fileToWav(file: string, options?: {
|
|
4
|
+
sampleRate?: number;
|
|
5
|
+
channels?: number;
|
|
6
|
+
}): Promise<string>;
|
|
7
|
+
declare function fileToFormat(file: string, targetFormat: AudioFormat, options?: {
|
|
8
|
+
sampleRate?: number;
|
|
9
|
+
channels?: number;
|
|
10
|
+
}): Promise<string>;
|
|
11
|
+
|
|
12
|
+
export { fileToFormat, fileToWav };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AudioFormat } from './audio/AudioFormat.js';
|
|
2
|
+
|
|
3
|
+
declare function fileToWav(file: string, options?: {
|
|
4
|
+
sampleRate?: number;
|
|
5
|
+
channels?: number;
|
|
6
|
+
}): Promise<string>;
|
|
7
|
+
declare function fileToFormat(file: string, targetFormat: AudioFormat, options?: {
|
|
8
|
+
sampleRate?: number;
|
|
9
|
+
channels?: number;
|
|
10
|
+
}): Promise<string>;
|
|
11
|
+
|
|
12
|
+
export { fileToFormat, fileToWav };
|
package/dist/convert.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { tmpdir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { Converter } from "ffmpeg-stream";
|
|
4
|
+
import { formatToExtension } from "./audio/AudioFormat.js";
|
|
5
|
+
async function fileToWav(file, options = {}) {
|
|
6
|
+
const converter = new Converter();
|
|
7
|
+
const outputPath = join(tmpdir(), `vad-${Date.now()}.wav`);
|
|
8
|
+
converter.createInputFromFile(file);
|
|
9
|
+
converter.createOutputToFile(outputPath, {
|
|
10
|
+
f: "wav",
|
|
11
|
+
ar: String(options.sampleRate ?? 16e3),
|
|
12
|
+
ac: String(options.channels ?? 1)
|
|
13
|
+
});
|
|
14
|
+
await converter.run();
|
|
15
|
+
return outputPath;
|
|
16
|
+
}
|
|
17
|
+
async function fileToFormat(file, targetFormat, options = {}) {
|
|
18
|
+
const converter = new Converter();
|
|
19
|
+
const ext = formatToExtension(targetFormat);
|
|
20
|
+
const outputPath = join(tmpdir(), `convert-${Date.now()}${ext}`);
|
|
21
|
+
converter.createInputFromFile(file);
|
|
22
|
+
converter.createOutputToFile(outputPath, getFormatOptions(targetFormat, options));
|
|
23
|
+
await converter.run();
|
|
24
|
+
return outputPath;
|
|
25
|
+
}
|
|
26
|
+
function getFormatOptions(format, options) {
|
|
27
|
+
const opts = {};
|
|
28
|
+
switch (format) {
|
|
29
|
+
case "wav":
|
|
30
|
+
opts["f"] = "wav";
|
|
31
|
+
opts["acodec"] = "pcm_s16le";
|
|
32
|
+
break;
|
|
33
|
+
case "flac":
|
|
34
|
+
opts["f"] = "flac";
|
|
35
|
+
opts["acodec"] = "flac";
|
|
36
|
+
break;
|
|
37
|
+
case "opus":
|
|
38
|
+
opts["f"] = "ogg";
|
|
39
|
+
opts["acodec"] = "libopus";
|
|
40
|
+
break;
|
|
41
|
+
case "ogg":
|
|
42
|
+
opts["f"] = "ogg";
|
|
43
|
+
opts["acodec"] = "libvorbis";
|
|
44
|
+
break;
|
|
45
|
+
case "mp3":
|
|
46
|
+
opts["f"] = "mp3";
|
|
47
|
+
opts["acodec"] = "libmp3lame";
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
opts["f"] = format;
|
|
51
|
+
}
|
|
52
|
+
if (options.sampleRate) {
|
|
53
|
+
opts["ar"] = String(options.sampleRate);
|
|
54
|
+
}
|
|
55
|
+
if (options.channels) {
|
|
56
|
+
opts["ac"] = String(options.channels);
|
|
57
|
+
}
|
|
58
|
+
return opts;
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
fileToFormat,
|
|
62
|
+
fileToWav
|
|
63
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Ascii_exports = {};
|
|
20
|
+
__export(Ascii_exports, {
|
|
21
|
+
ChunkedAsciiDecoder: () => ChunkedAsciiDecoder,
|
|
22
|
+
decodeAscii: () => decodeAscii,
|
|
23
|
+
encodeAscii: () => encodeAscii,
|
|
24
|
+
encodeAsciiInto: () => encodeAsciiInto
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(Ascii_exports);
|
|
27
|
+
function encodeAscii(asciiString) {
|
|
28
|
+
const charCount = asciiString.length;
|
|
29
|
+
const resultArray = new Uint8Array(charCount);
|
|
30
|
+
const { written } = encodeAsciiInto(asciiString, resultArray);
|
|
31
|
+
return resultArray.subarray(0, written);
|
|
32
|
+
}
|
|
33
|
+
function encodeAsciiInto(asciiString, resultBuffer) {
|
|
34
|
+
const len = asciiString.length;
|
|
35
|
+
if (resultBuffer.length < len) {
|
|
36
|
+
throw new Error(`Result Uint8Array is not large enough to hold the string`);
|
|
37
|
+
}
|
|
38
|
+
for (let readOffset = 0; readOffset < len; readOffset++) {
|
|
39
|
+
const charCode = asciiString.charCodeAt(readOffset);
|
|
40
|
+
if (charCode >= 128) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Character '${asciiString[readOffset]}' (code: ${charCode}) can't be encoded as a standard ASCII character`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
resultBuffer[readOffset] = charCode;
|
|
46
|
+
}
|
|
47
|
+
return { read: len, written: len };
|
|
48
|
+
}
|
|
49
|
+
function decodeAscii(encodedString) {
|
|
50
|
+
const maxChunkLength = 2 ** 24;
|
|
51
|
+
const decoder = new ChunkedAsciiDecoder();
|
|
52
|
+
for (let offset = 0; offset < encodedString.length; offset += maxChunkLength) {
|
|
53
|
+
const chunk = encodedString.subarray(offset, offset + maxChunkLength);
|
|
54
|
+
decoder.writeChunk(chunk);
|
|
55
|
+
}
|
|
56
|
+
return decoder.toString();
|
|
57
|
+
}
|
|
58
|
+
class ChunkedAsciiDecoder {
|
|
59
|
+
str = "";
|
|
60
|
+
textDecoder = new TextDecoder("windows-1252");
|
|
61
|
+
writeChunk(chunk) {
|
|
62
|
+
const decodedChunk = this.textDecoder.decode(chunk, { stream: true });
|
|
63
|
+
this.str += decodedChunk;
|
|
64
|
+
}
|
|
65
|
+
toString() {
|
|
66
|
+
return this.str;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
ChunkedAsciiDecoder,
|
|
72
|
+
decodeAscii,
|
|
73
|
+
encodeAscii,
|
|
74
|
+
encodeAsciiInto
|
|
75
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EncodeIntoResult } from './TextEncodingsCommon.cjs';
|
|
2
|
+
|
|
3
|
+
declare function encodeAscii(asciiString: string): Uint8Array<ArrayBuffer>;
|
|
4
|
+
declare function encodeAsciiInto(asciiString: string, resultBuffer: Uint8Array): EncodeIntoResult;
|
|
5
|
+
declare function decodeAscii(encodedString: Uint8Array): string;
|
|
6
|
+
declare class ChunkedAsciiDecoder {
|
|
7
|
+
private str;
|
|
8
|
+
private readonly textDecoder;
|
|
9
|
+
writeChunk(chunk: Uint8Array): void;
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { ChunkedAsciiDecoder, decodeAscii, encodeAscii, encodeAsciiInto };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EncodeIntoResult } from './TextEncodingsCommon.js';
|
|
2
|
+
|
|
3
|
+
declare function encodeAscii(asciiString: string): Uint8Array<ArrayBuffer>;
|
|
4
|
+
declare function encodeAsciiInto(asciiString: string, resultBuffer: Uint8Array): EncodeIntoResult;
|
|
5
|
+
declare function decodeAscii(encodedString: Uint8Array): string;
|
|
6
|
+
declare class ChunkedAsciiDecoder {
|
|
7
|
+
private str;
|
|
8
|
+
private readonly textDecoder;
|
|
9
|
+
writeChunk(chunk: Uint8Array): void;
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { ChunkedAsciiDecoder, decodeAscii, encodeAscii, encodeAsciiInto };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
function encodeAscii(asciiString) {
|
|
2
|
+
const charCount = asciiString.length;
|
|
3
|
+
const resultArray = new Uint8Array(charCount);
|
|
4
|
+
const { written } = encodeAsciiInto(asciiString, resultArray);
|
|
5
|
+
return resultArray.subarray(0, written);
|
|
6
|
+
}
|
|
7
|
+
function encodeAsciiInto(asciiString, resultBuffer) {
|
|
8
|
+
const len = asciiString.length;
|
|
9
|
+
if (resultBuffer.length < len) {
|
|
10
|
+
throw new Error(`Result Uint8Array is not large enough to hold the string`);
|
|
11
|
+
}
|
|
12
|
+
for (let readOffset = 0; readOffset < len; readOffset++) {
|
|
13
|
+
const charCode = asciiString.charCodeAt(readOffset);
|
|
14
|
+
if (charCode >= 128) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Character '${asciiString[readOffset]}' (code: ${charCode}) can't be encoded as a standard ASCII character`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
resultBuffer[readOffset] = charCode;
|
|
20
|
+
}
|
|
21
|
+
return { read: len, written: len };
|
|
22
|
+
}
|
|
23
|
+
function decodeAscii(encodedString) {
|
|
24
|
+
const maxChunkLength = 2 ** 24;
|
|
25
|
+
const decoder = new ChunkedAsciiDecoder();
|
|
26
|
+
for (let offset = 0; offset < encodedString.length; offset += maxChunkLength) {
|
|
27
|
+
const chunk = encodedString.subarray(offset, offset + maxChunkLength);
|
|
28
|
+
decoder.writeChunk(chunk);
|
|
29
|
+
}
|
|
30
|
+
return decoder.toString();
|
|
31
|
+
}
|
|
32
|
+
class ChunkedAsciiDecoder {
|
|
33
|
+
str = "";
|
|
34
|
+
textDecoder = new TextDecoder("windows-1252");
|
|
35
|
+
writeChunk(chunk) {
|
|
36
|
+
const decodedChunk = this.textDecoder.decode(chunk, { stream: true });
|
|
37
|
+
this.str += decodedChunk;
|
|
38
|
+
}
|
|
39
|
+
toString() {
|
|
40
|
+
return this.str;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
ChunkedAsciiDecoder,
|
|
45
|
+
decodeAscii,
|
|
46
|
+
encodeAscii,
|
|
47
|
+
encodeAsciiInto
|
|
48
|
+
};
|