@inworld/cli 0.3.1 → 1.0.0-rc.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/dist/index.js +820 -296
- package/dist/package.json +11 -7
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts +2 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js.map +1 -1
- package/dist/proto/generated/portal/fetch.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/fetch.pb.js.map +1 -1
- package/dist/src/auth/manager.d.ts.map +1 -1
- package/dist/src/auth/manager.js +1 -3
- package/dist/src/auth/manager.js.map +1 -1
- package/dist/src/auth/utils.d.ts +1 -1
- package/dist/src/auth/utils.d.ts.map +1 -1
- package/dist/src/auth/utils.js +1 -1
- package/dist/src/auth/utils.js.map +1 -1
- package/dist/src/commands/auth/disable_telemetry_command.js +21 -0
- package/dist/src/commands/auth/disable_telemetry_command.js.map +1 -0
- package/dist/src/commands/auth/enable_telemetry_command.js +22 -0
- package/dist/src/commands/auth/enable_telemetry_command.js.map +1 -0
- package/dist/src/commands/auth/login_command.d.ts.map +1 -1
- package/dist/src/commands/auth/login_command.js +2 -2
- package/dist/src/commands/auth/login_command.js.map +1 -1
- package/dist/src/commands/auth/status_command.d.ts.map +1 -1
- package/dist/src/commands/auth/status_command.js.map +1 -1
- package/dist/src/commands/auth_command.js +4 -0
- package/dist/src/commands/auth_command.js.map +1 -1
- package/dist/src/commands/graph/graph_deploy_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_deploy_command.js +14 -1
- package/dist/src/commands/graph/graph_deploy_command.js.map +1 -1
- package/dist/src/commands/graph/graph_init_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_init_command.js +231 -272
- package/dist/src/commands/graph/graph_init_command.js.map +1 -1
- package/dist/src/commands/graph/graph_run_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_run_command.js +1 -1
- package/dist/src/commands/graph/graph_run_command.js.map +1 -1
- package/dist/src/commands/graph/graph_visualize_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_visualize_command.js +3 -3
- package/dist/src/commands/graph/graph_visualize_command.js.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_list_command.js +1 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.js.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.js +2 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.js.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_register_command.js +1 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.js.map +1 -1
- package/dist/src/commands/tts/tts_clone_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_clone_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_clone_command.js +80 -0
- package/dist/src/commands/tts/tts_clone_command.js.map +1 -0
- package/dist/src/commands/tts/tts_design_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_design_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_design_command.js +216 -0
- package/dist/src/commands/tts/tts_design_command.js.map +1 -0
- package/dist/src/commands/tts/tts_list_voices_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_list_voices_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_list_voices_command.js +108 -0
- package/dist/src/commands/tts/tts_list_voices_command.js.map +1 -0
- package/dist/src/commands/tts/tts_synthesize_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_synthesize_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_synthesize_command.js +351 -0
- package/dist/src/commands/tts/tts_synthesize_command.js.map +1 -0
- package/dist/src/commands/tts/tts_utils.d.ts +14 -0
- package/dist/src/commands/tts/tts_utils.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_utils.js +84 -0
- package/dist/src/commands/tts/tts_utils.js.map +1 -0
- package/dist/src/commands/tts_commands.d.ts +0 -11
- package/dist/src/commands/tts_commands.d.ts.map +1 -1
- package/dist/src/commands/tts_commands.js +6 -556
- package/dist/src/commands/tts_commands.js.map +1 -1
- package/dist/src/commands/workspace_command.d.ts +10 -0
- package/dist/src/commands/workspace_command.d.ts.map +1 -1
- package/dist/src/commands/workspace_command.js +39 -0
- package/dist/src/commands/workspace_command.js.map +1 -1
- package/dist/src/constants.d.ts +2 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +19 -1
- package/dist/src/constants.js.map +1 -1
- package/dist/src/grpc/core/InworldError.d.ts.map +1 -1
- package/dist/src/grpc/core/InworldError.js.map +1 -1
- package/dist/src/index.js +139 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/services/analytics.d.ts +2 -2
- package/dist/src/services/analytics.d.ts.map +1 -1
- package/dist/src/services/analytics.js +139 -0
- package/dist/src/services/analytics.js.map +1 -0
- package/dist/src/services/deploy_service.js +1 -1
- package/dist/src/services/deploy_service.js.map +1 -1
- package/dist/src/services/graph_loader.d.ts.map +1 -1
- package/dist/src/services/graph_loader.js +1 -1
- package/dist/src/services/graph_loader.js.map +1 -1
- package/dist/src/services/graph_variant_service.d.ts.map +1 -1
- package/dist/src/services/graph_variant_service.js +1 -1
- package/dist/src/services/graph_variant_service.js.map +1 -1
- package/dist/src/services/template_service.d.ts +79 -0
- package/dist/src/services/template_service.d.ts.map +1 -0
- package/dist/src/services/template_service.js +299 -0
- package/dist/src/services/template_service.js.map +1 -0
- package/dist/src/services/tts_service.d.ts +138 -71
- package/dist/src/services/tts_service.d.ts.map +1 -1
- package/dist/src/services/tts_service.js +87 -66
- package/dist/src/services/tts_service.js.map +1 -1
- package/dist/src/services/update_checker.js +134 -0
- package/dist/src/services/update_checker.js.map +1 -0
- package/dist/src/services/workspace_service.d.ts +6 -0
- package/dist/src/services/workspace_service.d.ts.map +1 -1
- package/dist/src/services/workspace_service.js +115 -13
- package/dist/src/services/workspace_service.js.map +1 -1
- package/dist/src/utils/audio_player.d.ts +10 -0
- package/dist/src/utils/audio_player.d.ts.map +1 -0
- package/dist/src/utils/audio_player.js +34 -0
- package/dist/src/utils/audio_player.js.map +1 -0
- package/dist/src/utils/long_running_operations.d.ts.map +1 -1
- package/dist/src/utils/long_running_operations.js +1 -1
- package/dist/src/utils/long_running_operations.js.map +1 -1
- package/dist/src/utils/resource_name_helper.d.ts +5 -0
- package/dist/src/utils/resource_name_helper.d.ts.map +1 -1
- package/dist/src/utils/resource_name_helper.js +9 -0
- package/dist/src/utils/resource_name_helper.js.map +1 -1
- package/dist/src/utils/selector.d.ts.map +1 -1
- package/dist/src/utils/selector.js +1 -2
- package/dist/src/utils/selector.js.map +1 -1
- package/dist/src/utils/ui.d.ts.map +1 -1
- package/dist/src/utils/ui.js +8 -2
- package/dist/src/utils/ui.js.map +1 -1
- package/package.json +8 -2
- package/dist/index.js.map +0 -7
- package/dist/src/templates/llm_tts/README.md +0 -161
- package/dist/src/templates/llm_tts/graph.d.ts +0 -2
- package/dist/src/templates/llm_tts/graph.d.ts.map +0 -1
- package/dist/src/templates/llm_tts/graph.ts +0 -30
- package/dist/src/templates/llm_tts/metadata.json +0 -41
- package/dist/templates/llm_tts/README.md +0 -155
- package/dist/templates/llm_tts/graph.ts +0 -29
- package/dist/templates/llm_tts/metadata.json +0 -41
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
import
|
|
6
|
-
import { Command as
|
|
5
|
+
import chalk9 from "chalk";
|
|
6
|
+
import { Command as Command26 } from "commander";
|
|
7
7
|
|
|
8
8
|
// src/commands/auth/login_command.ts
|
|
9
9
|
import { exec } from "child_process";
|
|
@@ -17,20 +17,25 @@ import * as http from "http";
|
|
|
17
17
|
// package.json
|
|
18
18
|
var package_default = {
|
|
19
19
|
name: "@inworld/cli",
|
|
20
|
-
version: "0.
|
|
20
|
+
version: "1.0.0-rc.1",
|
|
21
21
|
type: "module",
|
|
22
22
|
main: "dist/index.js",
|
|
23
23
|
bin: {
|
|
24
24
|
inworld: "dist/index.js"
|
|
25
25
|
},
|
|
26
26
|
scripts: {
|
|
27
|
-
|
|
27
|
+
postversion: "npm install && git add ../../package-lock.json",
|
|
28
|
+
"copy:release-it-config": "node ../../scripts/copy-release-it-config.js",
|
|
29
|
+
build: "node esbuild.config.js && npm run copy:release-it-config",
|
|
28
30
|
"build:tsc": "tsc --project tsconfig.json",
|
|
29
31
|
"build:types": "tsc --emitDeclarationOnly",
|
|
30
32
|
"build:all": "npm run build && npm run build:types",
|
|
31
33
|
start: "node dist/index.js",
|
|
32
34
|
dev: "tsx src/index.ts"
|
|
33
35
|
},
|
|
36
|
+
engines: {
|
|
37
|
+
node: ">=20.0.0"
|
|
38
|
+
},
|
|
34
39
|
files: [
|
|
35
40
|
"dist/**/*"
|
|
36
41
|
],
|
|
@@ -57,6 +62,7 @@ var package_default = {
|
|
|
57
62
|
"jwt-decode": "^4.0.0",
|
|
58
63
|
mixpanel: "^0.18.1",
|
|
59
64
|
ora: "^8.2.0",
|
|
65
|
+
"play-sound": "^1.1.6",
|
|
60
66
|
semver: "^7.6.3",
|
|
61
67
|
tsx: "^4.20.5",
|
|
62
68
|
typescript: "^5.8.3"
|
|
@@ -108,7 +114,7 @@ var resolveTemplatesMetadataUrl = () => {
|
|
|
108
114
|
}
|
|
109
115
|
};
|
|
110
116
|
var TEMPLATES_METADATA_URL = resolveTemplatesMetadataUrl();
|
|
111
|
-
var RUNTIME_VERSION = "0.
|
|
117
|
+
var RUNTIME_VERSION = "0.9.0-rc.17";
|
|
112
118
|
var CLI_VERSION = package_default.version;
|
|
113
119
|
|
|
114
120
|
// src/utils/ui.ts
|
|
@@ -196,7 +202,7 @@ async function createCallbackServer(options = {}) {
|
|
|
196
202
|
allowedOrigins = ["http://localhost:3001", "https://cli.inworld.ai"],
|
|
197
203
|
firebaseApiKey = FIREBASE_API_KEY
|
|
198
204
|
} = options;
|
|
199
|
-
return new Promise((
|
|
205
|
+
return new Promise((resolve3, reject) => {
|
|
200
206
|
const httpServer = http.createServer(
|
|
201
207
|
{
|
|
202
208
|
keepAlive: false
|
|
@@ -249,7 +255,7 @@ async function createCallbackServer(options = {}) {
|
|
|
249
255
|
if (tokenResponse?.id_token) {
|
|
250
256
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
251
257
|
res.end(JSON.stringify({ success: true }));
|
|
252
|
-
|
|
258
|
+
resolve3({
|
|
253
259
|
server: httpServer,
|
|
254
260
|
token: tokenResponse.id_token,
|
|
255
261
|
refreshToken,
|
|
@@ -298,12 +304,12 @@ async function createCallbackServer(options = {}) {
|
|
|
298
304
|
});
|
|
299
305
|
}
|
|
300
306
|
function stopCallbackServer(server) {
|
|
301
|
-
return new Promise((
|
|
307
|
+
return new Promise((resolve3, reject) => {
|
|
302
308
|
server.close((err) => {
|
|
303
309
|
if (err) {
|
|
304
310
|
reject(err);
|
|
305
311
|
} else {
|
|
306
|
-
|
|
312
|
+
resolve3();
|
|
307
313
|
}
|
|
308
314
|
});
|
|
309
315
|
});
|
|
@@ -933,7 +939,7 @@ var checkLRO = async ({
|
|
|
933
939
|
pollOptions?.errorCallback?.(operationName, error);
|
|
934
940
|
throw error;
|
|
935
941
|
}
|
|
936
|
-
await new Promise((
|
|
942
|
+
await new Promise((resolve3) => setTimeout(resolve3, checkTimeout));
|
|
937
943
|
}
|
|
938
944
|
throw new Error(
|
|
939
945
|
`Operation timeout. Max number of checks reached ${checkLimit}`
|
|
@@ -1042,9 +1048,9 @@ async function retryableAuthenticatedInworldRequest(pb, req, options = {
|
|
|
1042
1048
|
minTimeout * Math.pow(backoffFactor, currentAttempt),
|
|
1043
1049
|
maxTimeout
|
|
1044
1050
|
);
|
|
1045
|
-
return new Promise((
|
|
1051
|
+
return new Promise((resolve3) => {
|
|
1046
1052
|
setTimeout(() => {
|
|
1047
|
-
|
|
1053
|
+
resolve3(retryRequest(currentAttempt + 1));
|
|
1048
1054
|
}, timeout);
|
|
1049
1055
|
});
|
|
1050
1056
|
} else {
|
|
@@ -1217,23 +1223,23 @@ async function confirm(options) {
|
|
|
1217
1223
|
input: process.stdin,
|
|
1218
1224
|
output: process.stdout
|
|
1219
1225
|
});
|
|
1220
|
-
return new Promise((
|
|
1226
|
+
return new Promise((resolve3) => {
|
|
1221
1227
|
rl.question(message, (answer) => {
|
|
1222
1228
|
rl.close();
|
|
1223
1229
|
const trimmedAnswer = answer.trim().toLowerCase();
|
|
1224
1230
|
if (trimmedAnswer === "y" || trimmedAnswer === "yes") {
|
|
1225
|
-
|
|
1231
|
+
resolve3(true);
|
|
1226
1232
|
return;
|
|
1227
1233
|
}
|
|
1228
1234
|
if (trimmedAnswer === "n" || trimmedAnswer === "no") {
|
|
1229
|
-
|
|
1235
|
+
resolve3(false);
|
|
1230
1236
|
return;
|
|
1231
1237
|
}
|
|
1232
1238
|
if (trimmedAnswer === "") {
|
|
1233
|
-
|
|
1239
|
+
resolve3(defaultValue);
|
|
1234
1240
|
return;
|
|
1235
1241
|
}
|
|
1236
|
-
|
|
1242
|
+
resolve3(false);
|
|
1237
1243
|
});
|
|
1238
1244
|
});
|
|
1239
1245
|
}
|
|
@@ -1255,6 +1261,9 @@ var getGraphVariantResourceName = (workspaceId, graphId, variantId) => {
|
|
|
1255
1261
|
var getWorkspaceResourceName = (workspaceId) => {
|
|
1256
1262
|
return `workspaces/${workspaceId}`;
|
|
1257
1263
|
};
|
|
1264
|
+
var ensureWorkspaceResourceName = (workspace) => {
|
|
1265
|
+
return workspace.startsWith("workspaces/") ? workspace : `workspaces/${workspace}`;
|
|
1266
|
+
};
|
|
1258
1267
|
|
|
1259
1268
|
// src/utils/selector.ts
|
|
1260
1269
|
import * as readline2 from "readline";
|
|
@@ -1280,16 +1289,13 @@ async function selectItem(options) {
|
|
|
1280
1289
|
printHeader(title);
|
|
1281
1290
|
items.forEach((item, idx) => {
|
|
1282
1291
|
const displayName = getDisplayName(item);
|
|
1283
|
-
|
|
1284
|
-
printListItem(
|
|
1285
|
-
`${idx + 1}. ${bright(displayName)} (ID: ${cyan(identifier)})`
|
|
1286
|
-
);
|
|
1292
|
+
printListItem(`${idx + 1}. ${bright(displayName)}`);
|
|
1287
1293
|
});
|
|
1288
1294
|
const rl = readline2.createInterface({
|
|
1289
1295
|
input: process.stdin,
|
|
1290
1296
|
output: process.stdout
|
|
1291
1297
|
});
|
|
1292
|
-
const question = (query) => new Promise((
|
|
1298
|
+
const question = (query) => new Promise((resolve3) => rl.question(query, resolve3));
|
|
1293
1299
|
let selectedItem = null;
|
|
1294
1300
|
try {
|
|
1295
1301
|
while (!selectedItem) {
|
|
@@ -1324,6 +1330,35 @@ async function selectItemOrExit(options) {
|
|
|
1324
1330
|
}
|
|
1325
1331
|
|
|
1326
1332
|
// src/services/workspace_service.ts
|
|
1333
|
+
function formatApiKeyScopes(scopes) {
|
|
1334
|
+
if (!scopes?.length) return "";
|
|
1335
|
+
const scopeMap = {
|
|
1336
|
+
"api.dsgnt.voices": "voices",
|
|
1337
|
+
"api.dsgnt.router": "router"
|
|
1338
|
+
};
|
|
1339
|
+
const accessMap = {
|
|
1340
|
+
r: "read",
|
|
1341
|
+
w: "write",
|
|
1342
|
+
rw: "read/write"
|
|
1343
|
+
};
|
|
1344
|
+
const labels = [];
|
|
1345
|
+
let hasVoices = false;
|
|
1346
|
+
let hasRouter = false;
|
|
1347
|
+
for (const scope of scopes) {
|
|
1348
|
+
const match = scope.match(/^([^:]+)::(\w+)/);
|
|
1349
|
+
if (!match) continue;
|
|
1350
|
+
const [, prefix, access] = match;
|
|
1351
|
+
const name = scopeMap[prefix];
|
|
1352
|
+
if (!name) continue;
|
|
1353
|
+
if (name === "voices") hasVoices = true;
|
|
1354
|
+
if (name === "router") hasRouter = true;
|
|
1355
|
+
const accessLabel = accessMap[access] || access;
|
|
1356
|
+
labels.push(`${name}:${accessLabel}`);
|
|
1357
|
+
}
|
|
1358
|
+
if (!hasVoices) labels.push("voices:read");
|
|
1359
|
+
if (!hasRouter) labels.push("router:read");
|
|
1360
|
+
return `[${labels.join(", ")}]`;
|
|
1361
|
+
}
|
|
1327
1362
|
var WorkspaceService = class {
|
|
1328
1363
|
/**
|
|
1329
1364
|
* Prompts user to select a workspace from available workspaces
|
|
@@ -1360,16 +1395,18 @@ var WorkspaceService = class {
|
|
|
1360
1395
|
return selectItemOrExit({
|
|
1361
1396
|
items: apiKeys,
|
|
1362
1397
|
getDisplayName: (apiKey) => {
|
|
1363
|
-
const
|
|
1398
|
+
const displayName = apiKey.displayName;
|
|
1399
|
+
const label = displayName || trimBase64Key(apiKey.key || "unknown");
|
|
1364
1400
|
const createdAt = apiKey.createTime ? new Date(apiKey.createTime).toLocaleDateString() : "unknown date";
|
|
1365
|
-
|
|
1401
|
+
const permissions = formatApiKeyScopes(apiKey.scopes);
|
|
1402
|
+
return `${label} (created: ${createdAt})${permissions ? ` ${permissions}` : ""}`;
|
|
1366
1403
|
},
|
|
1367
1404
|
getIdentifier: (apiKey) => apiKey.name?.split("/").pop() || "unknown",
|
|
1368
|
-
prompt: "Enter the number
|
|
1405
|
+
prompt: "Enter the number of the API key to use:",
|
|
1369
1406
|
title: "Available API keys:",
|
|
1370
1407
|
forceFirst,
|
|
1371
1408
|
noItemsMessage: "No API keys found.",
|
|
1372
|
-
invalidSelectionMessage: "Invalid selection. Please enter a valid number
|
|
1409
|
+
invalidSelectionMessage: "Invalid selection. Please enter a valid number."
|
|
1373
1410
|
});
|
|
1374
1411
|
}
|
|
1375
1412
|
static returnBase64 = (key, secret) => {
|
|
@@ -1447,8 +1484,9 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1447
1484
|
);
|
|
1448
1485
|
return;
|
|
1449
1486
|
}
|
|
1487
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1450
1488
|
const response = await authenticatedInworldRequest(ApiKeys.ListApiKeys, {
|
|
1451
|
-
parent
|
|
1489
|
+
parent,
|
|
1452
1490
|
pageSize: WORKSPACES_LIST_SIZE
|
|
1453
1491
|
});
|
|
1454
1492
|
const apiKeys = response?.apiKeys || [];
|
|
@@ -1459,11 +1497,13 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1459
1497
|
console.log();
|
|
1460
1498
|
printHeader(`API keys in workspace ${credentials.workspace}:`);
|
|
1461
1499
|
apiKeys.forEach((apiKey, idx) => {
|
|
1462
|
-
const
|
|
1500
|
+
const displayName = apiKey.displayName;
|
|
1501
|
+
const label = displayName || trimBase64Key(apiKey.key || "unknown");
|
|
1463
1502
|
const createdAt = apiKey.createTime ? new Date(apiKey.createTime).toLocaleDateString() : "unknown date";
|
|
1464
1503
|
const state = apiKey.state || "unknown";
|
|
1504
|
+
const permissions = formatApiKeyScopes(apiKey.scopes);
|
|
1465
1505
|
printListItem(
|
|
1466
|
-
`${idx + 1}. ${
|
|
1506
|
+
`${idx + 1}. ${label} (created: ${createdAt}, state: ${state})${permissions ? ` ${permissions}` : ""}`
|
|
1467
1507
|
);
|
|
1468
1508
|
});
|
|
1469
1509
|
}
|
|
@@ -1478,8 +1518,9 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1478
1518
|
);
|
|
1479
1519
|
return;
|
|
1480
1520
|
}
|
|
1521
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1481
1522
|
const response = await authenticatedInworldRequest(ApiKeys.ListApiKeys, {
|
|
1482
|
-
parent
|
|
1523
|
+
parent,
|
|
1483
1524
|
pageSize: WORKSPACES_LIST_SIZE
|
|
1484
1525
|
});
|
|
1485
1526
|
const apiKeys = response?.apiKeys || [];
|
|
@@ -1530,10 +1571,11 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1530
1571
|
return;
|
|
1531
1572
|
}
|
|
1532
1573
|
print("Generating new API key...");
|
|
1574
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1533
1575
|
const generateApiKeyResponse = await authenticatedInworldRequest(
|
|
1534
1576
|
ApiKeys.GenerateApiKey,
|
|
1535
1577
|
{
|
|
1536
|
-
parent
|
|
1578
|
+
parent
|
|
1537
1579
|
}
|
|
1538
1580
|
);
|
|
1539
1581
|
if (!generateApiKeyResponse) {
|
|
@@ -1558,6 +1600,58 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1558
1600
|
printListItem(`Key: ${generateApiKeyResponse.key}`);
|
|
1559
1601
|
printListItem(`Base64: ${base64Key}`);
|
|
1560
1602
|
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Creates a new API key with predefined scope preset and activates it.
|
|
1605
|
+
* @param mode 'read' for read-only, 'write' for read/write voices & router
|
|
1606
|
+
* @param displayName Optional display name for the key
|
|
1607
|
+
*/
|
|
1608
|
+
static async createApiKey(mode, displayName) {
|
|
1609
|
+
const credentials = await authManager.getCredentials();
|
|
1610
|
+
if (!credentials?.workspace) {
|
|
1611
|
+
printError(
|
|
1612
|
+
'No workspace activated. Please run "inworld workspace activate" first.'
|
|
1613
|
+
);
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1617
|
+
const baseScopes = ["api.rt::x", "api.ml::x", "api.ops::x"];
|
|
1618
|
+
const scopes = mode === "write" ? [...baseScopes, "api.dsgnt.voices::rw", "api.dsgnt.router::rw"] : [...baseScopes, "api.dsgnt.voices::r", "api.dsgnt.router::r"];
|
|
1619
|
+
const label = mode === "write" ? "read/write" : "read-only";
|
|
1620
|
+
print(`Creating ${label} API key...`);
|
|
1621
|
+
const generateApiKeyResponse = await authenticatedInworldRequest(
|
|
1622
|
+
ApiKeys.GenerateApiKey,
|
|
1623
|
+
{
|
|
1624
|
+
parent,
|
|
1625
|
+
scopes,
|
|
1626
|
+
displayName,
|
|
1627
|
+
authTypes: [
|
|
1628
|
+
"API_KEY_AUTHORIZATION_TYPE_BASIC" /* API_KEY_AUTHORIZATION_TYPE_BASIC */,
|
|
1629
|
+
"API_KEY_AUTHORIZATION_TYPE_JWT" /* API_KEY_AUTHORIZATION_TYPE_JWT */
|
|
1630
|
+
]
|
|
1631
|
+
}
|
|
1632
|
+
);
|
|
1633
|
+
if (!generateApiKeyResponse) {
|
|
1634
|
+
printError("Failed to generate API key.");
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const base64Key = this.returnBase64(
|
|
1638
|
+
generateApiKeyResponse.key,
|
|
1639
|
+
generateApiKeyResponse.secret
|
|
1640
|
+
);
|
|
1641
|
+
await authManager.updateWorkspaceAndApiKey(
|
|
1642
|
+
credentials.workspace,
|
|
1643
|
+
base64Key
|
|
1644
|
+
);
|
|
1645
|
+
const permissions = formatApiKeyScopes(generateApiKeyResponse.scopes);
|
|
1646
|
+
success("\nAPI key created and activated.");
|
|
1647
|
+
console.log();
|
|
1648
|
+
printHeader("API Key details:");
|
|
1649
|
+
if (displayName) {
|
|
1650
|
+
printListItem(`Display Name: ${displayName}`);
|
|
1651
|
+
}
|
|
1652
|
+
printListItem(`Permissions: ${permissions || label}`);
|
|
1653
|
+
printListItem(`Key: ${trimBase64Key(base64Key)}`);
|
|
1654
|
+
}
|
|
1561
1655
|
};
|
|
1562
1656
|
|
|
1563
1657
|
// src/commands/auth/login_command.ts
|
|
@@ -1605,9 +1699,9 @@ var loginAction = async (options) => {
|
|
|
1605
1699
|
input: process.stdin,
|
|
1606
1700
|
output: process.stdout
|
|
1607
1701
|
});
|
|
1608
|
-
const enterPromise = new Promise((
|
|
1702
|
+
const enterPromise = new Promise((resolve3) => {
|
|
1609
1703
|
readlineInterface.question("Press Enter to open your browser...", () => {
|
|
1610
|
-
|
|
1704
|
+
resolve3();
|
|
1611
1705
|
});
|
|
1612
1706
|
});
|
|
1613
1707
|
const result = await Promise.race([
|
|
@@ -1919,15 +2013,15 @@ var Analytics = class _Analytics {
|
|
|
1919
2013
|
* Should be called before the CLI exits
|
|
1920
2014
|
*/
|
|
1921
2015
|
flush() {
|
|
1922
|
-
return new Promise((
|
|
2016
|
+
return new Promise((resolve3) => {
|
|
1923
2017
|
if (!this.initialized || !this.mixpanel) {
|
|
1924
|
-
|
|
2018
|
+
resolve3();
|
|
1925
2019
|
return;
|
|
1926
2020
|
}
|
|
1927
|
-
const timeout = setTimeout(() =>
|
|
2021
|
+
const timeout = setTimeout(() => resolve3(), 500);
|
|
1928
2022
|
setTimeout(() => {
|
|
1929
2023
|
clearTimeout(timeout);
|
|
1930
|
-
|
|
2024
|
+
resolve3();
|
|
1931
2025
|
}, 100);
|
|
1932
2026
|
});
|
|
1933
2027
|
}
|
|
@@ -2570,7 +2664,7 @@ var deployAction = async (file, options) => {
|
|
|
2570
2664
|
zlib: { level: 9 }
|
|
2571
2665
|
// Maximum compression
|
|
2572
2666
|
});
|
|
2573
|
-
const archiveComplete = new Promise((
|
|
2667
|
+
const archiveComplete = new Promise((resolve3, reject) => {
|
|
2574
2668
|
output.on("close", () => {
|
|
2575
2669
|
if (options.packageOnly) {
|
|
2576
2670
|
let packageName;
|
|
@@ -2590,7 +2684,7 @@ var deployAction = async (file, options) => {
|
|
|
2590
2684
|
print("Deployment should take around 5 minutes, please be patient.");
|
|
2591
2685
|
print("Deploying...");
|
|
2592
2686
|
console.log();
|
|
2593
|
-
|
|
2687
|
+
resolve3();
|
|
2594
2688
|
});
|
|
2595
2689
|
archive.on("error", (err) => {
|
|
2596
2690
|
reject(err);
|
|
@@ -2800,7 +2894,7 @@ async function downloadTemplateFromGitHub(templateName, targetPath, repository,
|
|
|
2800
2894
|
const zipPath = path3.join(tempDir, `${templateName}.zip`);
|
|
2801
2895
|
const archiveUrl = `https://api.github.com/repos/${owner}/${repo}/zipball/${repoBranch}`;
|
|
2802
2896
|
spinner.text = `Downloading repository archive from ${owner}/${repo}...`;
|
|
2803
|
-
await new Promise((
|
|
2897
|
+
await new Promise((resolve3, reject) => {
|
|
2804
2898
|
https.get(
|
|
2805
2899
|
archiveUrl,
|
|
2806
2900
|
{ headers: { "User-Agent": "inworld-cli" } },
|
|
@@ -2820,14 +2914,14 @@ async function downloadTemplateFromGitHub(templateName, targetPath, repository,
|
|
|
2820
2914
|
}
|
|
2821
2915
|
const fileStream = createWriteStream(zipPath);
|
|
2822
2916
|
redirectRes.pipe(fileStream);
|
|
2823
|
-
fileStream.on("finish",
|
|
2917
|
+
fileStream.on("finish", resolve3);
|
|
2824
2918
|
fileStream.on("error", reject);
|
|
2825
2919
|
}
|
|
2826
2920
|
).on("error", reject);
|
|
2827
2921
|
} else if (res.statusCode === 200) {
|
|
2828
2922
|
const fileStream = createWriteStream(zipPath);
|
|
2829
2923
|
res.pipe(fileStream);
|
|
2830
|
-
fileStream.on("finish",
|
|
2924
|
+
fileStream.on("finish", resolve3);
|
|
2831
2925
|
fileStream.on("error", reject);
|
|
2832
2926
|
} else {
|
|
2833
2927
|
reject(new Error(`Failed to download: ${res.statusCode}`));
|
|
@@ -2942,7 +3036,9 @@ async function getAvailableTemplatesWithMetadata() {
|
|
|
2942
3036
|
} catch (error) {
|
|
2943
3037
|
throw error;
|
|
2944
3038
|
}
|
|
2945
|
-
return templates.filter(
|
|
3039
|
+
return templates.filter(
|
|
3040
|
+
(template) => template.metadata.id === "llm-to-tts-node"
|
|
3041
|
+
);
|
|
2946
3042
|
}
|
|
2947
3043
|
function copyTemplateDirectory(src, dest) {
|
|
2948
3044
|
copyDirectory(src, dest);
|
|
@@ -2963,7 +3059,7 @@ Would you like to install dependencies now using npm? (y/n) `,
|
|
|
2963
3059
|
}
|
|
2964
3060
|
async function runPackageInstall(directory) {
|
|
2965
3061
|
const { spawn } = await import("child_process");
|
|
2966
|
-
return new Promise((
|
|
3062
|
+
return new Promise((resolve3, reject) => {
|
|
2967
3063
|
print(`Installing dependencies using npm...`);
|
|
2968
3064
|
const install = spawn("npm", ["install"], {
|
|
2969
3065
|
cwd: directory,
|
|
@@ -2973,7 +3069,7 @@ async function runPackageInstall(directory) {
|
|
|
2973
3069
|
install.on("close", (code) => {
|
|
2974
3070
|
if (code === 0) {
|
|
2975
3071
|
success("Dependencies installed successfully!");
|
|
2976
|
-
|
|
3072
|
+
resolve3();
|
|
2977
3073
|
} else {
|
|
2978
3074
|
printError(`\u274C npm install failed with code ${code}`);
|
|
2979
3075
|
reject(new Error(`npm install failed with code ${code}`));
|
|
@@ -3070,7 +3166,7 @@ Note: Templates are downloaded from GitHub repositories as complete applications
|
|
|
3070
3166
|
let selectedTemplateId;
|
|
3071
3167
|
const templates = await fetchTemplatesMetadata();
|
|
3072
3168
|
if (!options.template) {
|
|
3073
|
-
printBright("\u{1F680} Welcome to Inworld Template Initializer!");
|
|
3169
|
+
printBright("\u{1F680} Welcome to the Inworld Template Initializer!");
|
|
3074
3170
|
if (templates.length === 0) {
|
|
3075
3171
|
printError("\u274C No templates found.");
|
|
3076
3172
|
print(`
|
|
@@ -3083,7 +3179,7 @@ Please ensure the templates metadata is accessible.`);
|
|
|
3083
3179
|
return `${bold(cyan(template2.name))} - ${template2.description}`;
|
|
3084
3180
|
},
|
|
3085
3181
|
getIdentifier: (template2) => template2.id,
|
|
3086
|
-
prompt: "Select a template (enter number or name)",
|
|
3182
|
+
prompt: "Select a template (enter number or name):",
|
|
3087
3183
|
title: "\u{1F4CB} Available Templates:",
|
|
3088
3184
|
exitOnFailure: true
|
|
3089
3185
|
});
|
|
@@ -3167,13 +3263,13 @@ Please ensure the template exists in the templates metadata and the repository i
|
|
|
3167
3263
|
input: process.stdin,
|
|
3168
3264
|
output: process.stdout
|
|
3169
3265
|
});
|
|
3170
|
-
const askProjectName = () => new Promise((
|
|
3266
|
+
const askProjectName = () => new Promise((resolve3) => {
|
|
3171
3267
|
rl.question(
|
|
3172
3268
|
`
|
|
3173
3269
|
Project name (${selectedTemplate.metadata.id || selectedTemplate.metadata.name}): `,
|
|
3174
3270
|
(answer) => {
|
|
3175
3271
|
rl.close();
|
|
3176
|
-
|
|
3272
|
+
resolve3(
|
|
3177
3273
|
answer.trim() || selectedTemplate.metadata.id || selectedTemplate.metadata.name
|
|
3178
3274
|
);
|
|
3179
3275
|
}
|
|
@@ -3549,31 +3645,37 @@ var graphCommand = new Command19("graph").description("Manage Inworld graph proj
|
|
|
3549
3645
|
});
|
|
3550
3646
|
|
|
3551
3647
|
// src/commands/tts_commands.ts
|
|
3648
|
+
import { Command as Command24 } from "commander";
|
|
3649
|
+
|
|
3650
|
+
// src/commands/tts/tts_clone_command.ts
|
|
3552
3651
|
import chalk4 from "chalk";
|
|
3553
3652
|
import { Command as Command20 } from "commander";
|
|
3554
|
-
import {
|
|
3653
|
+
import { readFile } from "fs/promises";
|
|
3555
3654
|
import { resolve } from "path";
|
|
3556
3655
|
|
|
3557
3656
|
// src/services/tts_service.ts
|
|
3657
|
+
var LEGACY_MODELS = /* @__PURE__ */ new Set([
|
|
3658
|
+
"inworld-tts-1" /* INWORLD_TTS_1 */,
|
|
3659
|
+
"inworld-tts-1-max" /* INWORLD_TTS_1_MAX */
|
|
3660
|
+
]);
|
|
3558
3661
|
var TTSService = class {
|
|
3559
3662
|
apiKey = null;
|
|
3560
|
-
/**
|
|
3561
|
-
* Ensures the API key is available
|
|
3562
|
-
* @private
|
|
3563
|
-
*/
|
|
3564
3663
|
async ensureApiKey() {
|
|
3565
3664
|
if (!this.apiKey) {
|
|
3566
3665
|
this.apiKey = await requireApiKey();
|
|
3567
3666
|
}
|
|
3568
3667
|
return this.apiKey;
|
|
3569
3668
|
}
|
|
3669
|
+
/** Builds the API base URL from the platform URL */
|
|
3670
|
+
get apiBaseUrl() {
|
|
3671
|
+
return PLATFORM_URL.replace("platform", "api");
|
|
3672
|
+
}
|
|
3570
3673
|
/**
|
|
3571
3674
|
* Makes an authenticated request to the Inworld API
|
|
3572
|
-
* @private
|
|
3573
3675
|
*/
|
|
3574
3676
|
async makeRequest(endpoint, options = {}, trackMetrics = false) {
|
|
3575
3677
|
const apiKey = await this.ensureApiKey();
|
|
3576
|
-
const url = `${
|
|
3678
|
+
const url = `${this.apiBaseUrl}${endpoint}`;
|
|
3577
3679
|
const metrics = trackMetrics ? {
|
|
3578
3680
|
startTime: Date.now(),
|
|
3579
3681
|
ttfb: 0,
|
|
@@ -3598,9 +3700,18 @@ var TTSService = class {
|
|
|
3598
3700
|
}
|
|
3599
3701
|
if (!response.ok) {
|
|
3600
3702
|
const error = data;
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
)
|
|
3703
|
+
const code = error.code || response.status;
|
|
3704
|
+
const message = error.message || "Unknown error";
|
|
3705
|
+
if (code === 7 && /scope/i.test(message)) {
|
|
3706
|
+
throw new Error(
|
|
3707
|
+
`${message}
|
|
3708
|
+
|
|
3709
|
+
Your API key does not have the required scopes for this operation.
|
|
3710
|
+
Run "inworld ws select-key" to switch to a key with the correct permissions,
|
|
3711
|
+
or "inworld ws add-key --write" to create a new one with read/write access.`
|
|
3712
|
+
);
|
|
3713
|
+
}
|
|
3714
|
+
throw new Error(`TTS API Error [${code}]: ${message}`);
|
|
3604
3715
|
}
|
|
3605
3716
|
const result = data;
|
|
3606
3717
|
if (trackMetrics) {
|
|
@@ -3610,14 +3721,6 @@ var TTSService = class {
|
|
|
3610
3721
|
}
|
|
3611
3722
|
/**
|
|
3612
3723
|
* Lists all available voices based on the provided filter
|
|
3613
|
-
* @param filter - Optional filter expression (e.g., "language=en")
|
|
3614
|
-
* @returns Promise resolving to the list of available voices
|
|
3615
|
-
* @example
|
|
3616
|
-
* ```typescript
|
|
3617
|
-
* const ttsService = new TTSService();
|
|
3618
|
-
* const voices = await ttsService.listVoices('language=en');
|
|
3619
|
-
* console.log(voices.voices);
|
|
3620
|
-
* ```
|
|
3621
3724
|
*/
|
|
3622
3725
|
async listVoices(filter) {
|
|
3623
3726
|
const params = filter ? `?filter=${encodeURIComponent(filter)}` : "";
|
|
@@ -3627,19 +3730,6 @@ var TTSService = class {
|
|
|
3627
3730
|
}
|
|
3628
3731
|
/**
|
|
3629
3732
|
* Synthesizes speech from text
|
|
3630
|
-
* @param request - The synthesis request parameters
|
|
3631
|
-
* @returns Promise resolving to the synthesized audio data and optional timestamp information
|
|
3632
|
-
* @example
|
|
3633
|
-
* ```typescript
|
|
3634
|
-
* const ttsService = new TTSService();
|
|
3635
|
-
* const result = await ttsService.synthesizeSpeech({
|
|
3636
|
-
* text: 'Hello, world!',
|
|
3637
|
-
* voiceId: 'Dennis',
|
|
3638
|
-
* modelId: TTSModel.INWORLD_TTS_1,
|
|
3639
|
-
* timestampType: TimestampType.WORD,
|
|
3640
|
-
* });
|
|
3641
|
-
* // result.audioContent is base64 encoded audio data
|
|
3642
|
-
* ```
|
|
3643
3733
|
*/
|
|
3644
3734
|
async synthesizeSpeech(request) {
|
|
3645
3735
|
return this.makeRequest("/tts/v1/voice", {
|
|
@@ -3649,8 +3739,6 @@ var TTSService = class {
|
|
|
3649
3739
|
}
|
|
3650
3740
|
/**
|
|
3651
3741
|
* Synthesizes speech from text with performance metrics
|
|
3652
|
-
* @param request - The synthesis request parameters
|
|
3653
|
-
* @returns Promise resolving to the synthesized audio data with metrics
|
|
3654
3742
|
*/
|
|
3655
3743
|
async synthesizeSpeechWithMetrics(request) {
|
|
3656
3744
|
return this.makeRequest(
|
|
@@ -3660,19 +3748,14 @@ var TTSService = class {
|
|
|
3660
3748
|
body: JSON.stringify(request)
|
|
3661
3749
|
},
|
|
3662
3750
|
true
|
|
3663
|
-
// trackMetrics
|
|
3664
3751
|
);
|
|
3665
3752
|
}
|
|
3666
3753
|
/**
|
|
3667
3754
|
* Synthesizes speech using streaming API
|
|
3668
|
-
* @param request - The synthesis request parameters
|
|
3669
|
-
* @param onChunk - Callback for each audio chunk received
|
|
3670
|
-
* @param trackMetrics - Whether to track streaming metrics
|
|
3671
|
-
* @returns Promise resolving when stream completes, with optional metrics
|
|
3672
3755
|
*/
|
|
3673
3756
|
async synthesizeSpeechStream(request, onChunk, trackMetrics = false) {
|
|
3674
3757
|
const apiKey = await this.ensureApiKey();
|
|
3675
|
-
const url = `${
|
|
3758
|
+
const url = `${this.apiBaseUrl}/tts/v1/voice:stream`;
|
|
3676
3759
|
const metrics = trackMetrics ? {
|
|
3677
3760
|
startTime: Date.now(),
|
|
3678
3761
|
timeToFirstChunk: 0,
|
|
@@ -3687,15 +3770,25 @@ var TTSService = class {
|
|
|
3687
3770
|
method: "POST",
|
|
3688
3771
|
headers: {
|
|
3689
3772
|
Authorization: `Basic ${apiKey}`,
|
|
3690
|
-
"Content-Type": "application/json"
|
|
3773
|
+
"Content-Type": "application/json",
|
|
3774
|
+
Connection: "keep-alive"
|
|
3691
3775
|
},
|
|
3692
3776
|
body: JSON.stringify(request)
|
|
3693
3777
|
});
|
|
3694
3778
|
if (!response.ok) {
|
|
3695
3779
|
const error = await response.json();
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
)
|
|
3780
|
+
const code = error.code || response.status;
|
|
3781
|
+
const message = error.message || "Unknown error";
|
|
3782
|
+
if (code === 7 && /scope/i.test(message)) {
|
|
3783
|
+
throw new Error(
|
|
3784
|
+
`${message}
|
|
3785
|
+
|
|
3786
|
+
Your API key does not have the required scopes for this operation.
|
|
3787
|
+
Run "inworld ws select-key" to switch to a key with the correct permissions,
|
|
3788
|
+
or "inworld ws add-key --write" to create a new one with read/write access.`
|
|
3789
|
+
);
|
|
3790
|
+
}
|
|
3791
|
+
throw new Error(`TTS Stream API Error [${code}]: ${message}`);
|
|
3699
3792
|
}
|
|
3700
3793
|
if (!response.body) {
|
|
3701
3794
|
throw new Error("No response body received from streaming endpoint");
|
|
@@ -3767,18 +3860,8 @@ var TTSService = class {
|
|
|
3767
3860
|
}
|
|
3768
3861
|
/**
|
|
3769
3862
|
* Helper method to synthesize speech with simple parameters
|
|
3770
|
-
* @param text - The text to synthesize
|
|
3771
|
-
* @param voiceId - The voice ID to use
|
|
3772
|
-
* @param modelId - The model ID to use (defaults to inworld-tts-1-max)
|
|
3773
|
-
* @returns Promise resolving to the synthesized audio data
|
|
3774
|
-
* @example
|
|
3775
|
-
* ```typescript
|
|
3776
|
-
* const ttsService = new TTSService();
|
|
3777
|
-
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
3778
|
-
* const audioBuffer = Buffer.from(result.audioContent, 'base64');
|
|
3779
|
-
* ```
|
|
3780
3863
|
*/
|
|
3781
|
-
async synthesize(text, voiceId, modelId = "inworld-tts-1-max" /*
|
|
3864
|
+
async synthesize(text, voiceId, modelId = "inworld-tts-1.5-max" /* INWORLD_TTS_1_5_MAX */) {
|
|
3782
3865
|
return this.synthesizeSpeech({
|
|
3783
3866
|
text,
|
|
3784
3867
|
voiceId,
|
|
@@ -3787,25 +3870,158 @@ var TTSService = class {
|
|
|
3787
3870
|
}
|
|
3788
3871
|
/**
|
|
3789
3872
|
* Saves synthesized audio to a file
|
|
3790
|
-
* @param audioContent - Base64 encoded audio content
|
|
3791
|
-
* @param filepath - Path where the audio file should be saved
|
|
3792
|
-
* @returns Promise that resolves when the file is written
|
|
3793
|
-
* @example
|
|
3794
|
-
* ```typescript
|
|
3795
|
-
* const ttsService = new TTSService();
|
|
3796
|
-
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
3797
|
-
* await ttsService.saveAudioToFile(result.audioContent, 'output.mp3');
|
|
3798
|
-
* ```
|
|
3799
3873
|
*/
|
|
3800
3874
|
async saveAudioToFile(audioContent, filepath) {
|
|
3801
|
-
const { writeFile:
|
|
3875
|
+
const { writeFile: writeFile3 } = await import("fs/promises");
|
|
3802
3876
|
const audioBuffer = Buffer.from(audioContent, "base64");
|
|
3803
|
-
await
|
|
3877
|
+
await writeFile3(filepath, audioBuffer);
|
|
3878
|
+
}
|
|
3879
|
+
// --- Voice Cloning ---
|
|
3880
|
+
/**
|
|
3881
|
+
* Clones a voice from audio samples
|
|
3882
|
+
*/
|
|
3883
|
+
async cloneVoice(request) {
|
|
3884
|
+
return this.makeRequest("/voices/v1/voices:clone", {
|
|
3885
|
+
method: "POST",
|
|
3886
|
+
body: JSON.stringify(request)
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3889
|
+
// --- Voice Design ---
|
|
3890
|
+
/**
|
|
3891
|
+
* Generates preview text for voice design
|
|
3892
|
+
*/
|
|
3893
|
+
async generatePreviewText(workspace, description, langCode) {
|
|
3894
|
+
const resourceName = ensureWorkspaceResourceName(workspace);
|
|
3895
|
+
return this.makeRequest(
|
|
3896
|
+
`/voices/v1/${resourceName}/voices:generatePreviewText`,
|
|
3897
|
+
{
|
|
3898
|
+
method: "POST",
|
|
3899
|
+
body: JSON.stringify({ description, langCode })
|
|
3900
|
+
}
|
|
3901
|
+
);
|
|
3902
|
+
}
|
|
3903
|
+
/**
|
|
3904
|
+
* Designs a voice from a text description
|
|
3905
|
+
*/
|
|
3906
|
+
async designVoice(request) {
|
|
3907
|
+
return this.makeRequest("/voices/v1/voices:design", {
|
|
3908
|
+
method: "POST",
|
|
3909
|
+
body: JSON.stringify(request)
|
|
3910
|
+
});
|
|
3911
|
+
}
|
|
3912
|
+
/**
|
|
3913
|
+
* Publishes a designed voice preview to the voice library
|
|
3914
|
+
*/
|
|
3915
|
+
async publishVoice(voiceId, request) {
|
|
3916
|
+
return this.makeRequest(
|
|
3917
|
+
`/voices/v1/voices/${voiceId}:publish`,
|
|
3918
|
+
{
|
|
3919
|
+
method: "POST",
|
|
3920
|
+
body: JSON.stringify(request)
|
|
3921
|
+
}
|
|
3922
|
+
);
|
|
3804
3923
|
}
|
|
3805
3924
|
};
|
|
3806
3925
|
var ttsService = new TTSService();
|
|
3807
3926
|
|
|
3808
|
-
// src/commands/
|
|
3927
|
+
// src/commands/tts/tts_clone_command.ts
|
|
3928
|
+
var cloneCommand = new Command20("clone").description("Clone a voice from an audio file (5-15 seconds, max 4MB)").argument("<audioFile>", "Path to audio file (wav, mp3, webm)").requiredOption("-n, --name <name>", "Display name for the cloned voice").option("-l, --lang <code>", "Language code (e.g., EN_US)", "EN_US").option("-t, --transcription <text>", "Transcription of the audio").option("-d, --description <text>", "Description of the voice").option("--tags <tags>", "Comma-separated tags").option("--remove-noise", "Remove background noise from audio").option("-j, --json", "Output response as JSON").action(async (audioFile, options) => {
|
|
3929
|
+
try {
|
|
3930
|
+
const filePath = resolve(audioFile);
|
|
3931
|
+
const audioData = await readFile(filePath);
|
|
3932
|
+
if (audioData.length > 4 * 1024 * 1024) {
|
|
3933
|
+
console.error(chalk4.red("Error: Audio file exceeds 4MB limit"));
|
|
3934
|
+
process.exit(1);
|
|
3935
|
+
}
|
|
3936
|
+
const audioBase64 = audioData.toString("base64");
|
|
3937
|
+
console.log(chalk4.cyan("Cloning voice..."));
|
|
3938
|
+
console.log(chalk4.gray(`File: ${filePath}`));
|
|
3939
|
+
console.log(chalk4.gray(`Name: ${options.name}`));
|
|
3940
|
+
console.log(
|
|
3941
|
+
chalk4.gray(`Size: ${(audioData.length / 1024).toFixed(1)} KB`)
|
|
3942
|
+
);
|
|
3943
|
+
const response = await ttsService.cloneVoice({
|
|
3944
|
+
displayName: options.name,
|
|
3945
|
+
langCode: options.lang,
|
|
3946
|
+
voiceSamples: [
|
|
3947
|
+
{
|
|
3948
|
+
audioData: audioBase64,
|
|
3949
|
+
transcription: options.transcription
|
|
3950
|
+
}
|
|
3951
|
+
],
|
|
3952
|
+
description: options.description,
|
|
3953
|
+
tags: options.tags?.split(",").map((t) => t.trim()).filter(Boolean),
|
|
3954
|
+
audioProcessingConfig: options.removeNoise ? { removeBackgroundNoise: true } : void 0
|
|
3955
|
+
});
|
|
3956
|
+
if (options.json) {
|
|
3957
|
+
console.log(JSON.stringify(response, null, 2));
|
|
3958
|
+
process.exit(0);
|
|
3959
|
+
return;
|
|
3960
|
+
}
|
|
3961
|
+
for (const sample of response.audioSamplesValidated) {
|
|
3962
|
+
for (const warning of sample.warnings) {
|
|
3963
|
+
console.log(chalk4.yellow(`${warning}`));
|
|
3964
|
+
}
|
|
3965
|
+
for (const error of sample.errors) {
|
|
3966
|
+
console.log(chalk4.red(`${error}`));
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
const voice = response.voice;
|
|
3970
|
+
console.log(chalk4.green("\nVoice cloned successfully!"));
|
|
3971
|
+
console.log(chalk4.white(` Voice ID: ${chalk4.cyan(voice.voiceId)}`));
|
|
3972
|
+
console.log(chalk4.white(` Display Name: ${voice.displayName}`));
|
|
3973
|
+
console.log(chalk4.white(` Language: ${voice.langCode}`));
|
|
3974
|
+
if (voice.description) {
|
|
3975
|
+
console.log(chalk4.white(` Description: ${voice.description}`));
|
|
3976
|
+
}
|
|
3977
|
+
console.log(
|
|
3978
|
+
chalk4.gray(
|
|
3979
|
+
`
|
|
3980
|
+
Use this voice: inworld tts synthesize "Hello" -v ${voice.voiceId}`
|
|
3981
|
+
)
|
|
3982
|
+
);
|
|
3983
|
+
process.exit(0);
|
|
3984
|
+
} catch (error) {
|
|
3985
|
+
console.error(chalk4.red("Error cloning voice:"));
|
|
3986
|
+
console.error(chalk4.red(error.message || error));
|
|
3987
|
+
process.exit(1);
|
|
3988
|
+
}
|
|
3989
|
+
});
|
|
3990
|
+
|
|
3991
|
+
// src/commands/tts/tts_design_command.ts
|
|
3992
|
+
import chalk6 from "chalk";
|
|
3993
|
+
import { Command as Command21 } from "commander";
|
|
3994
|
+
import { writeFile } from "fs/promises";
|
|
3995
|
+
import { tmpdir } from "os";
|
|
3996
|
+
import { join } from "path";
|
|
3997
|
+
import * as readline6 from "readline";
|
|
3998
|
+
|
|
3999
|
+
// src/utils/audio_player.ts
|
|
4000
|
+
import { unlink } from "fs/promises";
|
|
4001
|
+
async function playFile(filePath) {
|
|
4002
|
+
try {
|
|
4003
|
+
const player = (await import("play-sound")).default();
|
|
4004
|
+
await new Promise((resolve3, reject) => {
|
|
4005
|
+
player.play(filePath, (err) => {
|
|
4006
|
+
if (err) reject(err);
|
|
4007
|
+
else resolve3();
|
|
4008
|
+
});
|
|
4009
|
+
});
|
|
4010
|
+
return true;
|
|
4011
|
+
} catch {
|
|
4012
|
+
return false;
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
async function cleanupTempFile(filepath) {
|
|
4016
|
+
try {
|
|
4017
|
+
await unlink(filepath);
|
|
4018
|
+
} catch {
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
|
|
4022
|
+
// src/commands/tts/tts_utils.ts
|
|
4023
|
+
import chalk5 from "chalk";
|
|
4024
|
+
import * as readline5 from "readline";
|
|
3809
4025
|
function wrapText(text, maxWidth) {
|
|
3810
4026
|
const words = text.split(" ");
|
|
3811
4027
|
const lines = [];
|
|
@@ -3821,7 +4037,300 @@ function wrapText(text, maxWidth) {
|
|
|
3821
4037
|
if (currentLine) lines.push(currentLine);
|
|
3822
4038
|
return lines;
|
|
3823
4039
|
}
|
|
3824
|
-
|
|
4040
|
+
function resolveModel(modelStr) {
|
|
4041
|
+
const modelMap = {
|
|
4042
|
+
"inworld-tts-1": "inworld-tts-1" /* INWORLD_TTS_1 */,
|
|
4043
|
+
"inworld-tts-1-max": "inworld-tts-1-max" /* INWORLD_TTS_1_MAX */,
|
|
4044
|
+
"inworld-tts-1.5-mini": "inworld-tts-1.5-mini" /* INWORLD_TTS_1_5_MINI */,
|
|
4045
|
+
"inworld-tts-1.5-max": "inworld-tts-1.5-max" /* INWORLD_TTS_1_5_MAX */
|
|
4046
|
+
};
|
|
4047
|
+
const model = modelMap[modelStr];
|
|
4048
|
+
if (!model) {
|
|
4049
|
+
console.error(
|
|
4050
|
+
chalk5.red(
|
|
4051
|
+
`Unknown model: ${modelStr}. Available: ${Object.keys(modelMap).join(", ")}`
|
|
4052
|
+
)
|
|
4053
|
+
);
|
|
4054
|
+
process.exit(1);
|
|
4055
|
+
}
|
|
4056
|
+
if (LEGACY_MODELS.has(model)) {
|
|
4057
|
+
console.log(
|
|
4058
|
+
chalk5.yellow(
|
|
4059
|
+
`Model "${modelStr}" is deprecated. Consider using "inworld-tts-1.5-mini" or "inworld-tts-1.5-max".`
|
|
4060
|
+
)
|
|
4061
|
+
);
|
|
4062
|
+
}
|
|
4063
|
+
return model;
|
|
4064
|
+
}
|
|
4065
|
+
var FORMAT_EXTENSIONS = {
|
|
4066
|
+
MP3: ".mp3",
|
|
4067
|
+
LINEAR16: ".wav",
|
|
4068
|
+
WAV: ".wav",
|
|
4069
|
+
OGG_OPUS: ".ogg",
|
|
4070
|
+
ALAW: ".raw",
|
|
4071
|
+
MULAW: ".raw",
|
|
4072
|
+
FLAC: ".flac",
|
|
4073
|
+
PCM: ".pcm"
|
|
4074
|
+
};
|
|
4075
|
+
var VALID_FORMATS = Object.keys(FORMAT_EXTENSIONS);
|
|
4076
|
+
function getFileExtension(format) {
|
|
4077
|
+
return FORMAT_EXTENSIONS[format] || ".mp3";
|
|
4078
|
+
}
|
|
4079
|
+
function resolveFormat(format, defaultFormat) {
|
|
4080
|
+
if (!format) return defaultFormat;
|
|
4081
|
+
const normalized = format.toUpperCase();
|
|
4082
|
+
if (!FORMAT_EXTENSIONS[normalized]) {
|
|
4083
|
+
console.error(
|
|
4084
|
+
chalk5.red(
|
|
4085
|
+
`Unknown format: ${format}. Available: ${VALID_FORMATS.join(", ")}`
|
|
4086
|
+
)
|
|
4087
|
+
);
|
|
4088
|
+
process.exit(1);
|
|
4089
|
+
}
|
|
4090
|
+
return normalized;
|
|
4091
|
+
}
|
|
4092
|
+
function promptInput(prompt, defaultValue) {
|
|
4093
|
+
const rl = readline5.createInterface({
|
|
4094
|
+
input: process.stdin,
|
|
4095
|
+
output: process.stdout
|
|
4096
|
+
});
|
|
4097
|
+
const displayPrompt = defaultValue ? `${prompt} [${defaultValue}]: ` : `${prompt}: `;
|
|
4098
|
+
return new Promise((resolve3) => {
|
|
4099
|
+
rl.question(displayPrompt, (answer) => {
|
|
4100
|
+
rl.close();
|
|
4101
|
+
resolve3(answer.trim() || defaultValue || "");
|
|
4102
|
+
});
|
|
4103
|
+
});
|
|
4104
|
+
}
|
|
4105
|
+
|
|
4106
|
+
// src/commands/tts/tts_design_command.ts
|
|
4107
|
+
async function savePreviewsToTemp(previews) {
|
|
4108
|
+
const paths = [];
|
|
4109
|
+
for (let i = 0; i < previews.length; i++) {
|
|
4110
|
+
const safeId = previews[i].voiceId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4111
|
+
const tempPath = join(tmpdir(), `inworld-preview-${i + 1}-${safeId}.wav`);
|
|
4112
|
+
const buf = Buffer.from(previews[i].previewAudio, "base64");
|
|
4113
|
+
await writeFile(tempPath, buf);
|
|
4114
|
+
paths.push(tempPath);
|
|
4115
|
+
}
|
|
4116
|
+
return paths;
|
|
4117
|
+
}
|
|
4118
|
+
var designCommand = new Command21("design").description(
|
|
4119
|
+
"Design a voice from a text description (interactive wizard)\n\nGenerates voice previews, lets you listen and pick, then publishes."
|
|
4120
|
+
).argument("<prompt>", "Voice description (30-250 characters, English)").option(
|
|
4121
|
+
"-s, --script <text>",
|
|
4122
|
+
"Preview script for the voice to speak (50-200 chars)"
|
|
4123
|
+
).option(
|
|
4124
|
+
"--auto-script",
|
|
4125
|
+
"Auto-generate preview script from prompt instead of using --script"
|
|
4126
|
+
).option("-l, --lang <code>", "Language code (e.g., EN_US)", "EN_US").option("-c, --count <n>", "Number of preview samples (1-3)", "3").option("-n, --name <name>", "Display name for publishing").option("-d, --description <text>", "Description for publishing").option("--tags <tags>", "Comma-separated tags for publishing").option("-j, --json", "Non-interactive: output all previews as JSON").action(async (prompt, options) => {
|
|
4127
|
+
let tempFiles = [];
|
|
4128
|
+
try {
|
|
4129
|
+
if (prompt.length < 30 || prompt.length > 250) {
|
|
4130
|
+
console.error(
|
|
4131
|
+
chalk6.red("Error: Design prompt must be 30-250 characters")
|
|
4132
|
+
);
|
|
4133
|
+
console.log(chalk6.gray(`Current length: ${prompt.length} characters`));
|
|
4134
|
+
process.exit(1);
|
|
4135
|
+
}
|
|
4136
|
+
const count = parseInt(options.count, 10);
|
|
4137
|
+
if (isNaN(count) || count < 1 || count > 3) {
|
|
4138
|
+
console.error(chalk6.red("Error: --count must be 1, 2, or 3"));
|
|
4139
|
+
process.exit(1);
|
|
4140
|
+
}
|
|
4141
|
+
let previewText = options.script;
|
|
4142
|
+
if (!previewText && !options.autoScript) {
|
|
4143
|
+
console.error(
|
|
4144
|
+
chalk6.red("Error: Provide --script <text> or use --auto-script")
|
|
4145
|
+
);
|
|
4146
|
+
process.exit(1);
|
|
4147
|
+
}
|
|
4148
|
+
if (options.autoScript) {
|
|
4149
|
+
console.log(chalk6.cyan("Generating preview script..."));
|
|
4150
|
+
const workspace = await requireWorkspace();
|
|
4151
|
+
const result = await ttsService.generatePreviewText(
|
|
4152
|
+
workspace,
|
|
4153
|
+
prompt,
|
|
4154
|
+
options.lang
|
|
4155
|
+
);
|
|
4156
|
+
previewText = result.previewText;
|
|
4157
|
+
console.log(chalk6.gray(` "${previewText}"`));
|
|
4158
|
+
} else if (previewText.length < 50 || previewText.length > 200) {
|
|
4159
|
+
console.error(
|
|
4160
|
+
chalk6.red("Error: Preview script must be 50-200 characters")
|
|
4161
|
+
);
|
|
4162
|
+
process.exit(1);
|
|
4163
|
+
}
|
|
4164
|
+
tempFiles = [];
|
|
4165
|
+
const generate = async () => {
|
|
4166
|
+
console.log(chalk6.cyan("\nDesigning voice..."));
|
|
4167
|
+
const response = await ttsService.designVoice({
|
|
4168
|
+
langCode: options.lang,
|
|
4169
|
+
designPrompt: prompt,
|
|
4170
|
+
previewText,
|
|
4171
|
+
voiceDesignConfig: { numberOfSamples: count }
|
|
4172
|
+
});
|
|
4173
|
+
return response.previewVoices;
|
|
4174
|
+
};
|
|
4175
|
+
let previews = await generate();
|
|
4176
|
+
if (options.json) {
|
|
4177
|
+
console.log(JSON.stringify(previews, null, 2));
|
|
4178
|
+
process.exit(0);
|
|
4179
|
+
return;
|
|
4180
|
+
}
|
|
4181
|
+
let selectedVoiceId = null;
|
|
4182
|
+
if (previews.length === 1) {
|
|
4183
|
+
const preview = previews[0];
|
|
4184
|
+
tempFiles = await savePreviewsToTemp(previews);
|
|
4185
|
+
console.log(chalk6.green(`
|
|
4186
|
+
Generated voice preview:
|
|
4187
|
+
`));
|
|
4188
|
+
console.log(
|
|
4189
|
+
` ${chalk6.bold.white("1.")} ${chalk6.cyan(preview.voiceId)}`
|
|
4190
|
+
);
|
|
4191
|
+
console.log(chalk6.gray(` ${tempFiles[0]}`));
|
|
4192
|
+
selectedVoiceId = preview.voiceId;
|
|
4193
|
+
}
|
|
4194
|
+
while (!selectedVoiceId) {
|
|
4195
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4196
|
+
tempFiles = await savePreviewsToTemp(previews);
|
|
4197
|
+
console.log(
|
|
4198
|
+
chalk6.green(`
|
|
4199
|
+
Generated ${previews.length} voice preview(s):
|
|
4200
|
+
`)
|
|
4201
|
+
);
|
|
4202
|
+
for (let i = 0; i < previews.length; i++) {
|
|
4203
|
+
console.log(
|
|
4204
|
+
` ${chalk6.bold.white(`${i + 1}.`)} ${chalk6.cyan(previews[i].voiceId)}`
|
|
4205
|
+
);
|
|
4206
|
+
console.log(chalk6.gray(` ${tempFiles[i]}`));
|
|
4207
|
+
}
|
|
4208
|
+
console.log(
|
|
4209
|
+
chalk6.gray(
|
|
4210
|
+
`
|
|
4211
|
+
Actions: [1-${previews.length}] play a preview, [p] publish, [r] regenerate, [q] quit`
|
|
4212
|
+
)
|
|
4213
|
+
);
|
|
4214
|
+
const rl = readline6.createInterface({
|
|
4215
|
+
input: process.stdin,
|
|
4216
|
+
output: process.stdout
|
|
4217
|
+
});
|
|
4218
|
+
const ask = (q) => new Promise((resolve3) => rl.question(q, resolve3));
|
|
4219
|
+
let action = null;
|
|
4220
|
+
while (true) {
|
|
4221
|
+
const answer = (await ask("> ")).trim().toLowerCase();
|
|
4222
|
+
const idx = parseInt(answer, 10);
|
|
4223
|
+
if (!isNaN(idx) && idx >= 1 && idx <= previews.length) {
|
|
4224
|
+
console.log(
|
|
4225
|
+
chalk6.white(
|
|
4226
|
+
` Playing preview ${idx}... (${chalk6.cyan(previews[idx - 1].voiceId)})`
|
|
4227
|
+
)
|
|
4228
|
+
);
|
|
4229
|
+
const played = await playFile(tempFiles[idx - 1]);
|
|
4230
|
+
if (!played) {
|
|
4231
|
+
console.log(
|
|
4232
|
+
chalk6.gray(
|
|
4233
|
+
` Playback unavailable. Open: ${tempFiles[idx - 1]}`
|
|
4234
|
+
)
|
|
4235
|
+
);
|
|
4236
|
+
}
|
|
4237
|
+
continue;
|
|
4238
|
+
}
|
|
4239
|
+
if (answer === "r") {
|
|
4240
|
+
action = "regenerate";
|
|
4241
|
+
break;
|
|
4242
|
+
}
|
|
4243
|
+
if (answer === "q") {
|
|
4244
|
+
action = "quit";
|
|
4245
|
+
break;
|
|
4246
|
+
}
|
|
4247
|
+
if (answer === "p") {
|
|
4248
|
+
action = "publish";
|
|
4249
|
+
break;
|
|
4250
|
+
}
|
|
4251
|
+
console.log(
|
|
4252
|
+
chalk6.yellow(
|
|
4253
|
+
` Enter 1-${previews.length} to play, p to publish, r to regenerate, q to quit`
|
|
4254
|
+
)
|
|
4255
|
+
);
|
|
4256
|
+
}
|
|
4257
|
+
rl.close();
|
|
4258
|
+
if (action === "quit") {
|
|
4259
|
+
break;
|
|
4260
|
+
}
|
|
4261
|
+
if (action === "regenerate") {
|
|
4262
|
+
console.log(chalk6.cyan("Regenerating..."));
|
|
4263
|
+
previews = await generate();
|
|
4264
|
+
continue;
|
|
4265
|
+
}
|
|
4266
|
+
if (action === "publish") {
|
|
4267
|
+
if (previews.length === 1) {
|
|
4268
|
+
selectedVoiceId = previews[0].voiceId;
|
|
4269
|
+
} else {
|
|
4270
|
+
const choice = await promptInput(
|
|
4271
|
+
` Which voice to publish? (1-${previews.length})`
|
|
4272
|
+
);
|
|
4273
|
+
const choiceIdx = parseInt(choice, 10);
|
|
4274
|
+
if (isNaN(choiceIdx) || choiceIdx < 1 || choiceIdx > previews.length) {
|
|
4275
|
+
console.error(chalk6.red("Invalid selection."));
|
|
4276
|
+
continue;
|
|
4277
|
+
}
|
|
4278
|
+
selectedVoiceId = previews[choiceIdx - 1].voiceId;
|
|
4279
|
+
}
|
|
4280
|
+
break;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
if (!selectedVoiceId) {
|
|
4284
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4285
|
+
process.exit(0);
|
|
4286
|
+
return;
|
|
4287
|
+
}
|
|
4288
|
+
console.log(chalk6.green(`
|
|
4289
|
+
Publishing: ${chalk6.cyan(selectedVoiceId)}`));
|
|
4290
|
+
const displayName = options.name || await promptInput(" Display name");
|
|
4291
|
+
if (!displayName) {
|
|
4292
|
+
console.error(chalk6.red("Display name is required."));
|
|
4293
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4294
|
+
process.exit(1);
|
|
4295
|
+
return;
|
|
4296
|
+
}
|
|
4297
|
+
const description = options.description || await promptInput(" Description", prompt);
|
|
4298
|
+
const tagsRaw = options.tags || await promptInput(" Tags (comma-separated, optional)");
|
|
4299
|
+
const tags = tagsRaw ? tagsRaw.split(",").map((t) => t.trim()).filter(Boolean) : void 0;
|
|
4300
|
+
console.log(chalk6.cyan("\nPublishing voice..."));
|
|
4301
|
+
const published = await ttsService.publishVoice(selectedVoiceId, {
|
|
4302
|
+
displayName,
|
|
4303
|
+
description,
|
|
4304
|
+
tags
|
|
4305
|
+
});
|
|
4306
|
+
console.log(chalk6.green("\nVoice published!"));
|
|
4307
|
+
console.log(
|
|
4308
|
+
chalk6.white(` Voice ID: ${chalk6.cyan(published.voiceId)}`)
|
|
4309
|
+
);
|
|
4310
|
+
console.log(chalk6.white(` Display Name: ${published.displayName}`));
|
|
4311
|
+
if (published.description) {
|
|
4312
|
+
console.log(chalk6.white(` Description: ${published.description}`));
|
|
4313
|
+
}
|
|
4314
|
+
console.log(
|
|
4315
|
+
chalk6.gray(
|
|
4316
|
+
`
|
|
4317
|
+
Use this voice: inworld tts synthesize "Hello" -v ${published.voiceId}`
|
|
4318
|
+
)
|
|
4319
|
+
);
|
|
4320
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4321
|
+
process.exit(0);
|
|
4322
|
+
} catch (error) {
|
|
4323
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4324
|
+
console.error(chalk6.red("Error designing voice:"));
|
|
4325
|
+
console.error(chalk6.red(error.message || error));
|
|
4326
|
+
process.exit(1);
|
|
4327
|
+
}
|
|
4328
|
+
});
|
|
4329
|
+
|
|
4330
|
+
// src/commands/tts/tts_list_voices_command.ts
|
|
4331
|
+
import chalk7 from "chalk";
|
|
4332
|
+
import { Command as Command22 } from "commander";
|
|
4333
|
+
var listVoicesCommand = new Command22("list-voices").description("List all available voices from the workspace").option("-f, --filter <filter>", 'Filter voices (e.g., "language=en")').option("-j, --json", "Output as JSON").option("-c, --compact", "Compact output (voice IDs only)").action(async (options) => {
|
|
3825
4334
|
try {
|
|
3826
4335
|
const response = await ttsService.listVoices(options.filter);
|
|
3827
4336
|
if (options.json) {
|
|
@@ -3830,15 +4339,15 @@ var listVoicesCommand = new Command20("list-voices").description("List all avail
|
|
|
3830
4339
|
return;
|
|
3831
4340
|
}
|
|
3832
4341
|
if (!response.voices || response.voices.length === 0) {
|
|
3833
|
-
console.log(
|
|
4342
|
+
console.log(chalk7.yellow("No voices found"));
|
|
3834
4343
|
process.exit(0);
|
|
3835
4344
|
return;
|
|
3836
4345
|
}
|
|
3837
4346
|
if (options.compact) {
|
|
3838
|
-
console.log("\n" +
|
|
3839
|
-
console.log(
|
|
4347
|
+
console.log("\n" + chalk7.bold.green("Available Voice IDs:"));
|
|
4348
|
+
console.log(chalk7.gray("\u2500".repeat(50)));
|
|
3840
4349
|
response.voices.sort((a, b) => a.voiceId.localeCompare(b.voiceId)).forEach((voice) => {
|
|
3841
|
-
console.log(` ${
|
|
4350
|
+
console.log(` ${chalk7.cyan("\u2022")} ${voice.voiceId}`);
|
|
3842
4351
|
});
|
|
3843
4352
|
console.log();
|
|
3844
4353
|
process.exit(0);
|
|
@@ -3854,13 +4363,13 @@ var listVoicesCommand = new Command20("list-voices").description("List all avail
|
|
|
3854
4363
|
voicesByLanguage.get(primaryLang).push(voice);
|
|
3855
4364
|
});
|
|
3856
4365
|
const sortedLanguages = Array.from(voicesByLanguage.keys()).sort();
|
|
3857
|
-
console.log("\n" +
|
|
4366
|
+
console.log("\n" + chalk7.bold.green("Available TTS Voices"));
|
|
3858
4367
|
console.log(
|
|
3859
|
-
|
|
4368
|
+
chalk7.gray(
|
|
3860
4369
|
`Found ${response.voices.length} voices across ${sortedLanguages.length} languages`
|
|
3861
4370
|
)
|
|
3862
4371
|
);
|
|
3863
|
-
console.log(
|
|
4372
|
+
console.log(chalk7.gray("\u2500".repeat(80)));
|
|
3864
4373
|
sortedLanguages.forEach((lang, langIndex) => {
|
|
3865
4374
|
const voices = voicesByLanguage.get(lang);
|
|
3866
4375
|
const languageFlags = {
|
|
@@ -3880,19 +4389,19 @@ var listVoicesCommand = new Command20("list-voices").description("List all avail
|
|
|
3880
4389
|
const flag = languageFlags[lang] || "\u{1F310}";
|
|
3881
4390
|
console.log(
|
|
3882
4391
|
`
|
|
3883
|
-
${flag} ${
|
|
4392
|
+
${flag} ${chalk7.bold.yellow(lang.toUpperCase())} ${chalk7.gray(`(${voices.length} voices)`)}`
|
|
3884
4393
|
);
|
|
3885
|
-
console.log(
|
|
4394
|
+
console.log(chalk7.gray("\u2500".repeat(80)));
|
|
3886
4395
|
voices.sort((a, b) => a.voiceId.localeCompare(b.voiceId)).forEach((voice) => {
|
|
3887
|
-
const displayName = voice.displayName && voice.displayName !== voice.voiceId ?
|
|
4396
|
+
const displayName = voice.displayName && voice.displayName !== voice.voiceId ? chalk7.gray(` (${voice.displayName})`) : "";
|
|
3888
4397
|
console.log(
|
|
3889
|
-
` ${
|
|
4398
|
+
` ${chalk7.cyan("\u25B8")} ${chalk7.bold.white(voice.voiceId)}${displayName}`
|
|
3890
4399
|
);
|
|
3891
4400
|
if (voice.description) {
|
|
3892
4401
|
const maxWidth = 76;
|
|
3893
4402
|
const descriptionLines = wrapText(voice.description, maxWidth);
|
|
3894
4403
|
descriptionLines.forEach((line) => {
|
|
3895
|
-
console.log(` ${
|
|
4404
|
+
console.log(` ${chalk7.gray(line)}`);
|
|
3896
4405
|
});
|
|
3897
4406
|
}
|
|
3898
4407
|
});
|
|
@@ -3900,112 +4409,110 @@ ${flag} ${chalk4.bold.yellow(lang.toUpperCase())} ${chalk4.gray(`(${voices.leng
|
|
|
3900
4409
|
console.log();
|
|
3901
4410
|
}
|
|
3902
4411
|
});
|
|
3903
|
-
console.log("\n" +
|
|
3904
|
-
console.log(
|
|
4412
|
+
console.log("\n" + chalk7.gray("\u2500".repeat(80)));
|
|
4413
|
+
console.log(chalk7.gray("Tips:"));
|
|
3905
4414
|
console.log(
|
|
3906
|
-
|
|
4415
|
+
chalk7.gray(' \u2022 Use --filter "language=<code>" to filter by language')
|
|
3907
4416
|
);
|
|
3908
4417
|
console.log(
|
|
3909
|
-
|
|
4418
|
+
chalk7.gray(" \u2022 Use --compact for a simple list of voice IDs")
|
|
3910
4419
|
);
|
|
3911
|
-
console.log(
|
|
4420
|
+
console.log(chalk7.gray(" \u2022 Use --json for machine-readable output"));
|
|
3912
4421
|
console.log(
|
|
3913
|
-
|
|
4422
|
+
chalk7.gray('\nExample: inworld tts list-voices --filter "language=en"')
|
|
3914
4423
|
);
|
|
3915
4424
|
console.log();
|
|
3916
4425
|
} catch (error) {
|
|
3917
|
-
console.error(
|
|
4426
|
+
console.error(chalk7.red("Error listing voices:"), error);
|
|
3918
4427
|
process.exit(1);
|
|
3919
4428
|
}
|
|
3920
4429
|
process.exit(0);
|
|
3921
4430
|
});
|
|
3922
|
-
|
|
4431
|
+
|
|
4432
|
+
// src/commands/tts/tts_synthesize_command.ts
|
|
4433
|
+
import chalk8 from "chalk";
|
|
4434
|
+
import { Command as Command23 } from "commander";
|
|
4435
|
+
import { writeFile as writeFile2 } from "fs/promises";
|
|
4436
|
+
import { resolve as resolve2 } from "path";
|
|
4437
|
+
var synthesizeCommand = new Command23("synthesize").description(
|
|
4438
|
+
'Synthesize text to speech\n\nAudio markups supported in text:\n SSML breaks: <break time="1s" /> or <break time="500ms" />\n Emotions: [happy] [sad] [angry] [surprised] [fearful] [disgusted]\n Delivery: [laughing] [whispering]\n Vocalizations: [breathe] [clear_throat] [cough] [laugh] [sigh] [yawn]\n Pronunciation: /kri\u02D0t/ (IPA in forward slashes)'
|
|
4439
|
+
).argument("<text>", "Text to synthesize (max 2000 characters)").requiredOption(
|
|
3923
4440
|
"-v, --voice <voiceId>",
|
|
3924
4441
|
"Voice ID to use for synthesis",
|
|
3925
4442
|
"Dennis"
|
|
3926
4443
|
).option("-o, --output <file>", "Output audio file path (default: output.mp3)").option(
|
|
3927
4444
|
"-m, --model <model>",
|
|
3928
|
-
"TTS model
|
|
3929
|
-
"inworld-tts-1"
|
|
4445
|
+
"TTS model (inworld-tts-1.5-mini, inworld-tts-1.5-max, or legacy inworld-tts-1, inworld-tts-1-max)",
|
|
4446
|
+
"inworld-tts-1.5-max"
|
|
3930
4447
|
).option(
|
|
3931
4448
|
"-t, --temperature <temp>",
|
|
3932
4449
|
"Temperature (0.0-2.0, default: 1.1)",
|
|
3933
4450
|
"1.1"
|
|
3934
|
-
).option(
|
|
4451
|
+
).option(
|
|
4452
|
+
"--format <format>",
|
|
4453
|
+
"Audio format (MP3, LINEAR16, OGG_OPUS, FLAC, PCM, WAV, ALAW, MULAW). Default: MP3 (LINEAR16 for streaming)"
|
|
4454
|
+
).option("--timestamps <type>", "Include timestamps (WORD or CHARACTER)").option("--normalize <mode>", "Text normalization (on or off)").option("-j, --json", "Output response as JSON (includes base64 audio)").option("-p, --play", "Play the synthesized audio through speakers").option("--stats", "Show request performance statistics").option("--stream", "Use streaming API for synthesis").action(async (text, options) => {
|
|
3935
4455
|
try {
|
|
3936
4456
|
if (text.length > 2e3) {
|
|
3937
|
-
console.error(
|
|
3938
|
-
console.log(
|
|
4457
|
+
console.error(chalk8.red("Error: Text exceeds 2000 character limit"));
|
|
4458
|
+
console.log(chalk8.gray(`Current length: ${text.length} characters`));
|
|
3939
4459
|
process.exit(1);
|
|
3940
4460
|
}
|
|
3941
4461
|
const temperature = parseFloat(options.temperature);
|
|
3942
4462
|
if (isNaN(temperature) || temperature < 0 || temperature > 2) {
|
|
3943
4463
|
console.error(
|
|
3944
|
-
|
|
4464
|
+
chalk8.red("Error: Temperature must be between 0.0 and 2.0")
|
|
3945
4465
|
);
|
|
3946
4466
|
process.exit(1);
|
|
3947
4467
|
}
|
|
3948
|
-
const
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
};
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
4468
|
+
const modelId = resolveModel(options.model);
|
|
4469
|
+
console.log(chalk8.cyan("Synthesizing speech..."));
|
|
4470
|
+
console.log(chalk8.gray(`Voice: ${options.voice}`));
|
|
4471
|
+
console.log(chalk8.gray(`Model: ${options.model}`));
|
|
4472
|
+
console.log(chalk8.gray(`Text length: ${text.length} characters`));
|
|
4473
|
+
const defaultFormat = options.stream ? "LINEAR16" : "MP3";
|
|
4474
|
+
const format = resolveFormat(options.format, defaultFormat);
|
|
4475
|
+
const fileExtension = getFileExtension(format);
|
|
4476
|
+
const outputPath = resolve2(
|
|
4477
|
+
options.output || `${options.voice}_${Date.now()}${fileExtension}`
|
|
4478
|
+
);
|
|
3957
4479
|
const request = {
|
|
3958
4480
|
text,
|
|
3959
4481
|
voiceId: options.voice,
|
|
3960
4482
|
modelId,
|
|
3961
|
-
temperature
|
|
4483
|
+
temperature,
|
|
4484
|
+
audioConfig: { audioEncoding: format }
|
|
3962
4485
|
};
|
|
3963
|
-
if (options.format) {
|
|
3964
|
-
request.audioConfig = {
|
|
3965
|
-
audioEncoding: options.format
|
|
3966
|
-
};
|
|
3967
|
-
}
|
|
3968
4486
|
if (options.timestamps) {
|
|
3969
4487
|
request.timestampType = options.timestamps;
|
|
3970
4488
|
}
|
|
4489
|
+
if (options.normalize) {
|
|
4490
|
+
const mode = options.normalize.toUpperCase();
|
|
4491
|
+
if (mode === "ON" || mode === "OFF") {
|
|
4492
|
+
request.applyTextNormalization = mode;
|
|
4493
|
+
} else {
|
|
4494
|
+
console.error(chalk8.red('Error: --normalize must be "on" or "off"'));
|
|
4495
|
+
process.exit(1);
|
|
4496
|
+
}
|
|
4497
|
+
}
|
|
3971
4498
|
let response;
|
|
3972
4499
|
let audioBuffer;
|
|
3973
|
-
let fileExtension = ".mp3";
|
|
3974
4500
|
if (options.stream) {
|
|
3975
|
-
|
|
3976
|
-
fileExtension = ".wav";
|
|
3977
|
-
if (options.format === "MP3") {
|
|
4501
|
+
if (format === "MP3") {
|
|
3978
4502
|
console.log(
|
|
3979
|
-
|
|
3980
|
-
"\u26A0\uFE0F Warning: MP3 streaming requires special handling."
|
|
3981
|
-
)
|
|
4503
|
+
chalk8.yellow("Warning: MP3 streaming requires special handling.")
|
|
3982
4504
|
);
|
|
3983
4505
|
console.log(
|
|
3984
|
-
|
|
4506
|
+
chalk8.yellow(" Audio chunks may not concatenate perfectly.")
|
|
3985
4507
|
);
|
|
3986
4508
|
console.log(
|
|
3987
|
-
|
|
4509
|
+
chalk8.yellow(
|
|
3988
4510
|
" Consider using LINEAR16 or OGG_OPUS for better streaming."
|
|
3989
4511
|
)
|
|
3990
4512
|
);
|
|
3991
|
-
fileExtension = ".mp3";
|
|
3992
|
-
} else if (options.format === "OGG_OPUS") {
|
|
3993
|
-
fileExtension = ".ogg";
|
|
3994
|
-
} else if (options.format === "ALAW" || options.format === "MULAW") {
|
|
3995
|
-
fileExtension = ".raw";
|
|
3996
|
-
} else if (!options.format || options.format === "LINEAR16") {
|
|
3997
|
-
streamFormat = "LINEAR16";
|
|
3998
|
-
fileExtension = ".wav";
|
|
3999
4513
|
}
|
|
4000
|
-
console.log(
|
|
4001
|
-
console.log(
|
|
4002
|
-
const streamRequest = {
|
|
4003
|
-
...request,
|
|
4004
|
-
audioConfig: {
|
|
4005
|
-
...request.audioConfig,
|
|
4006
|
-
audioEncoding: streamFormat
|
|
4007
|
-
}
|
|
4008
|
-
};
|
|
4514
|
+
console.log(chalk8.cyan("Using streaming synthesis..."));
|
|
4515
|
+
console.log(chalk8.gray(`Format: ${format}${fileExtension}`));
|
|
4009
4516
|
const audioChunks = [];
|
|
4010
4517
|
let timestampInfo = null;
|
|
4011
4518
|
let streamError = null;
|
|
@@ -4022,18 +4529,16 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4022
4529
|
characterEndTimeSeconds: []
|
|
4023
4530
|
};
|
|
4024
4531
|
const streamResult = await ttsService.synthesizeSpeechStream(
|
|
4025
|
-
|
|
4532
|
+
request,
|
|
4026
4533
|
(chunk) => {
|
|
4027
4534
|
chunkCount++;
|
|
4028
4535
|
if (chunk.error) {
|
|
4029
4536
|
streamError = chunk.error;
|
|
4030
|
-
console.error(
|
|
4031
|
-
chalk4.red(`\u274C Stream error: ${chunk.error.message}`)
|
|
4032
|
-
);
|
|
4537
|
+
console.error(chalk8.red(`Stream error: ${chunk.error.message}`));
|
|
4033
4538
|
} else {
|
|
4034
4539
|
if (chunk.audioContent) {
|
|
4035
4540
|
const chunkBuffer = Buffer.from(chunk.audioContent, "base64");
|
|
4036
|
-
if (
|
|
4541
|
+
if (format === "LINEAR16") {
|
|
4037
4542
|
if (!isFirstChunk) {
|
|
4038
4543
|
const headerSize = 44;
|
|
4039
4544
|
if (chunkBuffer.length > headerSize) {
|
|
@@ -4043,17 +4548,13 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4043
4548
|
audioChunks.push(chunkBuffer);
|
|
4044
4549
|
isFirstChunk = false;
|
|
4045
4550
|
}
|
|
4046
|
-
} else if (streamFormat === "OGG_OPUS") {
|
|
4047
|
-
audioChunks.push(chunkBuffer);
|
|
4048
|
-
} else if (streamFormat === "MP3") {
|
|
4049
|
-
audioChunks.push(chunkBuffer);
|
|
4050
4551
|
} else {
|
|
4051
4552
|
audioChunks.push(chunkBuffer);
|
|
4052
4553
|
}
|
|
4053
4554
|
if (!options.json && !options.stats) {
|
|
4054
4555
|
const chunkSizeKB = (chunkBuffer.length / 1024).toFixed(2);
|
|
4055
4556
|
process.stdout.write(
|
|
4056
|
-
|
|
4557
|
+
chalk8.gray(
|
|
4057
4558
|
`\rReceived chunk ${chunkCount} (${chunkSizeKB} KB)...`
|
|
4058
4559
|
)
|
|
4059
4560
|
);
|
|
@@ -4086,7 +4587,6 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4086
4587
|
}
|
|
4087
4588
|
},
|
|
4088
4589
|
options.stats
|
|
4089
|
-
// trackMetrics
|
|
4090
4590
|
);
|
|
4091
4591
|
if (!options.json && !options.stats && chunkCount > 0) {
|
|
4092
4592
|
process.stdout.write("\r" + " ".repeat(50) + "\r");
|
|
@@ -4098,18 +4598,10 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4098
4598
|
if (allWordAlignments.words.length > 0 || allCharacterAlignments.characters.length > 0) {
|
|
4099
4599
|
timestampInfo = {};
|
|
4100
4600
|
if (allWordAlignments.words.length > 0) {
|
|
4101
|
-
timestampInfo.wordAlignment = {
|
|
4102
|
-
words: allWordAlignments.words,
|
|
4103
|
-
wordStartTimeSeconds: allWordAlignments.wordStartTimeSeconds,
|
|
4104
|
-
wordEndTimeSeconds: allWordAlignments.wordEndTimeSeconds
|
|
4105
|
-
};
|
|
4601
|
+
timestampInfo.wordAlignment = { ...allWordAlignments };
|
|
4106
4602
|
}
|
|
4107
4603
|
if (allCharacterAlignments.characters.length > 0) {
|
|
4108
|
-
timestampInfo.characterAlignment = {
|
|
4109
|
-
characters: allCharacterAlignments.characters,
|
|
4110
|
-
characterStartTimeSeconds: allCharacterAlignments.characterStartTimeSeconds,
|
|
4111
|
-
characterEndTimeSeconds: allCharacterAlignments.characterEndTimeSeconds
|
|
4112
|
-
};
|
|
4604
|
+
timestampInfo.characterAlignment = { ...allCharacterAlignments };
|
|
4113
4605
|
}
|
|
4114
4606
|
}
|
|
4115
4607
|
const combinedAudioBase64 = audioBuffer.toString("base64");
|
|
@@ -4131,55 +4623,40 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4131
4623
|
)
|
|
4132
4624
|
);
|
|
4133
4625
|
} else {
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
);
|
|
4137
|
-
await writeFile(outputPath, audioBuffer);
|
|
4138
|
-
console.log(chalk4.green(`\u2705 Audio saved to: ${outputPath}`));
|
|
4626
|
+
await writeFile2(outputPath, audioBuffer);
|
|
4627
|
+
console.log(chalk8.green(`Audio saved to: ${outputPath}`));
|
|
4139
4628
|
console.log(
|
|
4140
|
-
|
|
4629
|
+
chalk8.gray(
|
|
4141
4630
|
`File size: ${(audioBuffer.length / 1024).toFixed(2)} KB`
|
|
4142
4631
|
)
|
|
4143
4632
|
);
|
|
4144
|
-
console.log(
|
|
4633
|
+
console.log(chalk8.gray(`Chunks received: ${chunkCount}`));
|
|
4145
4634
|
if (allWordAlignments.words.length > 0) {
|
|
4146
4635
|
console.log(
|
|
4147
|
-
|
|
4636
|
+
chalk8.gray(
|
|
4148
4637
|
`Word timestamps collected: ${allWordAlignments.words.length}`
|
|
4149
4638
|
)
|
|
4150
4639
|
);
|
|
4151
4640
|
}
|
|
4152
4641
|
if (allCharacterAlignments.characters.length > 0) {
|
|
4153
4642
|
console.log(
|
|
4154
|
-
|
|
4643
|
+
chalk8.gray(
|
|
4155
4644
|
`Character timestamps collected: ${allCharacterAlignments.characters.length}`
|
|
4156
4645
|
)
|
|
4157
4646
|
);
|
|
4158
4647
|
}
|
|
4159
4648
|
}
|
|
4160
4649
|
} else {
|
|
4161
|
-
console.log(
|
|
4162
|
-
if (options.format === "LINEAR16") {
|
|
4163
|
-
fileExtension = ".wav";
|
|
4164
|
-
} else if (options.format === "OGG_OPUS") {
|
|
4165
|
-
fileExtension = ".ogg";
|
|
4166
|
-
} else if (options.format === "ALAW" || options.format === "MULAW") {
|
|
4167
|
-
fileExtension = ".raw";
|
|
4168
|
-
} else {
|
|
4169
|
-
fileExtension = ".mp3";
|
|
4170
|
-
}
|
|
4650
|
+
console.log(chalk8.gray(`Format: ${format}`));
|
|
4171
4651
|
response = options.stats ? await ttsService.synthesizeSpeechWithMetrics(request) : await ttsService.synthesizeSpeech(request);
|
|
4172
4652
|
audioBuffer = Buffer.from(response.audioContent, "base64");
|
|
4173
4653
|
if (options.json) {
|
|
4174
4654
|
console.log(JSON.stringify(response, null, 2));
|
|
4175
4655
|
} else {
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
);
|
|
4179
|
-
await writeFile(outputPath, audioBuffer);
|
|
4180
|
-
console.log(chalk4.green(`\u2705 Audio saved to: ${outputPath}`));
|
|
4656
|
+
await writeFile2(outputPath, audioBuffer);
|
|
4657
|
+
console.log(chalk8.green(`Audio saved to: ${outputPath}`));
|
|
4181
4658
|
console.log(
|
|
4182
|
-
|
|
4659
|
+
chalk8.gray(
|
|
4183
4660
|
`File size: ${(audioBuffer.length / 1024).toFixed(2)} KB`
|
|
4184
4661
|
)
|
|
4185
4662
|
);
|
|
@@ -4189,171 +4666,190 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4189
4666
|
process.exit(0);
|
|
4190
4667
|
return;
|
|
4191
4668
|
}
|
|
4669
|
+
if (response.usage) {
|
|
4670
|
+
console.log(
|
|
4671
|
+
chalk8.gray(
|
|
4672
|
+
`Characters processed: ${response.usage.processedCharactersCount} (model: ${response.usage.modelId})`
|
|
4673
|
+
)
|
|
4674
|
+
);
|
|
4675
|
+
}
|
|
4192
4676
|
if (options.stats && response._metrics) {
|
|
4193
4677
|
const m = response._metrics;
|
|
4194
4678
|
const isStreaming = "timeToFirstChunk" in m;
|
|
4195
4679
|
if (isStreaming) {
|
|
4196
4680
|
const sm = m;
|
|
4681
|
+
console.log("\n" + chalk8.cyan("Streaming Performance Statistics:"));
|
|
4682
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4683
|
+
console.log(chalk8.bold.white("\n Streaming Timeline:"));
|
|
4684
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4197
4685
|
console.log(
|
|
4198
|
-
"
|
|
4686
|
+
chalk8.white(" Time to First Chunk: ") + chalk8.yellow(`${sm.timeToFirstChunk.toFixed(0)} ms`)
|
|
4199
4687
|
);
|
|
4200
|
-
console.log(chalk4.gray("\u2550".repeat(50)));
|
|
4201
|
-
console.log(chalk4.bold.white("\n Streaming Timeline:"));
|
|
4202
|
-
console.log(chalk4.gray(" \u2500".repeat(23)));
|
|
4203
4688
|
console.log(
|
|
4204
|
-
|
|
4689
|
+
chalk8.white(" Total Stream Time: ") + chalk8.bold.yellow(`${sm.totalTime.toFixed(0)} ms`)
|
|
4205
4690
|
);
|
|
4691
|
+
console.log(chalk8.bold.white("\n Chunk Statistics:"));
|
|
4692
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4206
4693
|
console.log(
|
|
4207
|
-
|
|
4208
|
-
);
|
|
4209
|
-
console.log(chalk4.bold.white("\n Chunk Statistics:"));
|
|
4210
|
-
console.log(chalk4.gray(" \u2500".repeat(23)));
|
|
4211
|
-
console.log(
|
|
4212
|
-
chalk4.white(" \u{1F4E6} Chunks Received: ") + chalk4.yellow(`${sm.chunksReceived}`)
|
|
4694
|
+
chalk8.white(" Chunks Received: ") + chalk8.yellow(`${sm.chunksReceived}`)
|
|
4213
4695
|
);
|
|
4214
4696
|
if (sm.errorChunks > 0) {
|
|
4215
4697
|
console.log(
|
|
4216
|
-
|
|
4698
|
+
chalk8.white(" Error Chunks: ") + chalk8.red(`${sm.errorChunks}`)
|
|
4217
4699
|
);
|
|
4218
4700
|
}
|
|
4219
4701
|
if (sm.chunkSizes.length > 0) {
|
|
4220
4702
|
const avgChunkSize = sm.chunkSizes.reduce((a, b) => a + b, 0) / sm.chunkSizes.length;
|
|
4221
|
-
const minChunkSize = Math.min(...sm.chunkSizes);
|
|
4222
|
-
const maxChunkSize = Math.max(...sm.chunkSizes);
|
|
4223
4703
|
console.log(
|
|
4224
|
-
|
|
4704
|
+
chalk8.white(" Avg Chunk Size: ") + chalk8.yellow(`${(avgChunkSize / 1024).toFixed(2)} KB`)
|
|
4225
4705
|
);
|
|
4226
4706
|
console.log(
|
|
4227
|
-
|
|
4228
|
-
`${(
|
|
4707
|
+
chalk8.gray(" Min/Max: ") + chalk8.gray(
|
|
4708
|
+
`${(Math.min(...sm.chunkSizes) / 1024).toFixed(2)} - ${(Math.max(...sm.chunkSizes) / 1024).toFixed(2)} KB`
|
|
4229
4709
|
)
|
|
4230
4710
|
);
|
|
4231
4711
|
}
|
|
4232
4712
|
if (sm.chunkIntervals.length > 0) {
|
|
4233
4713
|
const avgInterval = sm.chunkIntervals.reduce((a, b) => a + b, 0) / sm.chunkIntervals.length;
|
|
4234
|
-
const minInterval = Math.min(...sm.chunkIntervals);
|
|
4235
|
-
const maxInterval = Math.max(...sm.chunkIntervals);
|
|
4236
4714
|
console.log(
|
|
4237
|
-
|
|
4715
|
+
chalk8.white(" Avg Chunk Interval: ") + chalk8.yellow(`${avgInterval.toFixed(0)} ms`)
|
|
4238
4716
|
);
|
|
4239
4717
|
console.log(
|
|
4240
|
-
|
|
4241
|
-
`${
|
|
4718
|
+
chalk8.gray(" Min/Max: ") + chalk8.gray(
|
|
4719
|
+
`${Math.min(...sm.chunkIntervals).toFixed(0)} - ${Math.max(...sm.chunkIntervals).toFixed(0)} ms`
|
|
4242
4720
|
)
|
|
4243
4721
|
);
|
|
4244
4722
|
}
|
|
4245
|
-
console.log(
|
|
4246
|
-
console.log(
|
|
4723
|
+
console.log(chalk8.bold.white("\n Data Transfer:"));
|
|
4724
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4247
4725
|
console.log(
|
|
4248
|
-
|
|
4726
|
+
chalk8.white(" Total Data: ") + chalk8.yellow(`${(sm.totalBytes / 1024).toFixed(2)} KB`)
|
|
4249
4727
|
);
|
|
4250
4728
|
console.log(
|
|
4251
|
-
|
|
4729
|
+
chalk8.white(" Audio File: ") + chalk8.yellow(
|
|
4252
4730
|
`${((audioBuffer?.length || 0) / 1024).toFixed(2)} KB`
|
|
4253
4731
|
)
|
|
4254
4732
|
);
|
|
4255
|
-
console.log(
|
|
4256
|
-
console.log(
|
|
4733
|
+
console.log(chalk8.bold.white("\n Performance Metrics:"));
|
|
4734
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4257
4735
|
const throughputKBps = sm.totalBytes / 1024 / (sm.totalTime / 1e3);
|
|
4258
4736
|
console.log(
|
|
4259
|
-
|
|
4737
|
+
chalk8.white(" Stream Throughput: ") + chalk8.yellow(`${throughputKBps.toFixed(2)} KB/s`)
|
|
4260
4738
|
);
|
|
4261
4739
|
const audioDuration = (audioBuffer?.length || 0) / (128 * 125);
|
|
4262
4740
|
const realTimeRatio = audioDuration / (sm.totalTime / 1e3);
|
|
4263
4741
|
console.log(
|
|
4264
|
-
|
|
4742
|
+
chalk8.white(" Audio Duration: ") + chalk8.yellow(`${audioDuration.toFixed(2)} seconds`)
|
|
4265
4743
|
);
|
|
4266
4744
|
console.log(
|
|
4267
|
-
|
|
4745
|
+
chalk8.white(" Real-time Factor: ") + (realTimeRatio > 1 ? chalk8.green(`${realTimeRatio.toFixed(2)}x faster`) : chalk8.yellow(`${realTimeRatio.toFixed(2)}x`))
|
|
4268
4746
|
);
|
|
4269
4747
|
const streamingEfficiency = (sm.totalTime - sm.timeToFirstChunk) / sm.totalTime * 100;
|
|
4270
4748
|
console.log(
|
|
4271
|
-
|
|
4749
|
+
chalk8.white(" Stream Efficiency: ") + chalk8.yellow(`${streamingEfficiency.toFixed(1)}%`)
|
|
4272
4750
|
);
|
|
4273
|
-
console.log(
|
|
4751
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4274
4752
|
} else {
|
|
4275
|
-
console.log("\n" +
|
|
4276
|
-
console.log(
|
|
4277
|
-
console.log(
|
|
4278
|
-
console.log(
|
|
4753
|
+
console.log("\n" + chalk8.cyan("Performance Statistics:"));
|
|
4754
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4755
|
+
console.log(chalk8.bold.white("\n Network Timing:"));
|
|
4756
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4279
4757
|
console.log(
|
|
4280
|
-
|
|
4758
|
+
chalk8.white(" Time to First Byte: ") + chalk8.yellow(`${m.ttfb.toFixed(0)} ms`)
|
|
4281
4759
|
);
|
|
4282
4760
|
if (m.downloadTime !== void 0) {
|
|
4283
4761
|
console.log(
|
|
4284
|
-
|
|
4762
|
+
chalk8.white(" Content Download: ") + chalk8.yellow(`${m.downloadTime.toFixed(0)} ms`)
|
|
4285
4763
|
);
|
|
4286
4764
|
}
|
|
4287
4765
|
console.log(
|
|
4288
|
-
|
|
4766
|
+
chalk8.white(" Total Time: ") + chalk8.bold.yellow(`${m.totalTime.toFixed(0)} ms`)
|
|
4289
4767
|
);
|
|
4290
|
-
console.log(
|
|
4291
|
-
console.log(
|
|
4768
|
+
console.log(chalk8.bold.white("\n Data Transfer:"));
|
|
4769
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4292
4770
|
if (m.requestSize) {
|
|
4293
4771
|
console.log(
|
|
4294
|
-
|
|
4772
|
+
chalk8.white(" Request Size: ") + chalk8.yellow(`${(m.requestSize / 1024).toFixed(2)} KB`)
|
|
4295
4773
|
);
|
|
4296
4774
|
}
|
|
4297
4775
|
console.log(
|
|
4298
|
-
|
|
4776
|
+
chalk8.white(" Response Size: ") + chalk8.yellow(`${(m.responseSize / 1024).toFixed(2)} KB`)
|
|
4299
4777
|
);
|
|
4300
4778
|
console.log(
|
|
4301
|
-
|
|
4779
|
+
chalk8.white(" Audio File: ") + chalk8.yellow(
|
|
4302
4780
|
`${((audioBuffer?.length || 0) / 1024).toFixed(2)} KB`
|
|
4303
4781
|
)
|
|
4304
4782
|
);
|
|
4305
|
-
console.log(
|
|
4306
|
-
console.log(
|
|
4783
|
+
console.log(chalk8.bold.white("\n Performance Metrics:"));
|
|
4784
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4307
4785
|
const audioDuration = (audioBuffer?.length || 0) / (128 * 125);
|
|
4308
4786
|
const realTimeRatio = audioDuration / (m.totalTime / 1e3);
|
|
4309
|
-
const serverTime = m.ttfb;
|
|
4310
4787
|
console.log(
|
|
4311
|
-
|
|
4788
|
+
chalk8.white(" Server Processing: ") + chalk8.yellow(`${Math.max(0, m.ttfb).toFixed(0)} ms`)
|
|
4312
4789
|
);
|
|
4313
4790
|
console.log(
|
|
4314
|
-
|
|
4791
|
+
chalk8.white(" Audio Duration: ") + chalk8.yellow(`${audioDuration.toFixed(2)} seconds`)
|
|
4315
4792
|
);
|
|
4316
4793
|
console.log(
|
|
4317
|
-
|
|
4794
|
+
chalk8.white(" Real-time Factor: ") + (realTimeRatio > 1 ? chalk8.green(`${realTimeRatio.toFixed(2)}x faster`) : chalk8.yellow(`${realTimeRatio.toFixed(2)}x`))
|
|
4318
4795
|
);
|
|
4319
4796
|
const throughputMbps = (m.responseSize + (audioBuffer?.length || 0)) * 8 / (m.totalTime * 1e3);
|
|
4320
4797
|
console.log(
|
|
4321
|
-
|
|
4798
|
+
chalk8.white(" Throughput: ") + chalk8.yellow(`${throughputMbps.toFixed(2)} Mbps`)
|
|
4322
4799
|
);
|
|
4323
|
-
console.log(
|
|
4800
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4324
4801
|
}
|
|
4325
4802
|
}
|
|
4326
4803
|
if (response.timestampInfo?.wordAlignment) {
|
|
4327
4804
|
const alignment = response.timestampInfo.wordAlignment;
|
|
4328
|
-
console.log("\n" +
|
|
4805
|
+
console.log("\n" + chalk8.cyan("Word Timestamps:"));
|
|
4329
4806
|
alignment.words.forEach((word, i) => {
|
|
4330
4807
|
const start = alignment.wordStartTimeSeconds[i].toFixed(3);
|
|
4331
4808
|
const end = alignment.wordEndTimeSeconds[i].toFixed(3);
|
|
4332
|
-
console.log(
|
|
4809
|
+
console.log(chalk8.gray(` ${start}s - ${end}s: ${word}`));
|
|
4333
4810
|
});
|
|
4811
|
+
if (alignment.phoneticDetails && alignment.phoneticDetails.length > 0) {
|
|
4812
|
+
console.log("\n" + chalk8.cyan("Phonetic Details (IPA + Visemes):"));
|
|
4813
|
+
for (const detail of alignment.phoneticDetails) {
|
|
4814
|
+
const viseme = detail.visemeSymbol ? chalk8.yellow(` [${detail.visemeSymbol}]`) : "";
|
|
4815
|
+
console.log(
|
|
4816
|
+
chalk8.gray(
|
|
4817
|
+
` ${detail.startTimeSeconds.toFixed(3)}s +${detail.durationSeconds.toFixed(3)}s: /${detail.phoneSymbol}/${viseme}`
|
|
4818
|
+
)
|
|
4819
|
+
);
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4334
4822
|
}
|
|
4335
4823
|
if (response.timestampInfo?.characterAlignment) {
|
|
4336
|
-
console.log("\n" +
|
|
4824
|
+
console.log("\n" + chalk8.cyan("Character Timestamps:"));
|
|
4337
4825
|
console.log(
|
|
4338
|
-
|
|
4826
|
+
chalk8.gray(
|
|
4339
4827
|
" (Too detailed to display - use --json to see full data)"
|
|
4340
4828
|
)
|
|
4341
4829
|
);
|
|
4342
4830
|
}
|
|
4831
|
+
if (options.play && audioBuffer) {
|
|
4832
|
+
const played = await playFile(outputPath);
|
|
4833
|
+
if (!played) {
|
|
4834
|
+
console.log(chalk8.gray(`Playback unavailable. Open: ${outputPath}`));
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4343
4837
|
process.exit(0);
|
|
4344
4838
|
} catch (error) {
|
|
4345
|
-
console.error(
|
|
4346
|
-
console.error(
|
|
4839
|
+
console.error(chalk8.red("Error synthesizing speech:"));
|
|
4840
|
+
console.error(chalk8.red(error.message || error));
|
|
4347
4841
|
process.exit(1);
|
|
4348
4842
|
}
|
|
4349
4843
|
});
|
|
4350
|
-
|
|
4844
|
+
|
|
4845
|
+
// src/commands/tts_commands.ts
|
|
4846
|
+
var ttsCommand = new Command24("tts").description("Text-to-speech functionality").addCommand(listVoicesCommand).addCommand(synthesizeCommand).addCommand(cloneCommand).addCommand(designCommand).action(() => {
|
|
4351
4847
|
ttsCommand.help();
|
|
4352
4848
|
});
|
|
4353
4849
|
|
|
4354
4850
|
// src/commands/workspace_command.ts
|
|
4355
|
-
import { Command as
|
|
4356
|
-
var selectWorkspaceCommand = new
|
|
4851
|
+
import { Command as Command25 } from "commander";
|
|
4852
|
+
var selectWorkspaceCommand = new Command25("select").description("Select a workspace for CLI operations").action(async () => {
|
|
4357
4853
|
await requireAuth();
|
|
4358
4854
|
try {
|
|
4359
4855
|
await WorkspaceService.activateWorkspace();
|
|
@@ -4363,7 +4859,35 @@ var selectWorkspaceCommand = new Command21("select").description("Select a works
|
|
|
4363
4859
|
process.exit(1);
|
|
4364
4860
|
}
|
|
4365
4861
|
});
|
|
4366
|
-
var
|
|
4862
|
+
var selectKeyCommand = new Command25("select-key").description("Select an API key for the current workspace").action(async () => {
|
|
4863
|
+
await requireAuth();
|
|
4864
|
+
try {
|
|
4865
|
+
await WorkspaceService.selectApiKey();
|
|
4866
|
+
process.exit(0);
|
|
4867
|
+
} catch (error) {
|
|
4868
|
+
printError(`
|
|
4869
|
+
Failed to select API key: ${error.message || error}`);
|
|
4870
|
+
process.exit(1);
|
|
4871
|
+
}
|
|
4872
|
+
});
|
|
4873
|
+
var addKeyCommand = new Command25("add-key").description(
|
|
4874
|
+
"Create a new API key (read-only by default, --write for read/write)"
|
|
4875
|
+
).option(
|
|
4876
|
+
"-w, --write",
|
|
4877
|
+
"Create with read/write permissions for voices and router"
|
|
4878
|
+
).option("-n, --name <name>", "Display name for the API key").action(async (options) => {
|
|
4879
|
+
await requireAuth();
|
|
4880
|
+
try {
|
|
4881
|
+
const mode = options.write ? "write" : "read";
|
|
4882
|
+
await WorkspaceService.createApiKey(mode, options.name);
|
|
4883
|
+
process.exit(0);
|
|
4884
|
+
} catch (error) {
|
|
4885
|
+
printError(`
|
|
4886
|
+
Failed to create API key: ${error.message || error}`);
|
|
4887
|
+
process.exit(1);
|
|
4888
|
+
}
|
|
4889
|
+
});
|
|
4890
|
+
var workspaceCommand = new Command25("workspace").description("Manage Inworld workspaces").alias("ws").addCommand(selectWorkspaceCommand).addCommand(selectKeyCommand).addCommand(addKeyCommand).action(() => {
|
|
4367
4891
|
workspaceCommand.help();
|
|
4368
4892
|
});
|
|
4369
4893
|
|
|
@@ -4496,7 +5020,7 @@ var InworldCLI = class {
|
|
|
4496
5020
|
program;
|
|
4497
5021
|
currentCommand = null;
|
|
4498
5022
|
constructor() {
|
|
4499
|
-
this.program = new
|
|
5023
|
+
this.program = new Command26();
|
|
4500
5024
|
this.setupProgram();
|
|
4501
5025
|
this.registerCommands();
|
|
4502
5026
|
}
|
|
@@ -4569,7 +5093,7 @@ var InworldCLI = class {
|
|
|
4569
5093
|
})
|
|
4570
5094
|
]);
|
|
4571
5095
|
const timeoutPromise = new Promise(
|
|
4572
|
-
(
|
|
5096
|
+
(resolve3) => setTimeout(resolve3, 1e3)
|
|
4573
5097
|
);
|
|
4574
5098
|
await Promise.race([initPromise, timeoutPromise]);
|
|
4575
5099
|
await this.program.parseAsync(args);
|
|
@@ -4580,7 +5104,7 @@ var InworldCLI = class {
|
|
|
4580
5104
|
analytics.trackCommandResult(this.currentCommand, false, errorMessage);
|
|
4581
5105
|
}
|
|
4582
5106
|
console.error(
|
|
4583
|
-
|
|
5107
|
+
chalk9.red("Error:"),
|
|
4584
5108
|
error instanceof Error ? error.message : String(error)
|
|
4585
5109
|
);
|
|
4586
5110
|
await analytics.flush();
|
|
@@ -4590,6 +5114,6 @@ var InworldCLI = class {
|
|
|
4590
5114
|
};
|
|
4591
5115
|
var cli = new InworldCLI();
|
|
4592
5116
|
cli.run().catch((error) => {
|
|
4593
|
-
console.error(
|
|
5117
|
+
console.error(chalk9.red("Fatal error:"), error);
|
|
4594
5118
|
process.exit(1);
|
|
4595
5119
|
});
|