@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
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { createWriteStream } from 'fs';
|
|
3
|
+
import https from 'https';
|
|
4
|
+
import ora from 'ora';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { TEMPLATES_METADATA_URL } from '@/constants';
|
|
8
|
+
// Default branch for template repositories
|
|
9
|
+
const DEFAULT_TEMPLATE_BRANCH = 'main';
|
|
10
|
+
// Cache expiration time (24 hours in milliseconds)
|
|
11
|
+
const CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1000;
|
|
12
|
+
/**
|
|
13
|
+
* Get cache directory for downloaded templates
|
|
14
|
+
*/
|
|
15
|
+
function getTemplateCachePath() {
|
|
16
|
+
// Use OS temp directory with a subdirectory for inworld templates
|
|
17
|
+
const cacheDir = path.join(os.tmpdir(), 'inworld-cli-templates');
|
|
18
|
+
if (!fs.existsSync(cacheDir)) {
|
|
19
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
return cacheDir;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Fetch templates metadata from the public JSON file
|
|
25
|
+
* Always fetches fresh data (no caching)
|
|
26
|
+
*/
|
|
27
|
+
export async function fetchTemplatesMetadata() {
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(TEMPLATES_METADATA_URL);
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new Error(`Failed to fetch templates metadata: ${response.status}`);
|
|
32
|
+
}
|
|
33
|
+
const data = (await response.json());
|
|
34
|
+
const templates = data.templates || [];
|
|
35
|
+
return templates.filter((template) => template.id === 'llm-to-tts-node');
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extract owner/repo from GitHub URL
|
|
43
|
+
*/
|
|
44
|
+
export function extractRepoFromUrl(githubUrl) {
|
|
45
|
+
const match = githubUrl.match(/github\.com[/:]([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
46
|
+
if (match) {
|
|
47
|
+
return `${match[1]}/${match[2]}`;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse repository string to extract owner and repo
|
|
53
|
+
* Supports formats:
|
|
54
|
+
* - 'owner/repo'
|
|
55
|
+
* - 'https://github.com/owner/repo'
|
|
56
|
+
* - 'https://github.com/owner/repo.git'
|
|
57
|
+
*/
|
|
58
|
+
export function parseRepository(repoString) {
|
|
59
|
+
// Remove .git suffix if present
|
|
60
|
+
let repo = repoString.replace(/\.git$/, '');
|
|
61
|
+
// Extract from URL if it's a full URL
|
|
62
|
+
const urlMatch = repo.match(/github\.com[/:]([^/]+)\/([^/]+)/);
|
|
63
|
+
if (urlMatch) {
|
|
64
|
+
return { owner: urlMatch[1], repo: urlMatch[2] };
|
|
65
|
+
}
|
|
66
|
+
// Assume format is 'owner/repo'
|
|
67
|
+
const parts = repo.split('/');
|
|
68
|
+
if (parts.length !== 2) {
|
|
69
|
+
throw new Error(`Invalid repository format: ${repoString}. Expected 'owner/repo' or GitHub URL.`);
|
|
70
|
+
}
|
|
71
|
+
return { owner: parts[0], repo: parts[1] };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Copy directory recursively
|
|
75
|
+
* Excludes .git directories and other unnecessary files
|
|
76
|
+
*/
|
|
77
|
+
function copyDirectory(src, dest) {
|
|
78
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
79
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
80
|
+
// Files/directories to exclude when copying
|
|
81
|
+
const excludeList = [
|
|
82
|
+
'.git',
|
|
83
|
+
'.github',
|
|
84
|
+
'node_modules',
|
|
85
|
+
'.DS_Store',
|
|
86
|
+
'.cache-metadata.json',
|
|
87
|
+
];
|
|
88
|
+
for (const entry of entries) {
|
|
89
|
+
// Skip excluded files/directories
|
|
90
|
+
if (excludeList.includes(entry.name)) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const srcPath = path.join(src, entry.name);
|
|
94
|
+
const destPath = path.join(dest, entry.name);
|
|
95
|
+
if (entry.isDirectory()) {
|
|
96
|
+
copyDirectory(srcPath, destPath);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
fs.copyFileSync(srcPath, destPath);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Download a template from GitHub
|
|
105
|
+
*/
|
|
106
|
+
async function downloadTemplateFromGitHub(templateName, targetPath, repository, branch) {
|
|
107
|
+
// Repository must be provided from metadata
|
|
108
|
+
if (!repository) {
|
|
109
|
+
throw new Error(`No repository found for template '${templateName}'. Please ensure the template exists in the templates metadata.`);
|
|
110
|
+
}
|
|
111
|
+
const { owner, repo } = parseRepository(repository);
|
|
112
|
+
const repoBranch = branch || DEFAULT_TEMPLATE_BRANCH;
|
|
113
|
+
const spinner = ora(`Downloading template '${templateName}' from ${owner}/${repo}...`).start();
|
|
114
|
+
try {
|
|
115
|
+
// Create a temporary directory for downloading
|
|
116
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'inworld-template-'));
|
|
117
|
+
const zipPath = path.join(tempDir, `${templateName}.zip`);
|
|
118
|
+
// GitHub API URL to download a directory as zip
|
|
119
|
+
// Format: https://api.github.com/repos/{owner}/{repo}/zipball/{branch}
|
|
120
|
+
const archiveUrl = `https://api.github.com/repos/${owner}/${repo}/zipball/${repoBranch}`;
|
|
121
|
+
spinner.text = `Downloading repository archive from ${owner}/${repo}...`;
|
|
122
|
+
// Download the entire repo as zip
|
|
123
|
+
await new Promise((resolve, reject) => {
|
|
124
|
+
https
|
|
125
|
+
.get(archiveUrl, { headers: { 'User-Agent': 'inworld-cli' } }, (res) => {
|
|
126
|
+
if (res.statusCode === 302 && res.headers.location) {
|
|
127
|
+
// Follow redirect
|
|
128
|
+
https
|
|
129
|
+
.get(res.headers.location, { headers: { 'User-Agent': 'inworld-cli' } }, (redirectRes) => {
|
|
130
|
+
if (redirectRes.statusCode !== 200) {
|
|
131
|
+
reject(new Error(`Failed to download: ${redirectRes.statusCode}`));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const fileStream = createWriteStream(zipPath);
|
|
135
|
+
redirectRes.pipe(fileStream);
|
|
136
|
+
fileStream.on('finish', resolve);
|
|
137
|
+
fileStream.on('error', reject);
|
|
138
|
+
})
|
|
139
|
+
.on('error', reject);
|
|
140
|
+
}
|
|
141
|
+
else if (res.statusCode === 200) {
|
|
142
|
+
const fileStream = createWriteStream(zipPath);
|
|
143
|
+
res.pipe(fileStream);
|
|
144
|
+
fileStream.on('finish', resolve);
|
|
145
|
+
fileStream.on('error', reject);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
reject(new Error(`Failed to download: ${res.statusCode}`));
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
.on('error', reject);
|
|
152
|
+
});
|
|
153
|
+
spinner.text = `Extracting template files...`;
|
|
154
|
+
// Extract the zip file
|
|
155
|
+
// @ts-ignore - adm-zip doesn't have type definitions
|
|
156
|
+
const AdmZip = (await import('adm-zip')).default;
|
|
157
|
+
const zip = new AdmZip(zipPath);
|
|
158
|
+
const extractPath = path.join(tempDir, 'extracted');
|
|
159
|
+
zip.extractAllTo(extractPath, true);
|
|
160
|
+
// Find the extracted directory (GitHub adds a commit hash prefix)
|
|
161
|
+
const extractedDirs = fs.readdirSync(extractPath);
|
|
162
|
+
if (extractedDirs.length === 0) {
|
|
163
|
+
throw new Error('Failed to extract template from GitHub');
|
|
164
|
+
}
|
|
165
|
+
const extractedRoot = path.join(extractPath, extractedDirs[0]);
|
|
166
|
+
// The repository is a complete app, so copy everything from the root
|
|
167
|
+
// Verify the repository has content
|
|
168
|
+
const entries = fs.readdirSync(extractedRoot);
|
|
169
|
+
if (entries.length === 0) {
|
|
170
|
+
throw new Error(`Repository ${owner}/${repo} appears to be empty.`);
|
|
171
|
+
}
|
|
172
|
+
spinner.text = `Copying application files...`;
|
|
173
|
+
// Create target directory
|
|
174
|
+
fs.mkdirSync(targetPath, { recursive: true });
|
|
175
|
+
// Copy entire repository contents to target path
|
|
176
|
+
copyDirectory(extractedRoot, targetPath);
|
|
177
|
+
// Cleanup
|
|
178
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
179
|
+
spinner.stop();
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
spinner.fail(`Failed to download template: ${error instanceof Error ? error.message : String(error)}`);
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Check if cached template is still valid (not expired)
|
|
188
|
+
*/
|
|
189
|
+
function isCacheValid(templateDir) {
|
|
190
|
+
if (!fs.existsSync(templateDir)) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const cacheMetadataPath = path.join(templateDir, '.cache-metadata.json');
|
|
194
|
+
// If no metadata file, check directory modification time
|
|
195
|
+
if (!fs.existsSync(cacheMetadataPath)) {
|
|
196
|
+
try {
|
|
197
|
+
const stats = fs.statSync(templateDir);
|
|
198
|
+
const age = Date.now() - stats.mtimeMs;
|
|
199
|
+
return age < CACHE_EXPIRATION_MS;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Check metadata file for expiration
|
|
206
|
+
try {
|
|
207
|
+
const metadata = JSON.parse(fs.readFileSync(cacheMetadataPath, 'utf-8'));
|
|
208
|
+
const age = Date.now() - metadata.cachedAt;
|
|
209
|
+
return age < CACHE_EXPIRATION_MS;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check if template is cached and valid (without downloading)
|
|
217
|
+
*/
|
|
218
|
+
export function isTemplateCached(templateId, forceRefresh) {
|
|
219
|
+
if (forceRefresh) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
const cachePath = getTemplateCachePath();
|
|
223
|
+
const templateDir = path.join(cachePath, templateId);
|
|
224
|
+
if (!fs.existsSync(templateDir)) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const files = fs.readdirSync(templateDir);
|
|
228
|
+
return files.length > 0 && isCacheValid(templateDir);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Write cache metadata file
|
|
232
|
+
*/
|
|
233
|
+
function writeCacheMetadata(templateDir) {
|
|
234
|
+
const cacheMetadataPath = path.join(templateDir, '.cache-metadata.json');
|
|
235
|
+
const metadata = {
|
|
236
|
+
cachedAt: Date.now(),
|
|
237
|
+
};
|
|
238
|
+
fs.writeFileSync(cacheMetadataPath, JSON.stringify(metadata, null, 2));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Download and cache a template from GitHub
|
|
242
|
+
* Returns the path to the cached template directory and whether it was from cache
|
|
243
|
+
*/
|
|
244
|
+
export async function downloadAndCacheTemplate(templateId, repository, branch, forceRefresh = false) {
|
|
245
|
+
const cachePath = getTemplateCachePath();
|
|
246
|
+
// Use template ID for cache directory (normalized, consistent)
|
|
247
|
+
const templateDir = path.join(cachePath, templateId);
|
|
248
|
+
// Check if already cached and not expired (unless force refresh)
|
|
249
|
+
if (!forceRefresh && fs.existsSync(templateDir)) {
|
|
250
|
+
const files = fs.readdirSync(templateDir);
|
|
251
|
+
if (files.length > 0 && isCacheValid(templateDir)) {
|
|
252
|
+
return { path: templateDir, fromCache: true };
|
|
253
|
+
}
|
|
254
|
+
// Cache expired or invalid, remove it
|
|
255
|
+
if (fs.existsSync(templateDir)) {
|
|
256
|
+
fs.rmSync(templateDir, { recursive: true, force: true });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Download from GitHub - repository must be provided from metadata
|
|
260
|
+
if (!repository) {
|
|
261
|
+
throw new Error(`No repository found for template '${templateId}'. Please ensure the template exists in the templates metadata.`);
|
|
262
|
+
}
|
|
263
|
+
await downloadTemplateFromGitHub(templateId, templateDir, repository, branch);
|
|
264
|
+
if (!fs.existsSync(templateDir)) {
|
|
265
|
+
throw new Error(`Template '${templateId}' was not downloaded correctly.`);
|
|
266
|
+
}
|
|
267
|
+
// Write cache metadata
|
|
268
|
+
writeCacheMetadata(templateDir);
|
|
269
|
+
return { path: templateDir, fromCache: false };
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get available templates from metadata URL
|
|
273
|
+
*/
|
|
274
|
+
export async function getAvailableTemplatesWithMetadata() {
|
|
275
|
+
const templates = [];
|
|
276
|
+
try {
|
|
277
|
+
// Fetch templates from metadata URL
|
|
278
|
+
const metadataTemplates = await fetchTemplatesMetadata();
|
|
279
|
+
for (const template of metadataTemplates) {
|
|
280
|
+
const templateInfo = {
|
|
281
|
+
directory: template.id || template.name,
|
|
282
|
+
metadata: template,
|
|
283
|
+
};
|
|
284
|
+
templates.push(templateInfo);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
return templates.filter((template) => template.metadata.id === 'llm-to-tts-node');
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Copy directory recursively (exported for use in command)
|
|
294
|
+
* Excludes .git directories and other unnecessary files
|
|
295
|
+
*/
|
|
296
|
+
export function copyTemplateDirectory(src, dest) {
|
|
297
|
+
copyDirectory(src, dest);
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=template_service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template_service.js","sourceRoot":"","sources":["../../../src/services/template_service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACv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AChC,MAAM,IAAI,KAAK,CAAC,aAAa,UAAU,iCAAiC,CAAC,CAAC;IAC5E,CAAC;IAED,uBAAuB;IACvB,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAEhC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iCAAiC;IAGrD,MAAM,SAAS,GAAmB,EAAE,CAAC;IAErC,IAAI,CAAC;QACH,oCAAoC;QACpC,MAAM,iBAAiB,GAAG,MAAM,sBAAsB,EAAE,CAAC;QAEzD,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;YACzC,MAAM,YAAY,GAAiB;gBACjC,SAAS,EAAE,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI;gBACvC,QAAQ,EAAE,QAAQ;aACnB,CAAC;YAEF,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,iBAAiB,CACzD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW,EAAE,IAAY;IAC7D,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Audio encoding options for TTS
|
|
3
|
-
* @see {@link https://
|
|
3
|
+
* @see {@link https://docs.inworld.ai/docs/tts/tts/}
|
|
4
4
|
*/
|
|
5
5
|
export declare enum AudioEncoding {
|
|
6
6
|
LINEAR16 = "LINEAR16",
|
|
7
7
|
MP3 = "MP3",
|
|
8
8
|
OGG_OPUS = "OGG_OPUS",
|
|
9
9
|
ALAW = "ALAW",
|
|
10
|
-
MULAW = "MULAW"
|
|
10
|
+
MULAW = "MULAW",
|
|
11
|
+
FLAC = "FLAC",
|
|
12
|
+
PCM = "PCM",
|
|
13
|
+
WAV = "WAV"
|
|
11
14
|
}
|
|
12
15
|
/**
|
|
13
16
|
* Available TTS models
|
|
14
|
-
* @see {@link https://
|
|
17
|
+
* @see {@link https://docs.inworld.ai/docs/tts/tts/}
|
|
15
18
|
*/
|
|
16
19
|
export declare enum TTSModel {
|
|
20
|
+
/** @deprecated Use INWORLD_TTS_1_5_MINI or INWORLD_TTS_1_5_MAX instead */
|
|
17
21
|
INWORLD_TTS_1 = "inworld-tts-1",
|
|
18
|
-
|
|
22
|
+
/** @deprecated Use INWORLD_TTS_1_5_MINI or INWORLD_TTS_1_5_MAX instead */
|
|
23
|
+
INWORLD_TTS_1_MAX = "inworld-tts-1-max",
|
|
24
|
+
INWORLD_TTS_1_5_MINI = "inworld-tts-1.5-mini",
|
|
25
|
+
INWORLD_TTS_1_5_MAX = "inworld-tts-1.5-max"
|
|
19
26
|
}
|
|
27
|
+
/** Legacy model IDs that trigger deprecation warnings */
|
|
28
|
+
export declare const LEGACY_MODELS: Set<TTSModel>;
|
|
20
29
|
/**
|
|
21
30
|
* Timestamp types for alignment data
|
|
22
31
|
*/
|
|
@@ -25,9 +34,15 @@ export declare enum TimestampType {
|
|
|
25
34
|
WORD = "WORD",
|
|
26
35
|
CHARACTER = "CHARACTER"
|
|
27
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Text normalization options
|
|
39
|
+
*/
|
|
40
|
+
export declare enum TextNormalization {
|
|
41
|
+
ON = "ON",
|
|
42
|
+
OFF = "OFF"
|
|
43
|
+
}
|
|
28
44
|
/**
|
|
29
45
|
* Audio configuration for TTS synthesis
|
|
30
|
-
* @description Configurations to use when synthesizing speech
|
|
31
46
|
*/
|
|
32
47
|
export interface AudioConfig {
|
|
33
48
|
/** The desired output format of the synthesized audio. Defaults to MP3. */
|
|
@@ -36,14 +51,11 @@ export interface AudioConfig {
|
|
|
36
51
|
bitRate?: number;
|
|
37
52
|
/** The synthesis sample rate (in hertz) for this audio. Accepts values within the range [8000, 48000]. Default is 48,000. */
|
|
38
53
|
sampleRateHertz?: number;
|
|
39
|
-
/**
|
|
40
|
-
pitch?: number;
|
|
41
|
-
/** Speaking rate/speed, in the range [0.5, 1.5]. Not supported for streaming. Default is 1.0. */
|
|
54
|
+
/** Speaking rate/speed, in the range [0.5, 1.5]. Default is 1.0. */
|
|
42
55
|
speakingRate?: number;
|
|
43
56
|
}
|
|
44
57
|
/**
|
|
45
58
|
* Request options for synthesizing speech
|
|
46
|
-
* @description Parameters for the TTS synthesis request
|
|
47
59
|
*/
|
|
48
60
|
export interface SynthesizeSpeechRequest {
|
|
49
61
|
/** The text to be synthesized into speech. Maximum input of 2,000 characters. */
|
|
@@ -54,14 +66,28 @@ export interface SynthesizeSpeechRequest {
|
|
|
54
66
|
modelId: TTSModel;
|
|
55
67
|
/** Audio configuration options. */
|
|
56
68
|
audioConfig?: AudioConfig;
|
|
57
|
-
/** Determines the degree of randomness when sampling audio tokens. Range
|
|
69
|
+
/** Determines the degree of randomness when sampling audio tokens. Range (0, 2]. Default is 1.1. */
|
|
58
70
|
temperature?: number;
|
|
59
71
|
/** Controls timestamp metadata returned with the audio. */
|
|
60
72
|
timestampType?: TimestampType;
|
|
73
|
+
/** Controls text normalization. */
|
|
74
|
+
applyTextNormalization?: TextNormalization;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Phonetic detail for a word (TTS 1.5+)
|
|
78
|
+
*/
|
|
79
|
+
export interface PhoneticDetail {
|
|
80
|
+
/** IPA phoneme symbol */
|
|
81
|
+
phoneSymbol: string;
|
|
82
|
+
/** Start time in seconds */
|
|
83
|
+
startTimeSeconds: number;
|
|
84
|
+
/** Duration in seconds */
|
|
85
|
+
durationSeconds: number;
|
|
86
|
+
/** Viseme symbol for lip-sync (e.g., 'aei', 'bmp', 'fv') */
|
|
87
|
+
visemeSymbol?: string;
|
|
61
88
|
}
|
|
62
89
|
/**
|
|
63
90
|
* Word alignment information
|
|
64
|
-
* @description Word-level timestamp alignment data
|
|
65
91
|
*/
|
|
66
92
|
export interface WordAlignment {
|
|
67
93
|
/** Aligned words in order. */
|
|
@@ -70,10 +96,11 @@ export interface WordAlignment {
|
|
|
70
96
|
wordStartTimeSeconds: number[];
|
|
71
97
|
/** End time for each word in seconds from the beginning of the audio. */
|
|
72
98
|
wordEndTimeSeconds: number[];
|
|
99
|
+
/** Phoneme-level details including IPA and visemes (TTS 1.5+). */
|
|
100
|
+
phoneticDetails?: PhoneticDetail[];
|
|
73
101
|
}
|
|
74
102
|
/**
|
|
75
103
|
* Character alignment information
|
|
76
|
-
* @description Character-level timestamp alignment data
|
|
77
104
|
*/
|
|
78
105
|
export interface CharacterAlignment {
|
|
79
106
|
/** Aligned characters (including punctuation and spaces) in order. */
|
|
@@ -85,7 +112,6 @@ export interface CharacterAlignment {
|
|
|
85
112
|
}
|
|
86
113
|
/**
|
|
87
114
|
* Timestamp information for synthesized speech
|
|
88
|
-
* @description Alignment information present when alignment is enabled
|
|
89
115
|
*/
|
|
90
116
|
export interface TimestampInfo {
|
|
91
117
|
/** Word-level alignment when timestampType is WORD. */
|
|
@@ -93,19 +119,28 @@ export interface TimestampInfo {
|
|
|
93
119
|
/** Character-level alignment when timestampType is CHARACTER. */
|
|
94
120
|
characterAlignment?: CharacterAlignment;
|
|
95
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Usage information from the API response
|
|
124
|
+
*/
|
|
125
|
+
export interface Usage {
|
|
126
|
+
/** Number of characters processed for billing */
|
|
127
|
+
processedCharactersCount: number;
|
|
128
|
+
/** Model used for synthesis */
|
|
129
|
+
modelId: string;
|
|
130
|
+
}
|
|
96
131
|
/**
|
|
97
132
|
* Response from synthesizing speech
|
|
98
|
-
* @description The response containing the synthesized audio and optional timestamp information
|
|
99
133
|
*/
|
|
100
134
|
export interface SynthesizeSpeechResponse {
|
|
101
135
|
/** The audio data bytes encoded in the format specified in the request. Base64 encoded. */
|
|
102
136
|
audioContent: string;
|
|
103
137
|
/** Timestamp alignment information (present when alignment is enabled). */
|
|
104
138
|
timestampInfo?: TimestampInfo;
|
|
139
|
+
/** Usage/billing information. */
|
|
140
|
+
usage?: Usage;
|
|
105
141
|
}
|
|
106
142
|
/**
|
|
107
143
|
* Voice information
|
|
108
|
-
* @description Information about an available TTS voice
|
|
109
144
|
*/
|
|
110
145
|
export interface Voice {
|
|
111
146
|
/** The language(s) of the original voice audio. */
|
|
@@ -119,7 +154,6 @@ export interface Voice {
|
|
|
119
154
|
}
|
|
120
155
|
/**
|
|
121
156
|
* Response from listing voices
|
|
122
|
-
* @description The response containing the list of available voices
|
|
123
157
|
*/
|
|
124
158
|
export interface ListVoicesResponse {
|
|
125
159
|
/** The list of voices. */
|
|
@@ -127,7 +161,6 @@ export interface ListVoicesResponse {
|
|
|
127
161
|
}
|
|
128
162
|
/**
|
|
129
163
|
* Error response from the API
|
|
130
|
-
* @description Standard error response format
|
|
131
164
|
*/
|
|
132
165
|
export interface ErrorResponse {
|
|
133
166
|
/** The error code, as specified by gRPC status codes. */
|
|
@@ -139,7 +172,6 @@ export interface ErrorResponse {
|
|
|
139
172
|
}
|
|
140
173
|
/**
|
|
141
174
|
* Request performance metrics
|
|
142
|
-
* @description Timing and size metrics for API requests
|
|
143
175
|
*/
|
|
144
176
|
export interface RequestMetrics {
|
|
145
177
|
/** Time when the request started (ms) */
|
|
@@ -153,7 +185,6 @@ export interface RequestMetrics {
|
|
|
153
185
|
}
|
|
154
186
|
/**
|
|
155
187
|
* Streaming performance metrics
|
|
156
|
-
* @description Timing and chunk metrics for streaming requests
|
|
157
188
|
*/
|
|
158
189
|
export interface StreamingMetrics {
|
|
159
190
|
/** Time when the request started (ms) */
|
|
@@ -173,65 +204,104 @@ export interface StreamingMetrics {
|
|
|
173
204
|
/** Error chunks received */
|
|
174
205
|
errorChunks: number;
|
|
175
206
|
}
|
|
207
|
+
export interface VoiceSample {
|
|
208
|
+
/** Base64-encoded audio data */
|
|
209
|
+
audioData: string;
|
|
210
|
+
/** Transcription of the audio */
|
|
211
|
+
transcription?: string;
|
|
212
|
+
}
|
|
213
|
+
export interface CloneVoiceRequest {
|
|
214
|
+
displayName: string;
|
|
215
|
+
langCode: string;
|
|
216
|
+
voiceSamples: VoiceSample[];
|
|
217
|
+
description?: string;
|
|
218
|
+
tags?: string[];
|
|
219
|
+
audioProcessingConfig?: {
|
|
220
|
+
removeBackgroundNoise?: boolean;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export interface ValidatedSample {
|
|
224
|
+
audioData: string;
|
|
225
|
+
errors: string[];
|
|
226
|
+
langCode: string;
|
|
227
|
+
transcription: string;
|
|
228
|
+
warnings: string[];
|
|
229
|
+
}
|
|
230
|
+
export interface ClonedVoice {
|
|
231
|
+
voiceId: string;
|
|
232
|
+
langCode: string;
|
|
233
|
+
displayName: string;
|
|
234
|
+
description: string;
|
|
235
|
+
tags: string[];
|
|
236
|
+
name: string;
|
|
237
|
+
source: string;
|
|
238
|
+
}
|
|
239
|
+
export interface CloneVoiceResponse {
|
|
240
|
+
audioSamplesValidated: ValidatedSample[];
|
|
241
|
+
voice: ClonedVoice;
|
|
242
|
+
}
|
|
243
|
+
export interface DesignVoiceRequest {
|
|
244
|
+
langCode: string;
|
|
245
|
+
designPrompt: string;
|
|
246
|
+
previewText: string;
|
|
247
|
+
voiceDesignConfig?: {
|
|
248
|
+
numberOfSamples?: number;
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
export interface PreviewVoice {
|
|
252
|
+
voiceId: string;
|
|
253
|
+
previewText: string;
|
|
254
|
+
previewAudio: string;
|
|
255
|
+
}
|
|
256
|
+
export interface DesignVoiceResponse {
|
|
257
|
+
langCode: string;
|
|
258
|
+
previewVoices: PreviewVoice[];
|
|
259
|
+
}
|
|
260
|
+
export interface PublishVoiceRequest {
|
|
261
|
+
displayName: string;
|
|
262
|
+
description: string;
|
|
263
|
+
tags?: string[];
|
|
264
|
+
}
|
|
265
|
+
export interface PublishedVoice {
|
|
266
|
+
voiceId: string;
|
|
267
|
+
langCode: string;
|
|
268
|
+
displayName: string;
|
|
269
|
+
description: string;
|
|
270
|
+
tags: string[];
|
|
271
|
+
name: string;
|
|
272
|
+
source: string;
|
|
273
|
+
}
|
|
274
|
+
export interface GeneratePreviewTextResponse {
|
|
275
|
+
previewText: string;
|
|
276
|
+
}
|
|
176
277
|
/**
|
|
177
278
|
* TTS Service for interacting with Inworld's Text-to-Speech API
|
|
178
|
-
* @description Provides methods for listing voices and synthesizing speech
|
|
179
279
|
*/
|
|
180
280
|
export declare class TTSService {
|
|
181
281
|
private apiKey;
|
|
182
|
-
/**
|
|
183
|
-
* Ensures the API key is available
|
|
184
|
-
* @private
|
|
185
|
-
*/
|
|
186
282
|
private ensureApiKey;
|
|
283
|
+
/** Builds the API base URL from the platform URL */
|
|
284
|
+
private get apiBaseUrl();
|
|
187
285
|
/**
|
|
188
286
|
* Makes an authenticated request to the Inworld API
|
|
189
|
-
* @private
|
|
190
287
|
*/
|
|
191
288
|
private makeRequest;
|
|
192
289
|
/**
|
|
193
290
|
* Lists all available voices based on the provided filter
|
|
194
|
-
* @param filter - Optional filter expression (e.g., "language=en")
|
|
195
|
-
* @returns Promise resolving to the list of available voices
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* const ttsService = new TTSService();
|
|
199
|
-
* const voices = await ttsService.listVoices('language=en');
|
|
200
|
-
* console.log(voices.voices);
|
|
201
|
-
* ```
|
|
202
291
|
*/
|
|
203
292
|
listVoices(filter?: string): Promise<ListVoicesResponse>;
|
|
204
293
|
/**
|
|
205
294
|
* Synthesizes speech from text
|
|
206
|
-
* @param request - The synthesis request parameters
|
|
207
|
-
* @returns Promise resolving to the synthesized audio data and optional timestamp information
|
|
208
|
-
* @example
|
|
209
|
-
* ```typescript
|
|
210
|
-
* const ttsService = new TTSService();
|
|
211
|
-
* const result = await ttsService.synthesizeSpeech({
|
|
212
|
-
* text: 'Hello, world!',
|
|
213
|
-
* voiceId: 'Dennis',
|
|
214
|
-
* modelId: TTSModel.INWORLD_TTS_1,
|
|
215
|
-
* timestampType: TimestampType.WORD,
|
|
216
|
-
* });
|
|
217
|
-
* // result.audioContent is base64 encoded audio data
|
|
218
|
-
* ```
|
|
219
295
|
*/
|
|
220
296
|
synthesizeSpeech(request: SynthesizeSpeechRequest): Promise<SynthesizeSpeechResponse>;
|
|
221
297
|
/**
|
|
222
298
|
* Synthesizes speech from text with performance metrics
|
|
223
|
-
* @param request - The synthesis request parameters
|
|
224
|
-
* @returns Promise resolving to the synthesized audio data with metrics
|
|
225
299
|
*/
|
|
226
300
|
synthesizeSpeechWithMetrics(request: SynthesizeSpeechRequest): Promise<SynthesizeSpeechResponse & {
|
|
227
301
|
_metrics?: RequestMetrics;
|
|
228
302
|
}>;
|
|
229
303
|
/**
|
|
230
304
|
* Synthesizes speech using streaming API
|
|
231
|
-
* @param request - The synthesis request parameters
|
|
232
|
-
* @param onChunk - Callback for each audio chunk received
|
|
233
|
-
* @param trackMetrics - Whether to track streaming metrics
|
|
234
|
-
* @returns Promise resolving when stream completes, with optional metrics
|
|
235
305
|
*/
|
|
236
306
|
synthesizeSpeechStream(request: SynthesizeSpeechRequest, onChunk: (chunk: {
|
|
237
307
|
audioContent?: string;
|
|
@@ -242,31 +312,28 @@ export declare class TTSService {
|
|
|
242
312
|
}>;
|
|
243
313
|
/**
|
|
244
314
|
* Helper method to synthesize speech with simple parameters
|
|
245
|
-
* @param text - The text to synthesize
|
|
246
|
-
* @param voiceId - The voice ID to use
|
|
247
|
-
* @param modelId - The model ID to use (defaults to inworld-tts-1-max)
|
|
248
|
-
* @returns Promise resolving to the synthesized audio data
|
|
249
|
-
* @example
|
|
250
|
-
* ```typescript
|
|
251
|
-
* const ttsService = new TTSService();
|
|
252
|
-
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
253
|
-
* const audioBuffer = Buffer.from(result.audioContent, 'base64');
|
|
254
|
-
* ```
|
|
255
315
|
*/
|
|
256
316
|
synthesize(text: string, voiceId: string, modelId?: TTSModel): Promise<SynthesizeSpeechResponse>;
|
|
257
317
|
/**
|
|
258
318
|
* Saves synthesized audio to a file
|
|
259
|
-
* @param audioContent - Base64 encoded audio content
|
|
260
|
-
* @param filepath - Path where the audio file should be saved
|
|
261
|
-
* @returns Promise that resolves when the file is written
|
|
262
|
-
* @example
|
|
263
|
-
* ```typescript
|
|
264
|
-
* const ttsService = new TTSService();
|
|
265
|
-
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
266
|
-
* await ttsService.saveAudioToFile(result.audioContent, 'output.mp3');
|
|
267
|
-
* ```
|
|
268
319
|
*/
|
|
269
320
|
saveAudioToFile(audioContent: string, filepath: string): Promise<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Clones a voice from audio samples
|
|
323
|
+
*/
|
|
324
|
+
cloneVoice(request: CloneVoiceRequest): Promise<CloneVoiceResponse>;
|
|
325
|
+
/**
|
|
326
|
+
* Generates preview text for voice design
|
|
327
|
+
*/
|
|
328
|
+
generatePreviewText(workspace: string, description: string, langCode: string): Promise<GeneratePreviewTextResponse>;
|
|
329
|
+
/**
|
|
330
|
+
* Designs a voice from a text description
|
|
331
|
+
*/
|
|
332
|
+
designVoice(request: DesignVoiceRequest): Promise<DesignVoiceResponse>;
|
|
333
|
+
/**
|
|
334
|
+
* Publishes a designed voice preview to the voice library
|
|
335
|
+
*/
|
|
336
|
+
publishVoice(voiceId: string, request: PublishVoiceRequest): Promise<PublishedVoice>;
|
|
270
337
|
}
|
|
271
338
|
export declare const ttsService: TTSService;
|
|
272
339
|
export declare const synthesizeSpeech: (text: string, voice: string) => Promise<SynthesizeSpeechResponse>;
|