vocnu 0.1.1 → 0.3.0
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/README.md +23 -5
- package/package.json +2 -2
- package/src/api.js +14 -0
- package/src/cli.js +56 -12
- package/src/mcp.js +67 -11
- package/src/media.js +21 -5
package/README.md
CHANGED
|
@@ -26,17 +26,29 @@ progress and time left, and saves the results next to the file. Options:
|
|
|
26
26
|
| --- | --- |
|
|
27
27
|
| `--output video\|audio\|subtitles` | the video with the voice-over (default for video files), the voice-over audio, or subtitles only |
|
|
28
28
|
| `--from <lang>` | spoken language (detected by default) |
|
|
29
|
-
| `--voice female
|
|
30
|
-
| `--format mp4\|mkv\|mov\|webm\|avi` | video file format (default: the upload's own, else MP4
|
|
29
|
+
| `--voice male\|female\|<voice id>` | a voice type, read by the language's default voice of it (default: male), or a voice from `vocnu voices <lang>` |
|
|
30
|
+
| `--format mp4\|mkv\|mov\|webm\|avi` | video file format, or several separated by commas (`--format mp4,mkv`: one file each, for the price of the dearest); default: the upload's own, else MP4 |
|
|
31
31
|
| `--audio-format m4a\|mp3\|wav\|flac\|ogg` | voice-over audio format |
|
|
32
32
|
| `--burn-subtitles` | subtitles burned into the picture |
|
|
33
|
+
| `--sdh` | SDH subtitles as well (sounds, speaker names and songs for deaf and hard-of-hearing viewers), one more credit per minute; with `--output subtitles` they may be in the spoken language (`--from de --to de`) |
|
|
33
34
|
| `--out <dir>` | where the results go |
|
|
34
35
|
| `--yes` | start without confirming the price |
|
|
35
36
|
| `--no-wait` | start the job and return its id |
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
`vocnu voices <lang>` lists the voices of a language with a link to a short sample of each. Other commands:
|
|
39
|
+
`vocnu credits`, `vocnu languages`, `vocnu jobs`, `vocnu status <job>`, `vocnu download <job>`,
|
|
38
40
|
`vocnu cancel <job>`, `vocnu logout`.
|
|
39
41
|
|
|
42
|
+
## Share the results
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npx vocnu share <job> # prints a link to the job's files
|
|
46
|
+
npx vocnu share <job> --revoke # turns the link off
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Anyone with the link can play the voice-over and download every file of the job in a browser, without an account,
|
|
50
|
+
until you revoke it or the files expire (30 days after the job). Running `share` again prints the same link.
|
|
51
|
+
|
|
40
52
|
## Use Vocnu from Claude (MCP)
|
|
41
53
|
|
|
42
54
|
Claude Code:
|
|
@@ -61,8 +73,10 @@ Claude Desktop (`claude_desktop_config.json`) and other MCP clients:
|
|
|
61
73
|
|
|
62
74
|
Then ask, for example, “Dub ~/Videos/film.mkv into Lithuanian with Vocnu”. The assistant uploads the file
|
|
63
75
|
(`vocnu_upload_media`), tells you the price, starts the job only after you agree (`vocnu_start_job`), checks on it
|
|
64
|
-
(`vocnu_job_status`) and saves the files (`vocnu_download_results`)
|
|
65
|
-
`
|
|
76
|
+
(`vocnu_job_status`) and saves the files (`vocnu_download_results`) or gives you a link to send
|
|
77
|
+
(`vocnu_share_job`, turned off with `vocnu_revoke_share`). Also: `vocnu_languages`, `vocnu_voices` (the voices of a
|
|
78
|
+
language with their samples, for `vocnu_start_job`'s `voice_id`), `vocnu_credits`, `vocnu_list_jobs`,
|
|
79
|
+
`vocnu_cancel_job`.
|
|
66
80
|
|
|
67
81
|
## Development
|
|
68
82
|
|
|
@@ -74,6 +88,10 @@ npm test
|
|
|
74
88
|
The CLI talks to the same product API as the app with a personal API token (backend ADR 0015); `VOCNU_URL` points
|
|
75
89
|
it at another deployment.
|
|
76
90
|
|
|
91
|
+
To release, raise `version` in `package.json` (and `package-lock.json`, `npm version <x.y.z> --no-git-tag-version`),
|
|
92
|
+
push it to master and run the **CLI release** workflow in GitHub Actions. It tests and publishes to npm through npm
|
|
93
|
+
trusted publishing, so no npm token or sign-in is needed; it refuses a version npm already has.
|
|
94
|
+
|
|
77
95
|
## License
|
|
78
96
|
|
|
79
97
|
MIT. The Vocnu service itself has its own [terms](https://vocnu.com/terms); the open source processing engine is
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vocnu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Vocnu from your terminal and your AI assistant: AI voice-over and subtitles for your videos (CLI and MCP server).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
34
|
-
"zod": "^
|
|
34
|
+
"zod": "^4.6.7"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/api.js
CHANGED
|
@@ -63,6 +63,11 @@ export class VocnuApi {
|
|
|
63
63
|
return this.request('GET', '/credits')
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// Vocnu's voice catalog for a language (backend ADR 0026): voices a job may name, each with a short sample.
|
|
67
|
+
async voices(language) {
|
|
68
|
+
return (await this.request('GET', `/voices?language=${encodeURIComponent(language)}`)).voices
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
async source(id) {
|
|
67
72
|
return (await this.request('GET', `/sources/${encodeURIComponent(id)}`)).source
|
|
68
73
|
}
|
|
@@ -83,6 +88,15 @@ export class VocnuApi {
|
|
|
83
88
|
return this.request('POST', '/jobs', { job })
|
|
84
89
|
}
|
|
85
90
|
|
|
91
|
+
// The public link to a finished job's files (backend ADR 0023): created, or the one already on.
|
|
92
|
+
async share(id) {
|
|
93
|
+
return (await this.request('POST', `/jobs/${encodeURIComponent(id)}/share`)).share
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async revokeShare(id) {
|
|
97
|
+
await this.request('DELETE', `/jobs/${encodeURIComponent(id)}/share`)
|
|
98
|
+
}
|
|
99
|
+
|
|
86
100
|
// Uploads a local file and returns its source (status `probing` until Vocnu has analysed it).
|
|
87
101
|
async upload(path, { onProgress = () => {} } = {}) {
|
|
88
102
|
const { size } = await stat(path)
|
package/src/cli.js
CHANGED
|
@@ -8,7 +8,9 @@ import { parseArgs } from 'node:util'
|
|
|
8
8
|
import { VocnuApi, VocnuError } from './api.js'
|
|
9
9
|
import { credentialsPath, DEFAULT_URL, forgetCredentials, loadConfig, saveCredentials } from './config.js'
|
|
10
10
|
import { formatTimeLeft, secondsLeft } from './estimate.js'
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
AUDIO_FORMATS, contentType, defaultVideoFormat, isVideo, OUTPUTS, productsFor, quotedCredits, VIDEO_FORMATS, videoFormatsFrom,
|
|
13
|
+
} from './media.js'
|
|
12
14
|
import { VERSION } from './version.js'
|
|
13
15
|
|
|
14
16
|
const JOB_POLL_MS = 5000
|
|
@@ -20,19 +22,23 @@ Usage:
|
|
|
20
22
|
vocnu logout Forget the saved token
|
|
21
23
|
vocnu credits Your credit balance
|
|
22
24
|
vocnu languages Languages you can translate into
|
|
25
|
+
vocnu voices <lang> Voices of a language, each with a short sample to listen to
|
|
23
26
|
vocnu translate <file> --to <lang> Upload, see the price, translate and download the results
|
|
24
27
|
--output video|audio|subtitles What you get (default: video for a video file, else audio)
|
|
25
28
|
--from <lang> Spoken language (default: detected)
|
|
26
|
-
--voice female
|
|
27
|
-
--format mp4|mkv|mov|webm|avi Video file format (default: the upload's, else mp4)
|
|
29
|
+
--voice male|female|<voice id> A voice type, or a voice from \`vocnu voices\` (default: male)
|
|
30
|
+
--format mp4|mkv|mov|webm|avi Video file format, or several: mp4,mkv (default: the upload's, else mp4)
|
|
28
31
|
--audio-format m4a|mp3|wav|flac|ogg
|
|
29
32
|
--burn-subtitles Subtitles burned into the picture
|
|
33
|
+
--sdh SDH subtitles too: sounds, speaker names and songs, for deaf and
|
|
34
|
+
hard-of-hearing viewers (subtitles may be in the spoken language)
|
|
30
35
|
--out <directory> Where the results go (default: next to the file)
|
|
31
36
|
--yes Start without asking to confirm the price
|
|
32
37
|
--no-wait Start the job and return its id
|
|
33
38
|
vocnu jobs Your recent jobs
|
|
34
39
|
vocnu status <job> Progress, time left and files of a job
|
|
35
40
|
vocnu download <job> [--out <dir>] Save the files of a finished job
|
|
41
|
+
vocnu share <job> [--revoke] A link anyone can open to play and download the files
|
|
36
42
|
vocnu cancel <job> Cancel a job (its credits are refunded)
|
|
37
43
|
vocnu mcp Run the Vocnu MCP server (for Claude and other assistants)
|
|
38
44
|
|
|
@@ -71,6 +77,8 @@ export async function main(argv, { env = process.env, out = process.stdout, err
|
|
|
71
77
|
}
|
|
72
78
|
case 'languages':
|
|
73
79
|
return await languages(api, print)
|
|
80
|
+
case 'voices':
|
|
81
|
+
return await voices(rest, { api, print })
|
|
74
82
|
case 'translate':
|
|
75
83
|
return await translate(rest, { api, err, out, print })
|
|
76
84
|
case 'jobs':
|
|
@@ -79,6 +87,8 @@ export async function main(argv, { env = process.env, out = process.stdout, err
|
|
|
79
87
|
return await status(rest, { api, print })
|
|
80
88
|
case 'download':
|
|
81
89
|
return await download(rest, { api, print })
|
|
90
|
+
case 'share':
|
|
91
|
+
return await share(rest, { api, print })
|
|
82
92
|
case 'cancel': {
|
|
83
93
|
const job = await api.cancel(required(rest[0], 'job id'))
|
|
84
94
|
print(`Cancelled ${job.id}; its credits were refunded.`)
|
|
@@ -129,6 +139,16 @@ async function languages(api, print) {
|
|
|
129
139
|
return 0
|
|
130
140
|
}
|
|
131
141
|
|
|
142
|
+
async function voices(args, { api, print }) {
|
|
143
|
+
const language = required(args[0], 'language code')
|
|
144
|
+
for (const voice of await api.voices(language)) {
|
|
145
|
+
const about = [voice.gender, ...(voice.traits ?? [])].join(', ')
|
|
146
|
+
print(`${voice.id.padEnd(24)} ${voice.name} (${about})${voice.default ? ', default' : ''}`)
|
|
147
|
+
print(`${''.padEnd(24)} ${voice.sample_url}`)
|
|
148
|
+
}
|
|
149
|
+
return 0
|
|
150
|
+
}
|
|
151
|
+
|
|
132
152
|
async function translate(args, { api, err, out, print }) {
|
|
133
153
|
const { positionals, values } = parse(args, {
|
|
134
154
|
'audio-format': { type: 'string' },
|
|
@@ -138,6 +158,7 @@ async function translate(args, { api, err, out, print }) {
|
|
|
138
158
|
'no-wait': { type: 'boolean' },
|
|
139
159
|
out: { type: 'string' },
|
|
140
160
|
output: { type: 'string' },
|
|
161
|
+
sdh: { type: 'boolean' },
|
|
141
162
|
to: { type: 'string' },
|
|
142
163
|
voice: { type: 'string' },
|
|
143
164
|
yes: { type: 'boolean' },
|
|
@@ -145,15 +166,20 @@ async function translate(args, { api, err, out, print }) {
|
|
|
145
166
|
const path = resolve(required(positionals[0], 'file'))
|
|
146
167
|
const target = required(values.to, '--to <language>')
|
|
147
168
|
const output = values.output ?? (isVideo(path) ? 'video' : 'audio')
|
|
148
|
-
const
|
|
169
|
+
const videoFormats = values.format === undefined ? [defaultVideoFormat(path)] : videoFormatsFrom(values.format)
|
|
149
170
|
const audioFormat = values['audio-format'] ?? 'm4a'
|
|
150
|
-
|
|
171
|
+
// A voice type, or a catalog voice of the target language, whose type the API takes.
|
|
172
|
+
const voice = values.voice ?? 'male'
|
|
173
|
+
const voiceType = ['male', 'female'].includes(voice) ? voice : 'male'
|
|
151
174
|
if (!OUTPUTS.includes(output)) throw new UsageError(`--output is one of ${OUTPUTS.join(', ')}.`)
|
|
152
|
-
if (!
|
|
175
|
+
if (!videoFormats) throw new UsageError(`--format is one or more of ${VIDEO_FORMATS.join(', ')}, separated by commas.`)
|
|
153
176
|
if (!AUDIO_FORMATS.includes(audioFormat)) throw new UsageError(`--audio-format is one of ${AUDIO_FORMATS.join(', ')}.`)
|
|
154
|
-
if (
|
|
177
|
+
if (!/^[a-z0-9-]+$/.test(voice)) throw new UsageError('--voice is male, female or a voice id from `vocnu voices <lang>`.')
|
|
155
178
|
if (output === 'video' && !isVideo(path)) throw new UsageError('This is an audio file: use --output audio or subtitles.')
|
|
156
179
|
if (!contentType(path)) throw new UsageError('Vocnu takes video and audio files (MP4, MOV, MKV, WebM, MP3, M4A, WAV...).')
|
|
180
|
+
if (voice !== voiceType && !(await api.voices(target)).some((candidate) => candidate.id === voice)) {
|
|
181
|
+
throw new UsageError(`${target} has no voice ${voice}: see \`vocnu voices ${target}\`.`)
|
|
182
|
+
}
|
|
157
183
|
const { size } = await stat(path)
|
|
158
184
|
|
|
159
185
|
const progress = progressLine(out)
|
|
@@ -163,7 +189,7 @@ async function translate(args, { api, err, out, print }) {
|
|
|
163
189
|
source = await api.waitForSource(source.id)
|
|
164
190
|
progress.done(`Ready: ${source.title ?? basename(path)}, ${formatDuration(source.duration_seconds)}`)
|
|
165
191
|
|
|
166
|
-
const credits = quotedCredits(source.quote, output,
|
|
192
|
+
const credits = quotedCredits(source.quote, output, videoFormats, values['burn-subtitles'], values.sdh)
|
|
167
193
|
const { balance } = await api.credits()
|
|
168
194
|
print(`Price: ${credits} credits (${source.quote.minutes} min). Balance: ${balance} credits.`)
|
|
169
195
|
if (!values.yes) {
|
|
@@ -176,12 +202,14 @@ async function translate(args, { api, err, out, print }) {
|
|
|
176
202
|
}
|
|
177
203
|
const created = await api.createJob({
|
|
178
204
|
audio_format: audioFormat,
|
|
179
|
-
products: productsFor(output, values['burn-subtitles']),
|
|
205
|
+
products: productsFor(output, values['burn-subtitles'], values.sdh === true),
|
|
180
206
|
source_id: source.id,
|
|
181
207
|
source_language: values.from ?? 'auto',
|
|
182
208
|
target_language: target,
|
|
183
|
-
video_format:
|
|
184
|
-
|
|
209
|
+
video_format: videoFormats[0],
|
|
210
|
+
video_formats: videoFormats,
|
|
211
|
+
voice: voiceType,
|
|
212
|
+
...(voice === voiceType ? {} : { voice_id: voice }),
|
|
185
213
|
})
|
|
186
214
|
print(`Started job ${created.job.id} (${created.credit_balance} credits left).`)
|
|
187
215
|
if (values['no-wait']) return 0
|
|
@@ -222,7 +250,9 @@ async function status(args, { api, print }) {
|
|
|
222
250
|
const left = formatTimeLeft(secondsLeft(job))
|
|
223
251
|
if (left) print(left)
|
|
224
252
|
if (job.error) print(`Error: ${job.error.message}`)
|
|
225
|
-
for (const output of job.outputs ?? [])
|
|
253
|
+
for (const output of job.outputs ?? []) {
|
|
254
|
+
print(`File: ${output.kind} (${[output.format, formatSize(output.byte_size ?? 0)].filter(Boolean).join(', ')})`)
|
|
255
|
+
}
|
|
226
256
|
return 0
|
|
227
257
|
}
|
|
228
258
|
|
|
@@ -234,6 +264,20 @@ async function download(args, { api, print }) {
|
|
|
234
264
|
return 0
|
|
235
265
|
}
|
|
236
266
|
|
|
267
|
+
async function share(args, { api, print }) {
|
|
268
|
+
const { positionals, values } = parse(args, { revoke: { type: 'boolean' } })
|
|
269
|
+
const id = required(positionals[0], 'job id')
|
|
270
|
+
if (values.revoke) {
|
|
271
|
+
await api.revokeShare(id)
|
|
272
|
+
print(`The link to ${id} is off; it no longer opens the files.`)
|
|
273
|
+
return 0
|
|
274
|
+
}
|
|
275
|
+
const link = await api.share(id)
|
|
276
|
+
print(link.url)
|
|
277
|
+
print(`Anyone with this link can play and download the files, without an account, until ${link.expires_at?.slice(0, 10) ?? 'the files expire'} or until you run \`vocnu share ${id} --revoke\`.`)
|
|
278
|
+
return 0
|
|
279
|
+
}
|
|
280
|
+
|
|
237
281
|
// One status line that rewrites itself on a terminal and prints each change elsewhere.
|
|
238
282
|
function progressLine(out) {
|
|
239
283
|
let last = ''
|
package/src/mcp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The Vocnu MCP server (stdio): lets Claude and other AI assistants upload a local file, show its price, start a
|
|
2
|
-
// translation, follow it
|
|
3
|
-
// price with the user first. stdout carries the protocol only.
|
|
2
|
+
// translation, follow it, save the results and share them with a link. Spending credits is a separate tool, so the
|
|
3
|
+
// assistant can confirm the price with the user first. stdout carries the protocol only.
|
|
4
4
|
import { homedir } from 'node:os'
|
|
5
5
|
import { join, resolve } from 'node:path'
|
|
6
6
|
|
|
@@ -40,6 +40,17 @@ export function createServer(api, { cwd = process.cwd() } = {}) {
|
|
|
40
40
|
return (catalog.languages ?? []).map((l) => ({ code: l.code, name: l.name, voiceover: l.voiceover !== false }))
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
+
tool('vocnu_voices', {
|
|
44
|
+
annotations: { readOnlyHint: true },
|
|
45
|
+
description: 'Voices Vocnu can read a voice-over with in a language: id, name, type, a few words on how it '
|
|
46
|
+
+ 'sounds, whether it is the default of its type, and a short sample (MP3) the user can listen to. Pass the '
|
|
47
|
+
+ 'chosen id as voice_id to vocnu_start_job.',
|
|
48
|
+
inputSchema: { language: z.string().describe('Language code, e.g. lt, en, de (see vocnu_languages)') },
|
|
49
|
+
title: 'Vocnu voices',
|
|
50
|
+
}, async ({ language }) => (await api.voices(language)).map((v) => ({
|
|
51
|
+
default: v.default, gender: v.gender, id: v.id, name: v.name, sample_url: v.sample_url, traits: v.traits,
|
|
52
|
+
})))
|
|
53
|
+
|
|
43
54
|
tool('vocnu_credits', {
|
|
44
55
|
annotations: { readOnlyHint: true },
|
|
45
56
|
description: "The user's Vocnu credit balance. One credit is about one minute of subtitles; a voice-over costs more.",
|
|
@@ -49,7 +60,8 @@ export function createServer(api, { cwd = process.cwd() } = {}) {
|
|
|
49
60
|
tool('vocnu_upload_media', {
|
|
50
61
|
description: 'Upload a local video or audio file (up to 10 GB) to Vocnu, wait until it is analysed and return its '
|
|
51
62
|
+ 'source_id, length and price in credits for each output. Nothing is charged until vocnu_start_job. '
|
|
52
|
-
+ '
|
|
63
|
+
+ 'captions_only is true for a video nobody speaks in whose story is told in captions burned into the picture: '
|
|
64
|
+
+ 'Vocnu narrates the captions. Large files take minutes to upload.',
|
|
53
65
|
inputSchema: { path: z.string().describe('Path of the video or audio file on this computer') },
|
|
54
66
|
title: 'Upload media to Vocnu',
|
|
55
67
|
}, async ({ path }) => {
|
|
@@ -59,13 +71,20 @@ export function createServer(api, { cwd = process.cwd() } = {}) {
|
|
|
59
71
|
const { balance } = await api.credits()
|
|
60
72
|
return {
|
|
61
73
|
balance,
|
|
74
|
+
captions_only: source.captions_only === true,
|
|
62
75
|
duration_seconds: source.duration_seconds,
|
|
63
76
|
has_video: source.has_video,
|
|
64
77
|
price_credits: {
|
|
65
78
|
audio: source.quote.options.voiceover_audio,
|
|
66
79
|
subtitles: source.quote.options.subtitles,
|
|
67
80
|
video: source.has_video ? quotedCredits(source.quote, 'video', defaultVideoFormat(file)) : null,
|
|
81
|
+
// Several video formats cost the dearest one's price.
|
|
82
|
+
video_by_format: source.has_video
|
|
83
|
+
? Object.fromEntries(VIDEO_FORMATS.map((format) => [format, quotedCredits(source.quote, 'video', format)]))
|
|
84
|
+
: null,
|
|
68
85
|
video_with_burned_subtitles: source.has_video ? source.quote.options.voiceover_video_burned_subtitles : null,
|
|
86
|
+
// What SDH subtitles add to any output (null: not offered).
|
|
87
|
+
sdh_extra: source.quote.options.sdh ?? null,
|
|
69
88
|
},
|
|
70
89
|
source_id: source.id,
|
|
71
90
|
suggested_video_format: isVideo(file) ? defaultVideoFormat(file) : null,
|
|
@@ -77,35 +96,50 @@ export function createServer(api, { cwd = process.cwd() } = {}) {
|
|
|
77
96
|
description: 'Start translating an uploaded file (source_id from vocnu_upload_media). Spends the quoted credits '
|
|
78
97
|
+ '(refunded if the job fails or is cancelled): confirm the price with the user before calling. output "video" '
|
|
79
98
|
+ 'is the video with the voice-over, "audio" the voice-over audio, "subtitles" subtitles only; every output '
|
|
80
|
-
+ 'also includes subtitles.'
|
|
99
|
+
+ 'also includes subtitles. sdh adds SDH subtitles (sound descriptions, speaker names, songs) for deaf and '
|
|
100
|
+
+ 'hard-of-hearing viewers to any output, at the sdh_extra price. Subtitles may be in the spoken language '
|
|
101
|
+
+ '(target_language = source_language, e.g. German SDH of a German film); a voice-over may not, except for a '
|
|
102
|
+
+ 'captions_only upload, whose captions the narrator then reads as written.',
|
|
81
103
|
inputSchema: {
|
|
82
104
|
audio_format: z.enum(AUDIO_FORMATS).optional().describe('Voice-over audio format (default m4a)'),
|
|
83
105
|
burn_subtitles: z.boolean().optional().describe('Burn the subtitles into the picture (video only)'),
|
|
84
106
|
output: z.enum(OUTPUTS),
|
|
107
|
+
sdh: z.boolean().optional()
|
|
108
|
+
.describe('Also SDH subtitles for deaf and hard-of-hearing viewers: sounds, speaker names and songs'),
|
|
85
109
|
source_id: z.string(),
|
|
86
110
|
source_language: z.string().optional().describe('Spoken language code, if known (default: detected)'),
|
|
87
111
|
target_language: z.string().describe('Language code to translate into, e.g. lt, en, de (see vocnu_languages)'),
|
|
88
112
|
video_format: z.enum(VIDEO_FORMATS).optional().describe('Video file format (default mp4)'),
|
|
89
|
-
|
|
113
|
+
video_formats: z.array(z.enum(VIDEO_FORMATS)).min(1).optional()
|
|
114
|
+
.describe('Several video file formats at once, e.g. ["mp4", "mkv"], each its own file (instead of '
|
|
115
|
+
+ 'video_format); they cost what the dearest of them costs'),
|
|
116
|
+
voice: z.enum(['male', 'female']).optional().describe('Voice type (default male), read by the language\'s '
|
|
117
|
+
+ 'default voice of that type'),
|
|
118
|
+
voice_id: z.string().optional().describe('A voice of the target language from vocnu_voices, instead of a type'),
|
|
90
119
|
},
|
|
91
120
|
title: 'Start a Vocnu translation',
|
|
92
121
|
}, async (input) => {
|
|
122
|
+
const chosen = input.video_formats ?? [input.video_format ?? 'mp4']
|
|
123
|
+
const videoFormats = VIDEO_FORMATS.filter((format) => chosen.includes(format))
|
|
93
124
|
const created = await api.createJob({
|
|
94
125
|
audio_format: input.audio_format ?? 'm4a',
|
|
95
|
-
products: productsFor(input.output, input.burn_subtitles),
|
|
126
|
+
products: productsFor(input.output, input.burn_subtitles, input.sdh === true),
|
|
96
127
|
source_id: input.source_id,
|
|
97
128
|
source_language: input.source_language ?? 'auto',
|
|
98
129
|
target_language: input.target_language,
|
|
99
|
-
video_format:
|
|
100
|
-
|
|
130
|
+
video_format: videoFormats[0],
|
|
131
|
+
video_formats: videoFormats,
|
|
132
|
+
voice: input.voice ?? 'male',
|
|
133
|
+
...(input.voice_id ? { voice_id: input.voice_id } : {}),
|
|
101
134
|
})
|
|
102
135
|
return { balance_after: created.credit_balance, job_id: created.job.id, status: created.job.status }
|
|
103
136
|
})
|
|
104
137
|
|
|
105
138
|
tool('vocnu_job_status', {
|
|
106
139
|
annotations: { readOnlyHint: true },
|
|
107
|
-
description: 'Status of a Vocnu job: progress, time left, error, and its files once completed.
|
|
108
|
-
+ '
|
|
140
|
+
description: 'Status of a Vocnu job: progress, time left, error, and its files once completed. A short clip '
|
|
141
|
+
+ 'takes a few minutes and a long video up to about its own length; check again later rather than waiting '
|
|
142
|
+
+ 'in a loop.',
|
|
109
143
|
inputSchema: { job_id: z.string() },
|
|
110
144
|
title: 'Vocnu job status',
|
|
111
145
|
}, async ({ job_id }) => summary(await api.job(job_id)))
|
|
@@ -129,6 +163,27 @@ export function createServer(api, { cwd = process.cwd() } = {}) {
|
|
|
129
163
|
return { files: await api.download(job, where(directory ?? join('.', `vocnu-${job_id}`))) }
|
|
130
164
|
})
|
|
131
165
|
|
|
166
|
+
tool('vocnu_share_job', {
|
|
167
|
+
description: 'A public link to the files of a completed Vocnu job: anyone with it can play the voice-over and '
|
|
168
|
+
+ 'download every file without an account, until the link is revoked or the files expire (expires_at). Returns '
|
|
169
|
+
+ 'the same link again while it is on. Share it only with people the user wants to have the files.',
|
|
170
|
+
inputSchema: { job_id: z.string() },
|
|
171
|
+
title: 'Share Vocnu results',
|
|
172
|
+
}, async ({ job_id }) => {
|
|
173
|
+
const link = await api.share(job_id)
|
|
174
|
+
return { expires_at: link.expires_at, job_id, url: link.url }
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
tool('vocnu_revoke_share', {
|
|
178
|
+
annotations: { destructiveHint: true },
|
|
179
|
+
description: "Turn off a Vocnu job's public link: it stops opening the files at once. Sharing again makes a new link.",
|
|
180
|
+
inputSchema: { job_id: z.string() },
|
|
181
|
+
title: 'Revoke a Vocnu share link',
|
|
182
|
+
}, async ({ job_id }) => {
|
|
183
|
+
await api.revokeShare(job_id)
|
|
184
|
+
return { job_id, revoked: true }
|
|
185
|
+
})
|
|
186
|
+
|
|
132
187
|
tool('vocnu_cancel_job', {
|
|
133
188
|
annotations: { destructiveHint: true },
|
|
134
189
|
description: 'Cancel a queued or running Vocnu job; its credits are refunded.',
|
|
@@ -142,9 +197,10 @@ export function createServer(api, { cwd = process.cwd() } = {}) {
|
|
|
142
197
|
function summary(job) {
|
|
143
198
|
return {
|
|
144
199
|
error: job.error,
|
|
145
|
-
files: (job.outputs ?? []).map((o) => ({ bytes: o.byte_size, kind: o.kind, language: o.language })),
|
|
200
|
+
files: (job.outputs ?? []).map((o) => ({ bytes: o.byte_size, format: o.format, kind: o.kind, language: o.language })),
|
|
146
201
|
job_id: job.id,
|
|
147
202
|
output: job.products?.voiceover_video ? 'video' : job.products?.voiceover_audio ? 'audio' : 'subtitles',
|
|
203
|
+
sdh: job.products?.sdh === true,
|
|
148
204
|
progress_percent: Math.round((job.progress ?? 0) * 100),
|
|
149
205
|
stage: job.stage,
|
|
150
206
|
status: job.status,
|
package/src/media.js
CHANGED
|
@@ -25,20 +25,36 @@ export function defaultVideoFormat(path) {
|
|
|
25
25
|
return VIDEO_FORMATS.includes(format) ? format : 'mp4'
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
//
|
|
29
|
-
|
|
28
|
+
// `mkv` or several formats at once, `mp4,mkv`: each comes as its own file. In the API's order (MP4 first); null for
|
|
29
|
+
// an unknown format or none.
|
|
30
|
+
export function videoFormatsFrom(value) {
|
|
31
|
+
const names = String(value).split(',').map((name) => name.trim().toLowerCase()).filter(Boolean)
|
|
32
|
+
if (names.length === 0 || names.some((name) => !VIDEO_FORMATS.includes(name))) return null
|
|
33
|
+
return VIDEO_FORMATS.filter((format) => names.includes(format))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// API products for an output: a video implies the voice-over audio and subtitles, as the API does. SDH subtitles
|
|
37
|
+
// (sounds, speaker names and songs for deaf and hard-of-hearing viewers) go with any output.
|
|
38
|
+
export function productsFor(output, burnSubtitles = false, sdh = false) {
|
|
30
39
|
return {
|
|
31
40
|
burned_subtitles: output === 'video' && burnSubtitles,
|
|
41
|
+
sdh,
|
|
32
42
|
subtitles: true,
|
|
33
43
|
voiceover_audio: output !== 'subtitles',
|
|
34
44
|
voiceover_video: output === 'video',
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
// Credits the quote asks for this output and video format
|
|
39
|
-
|
|
48
|
+
// Credits the quote asks for this output and video format, or formats: several cost the dearest one's price (a copy
|
|
49
|
+
// of the picture into another container is free, re-encoding it is charged once). SDH adds `options.sdh`.
|
|
50
|
+
export function quotedCredits(quote, output, videoFormats, burnSubtitles = false, sdh = false) {
|
|
51
|
+
return outputCredits(quote, output, videoFormats, burnSubtitles) + (sdh ? quote.options.sdh ?? 0 : 0)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function outputCredits(quote, output, videoFormats, burnSubtitles) {
|
|
40
55
|
if (output === 'subtitles') return quote.options.subtitles
|
|
41
56
|
if (output === 'audio') return quote.options.voiceover_audio
|
|
42
57
|
if (burnSubtitles) return quote.options.voiceover_video_burned_subtitles
|
|
43
|
-
|
|
58
|
+
const prices = [videoFormats].flat().map((format) => quote.video_formats?.[format]?.credits ?? quote.options.voiceover_video)
|
|
59
|
+
return prices.length === 0 ? quote.options.voiceover_video : Math.max(...prices)
|
|
44
60
|
}
|