@vocalstack/payload 0.4.0 → 0.5.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 CHANGED
@@ -37,7 +37,7 @@ Then run `payload generate:importmap`. The plugin adds fields to the targeted co
37
37
  - `POST /api/{collection}/:id/vocalstack/transcribe`, `POST …/vocalstack/stop`, `GET …/vocalstack/status` and `GET …/vocalstack/stream` (live progress as Server-Sent Events).
38
38
  - **Translations and readings**, under every finished transcript: translate it into up to 10 of VocalStack's 100 languages (VocalStack's limit per recording), and have each translation read aloud where VocalStack has a voice for it. VocalStack picks the voices; a toggle on each transcript chooses between **synthetic** voices and the speakers' own **cloned** voices (where they have one, made with their permission), saved as `voices`. One click in the admin does both; the server carries on until it is done, with no one watching. Saved in the `vocalstack` group as:
39
39
  - `translations`: `{ [lang]: { translatedAt, sentences, pending?, error?, requestedAt? } }`, the transcript's sentences (same ids and times) translated. `pending` while the server is still translating it.
40
- - `speech`: `{ [lang]: { voice, state, error, durationS, requestedAt, renderedAt, sentences, audio } }`. `state` is `translating` (waiting for its translation), `queued`, `running`, `failed` or `sealed`; once sealed, `sentences` are the translation in the reading's own timing, with words, for a read-along player, and `audio` is the MP3 kept in your storage.
40
+ - `speech`: `{ [lang]: { voice, cast, readIn, state, error, durationS, requestedAt, renderedAt, sentences, audio } }`. `state` is `translating` (waiting for its translation), `queued`, `running`, `failed` or `sealed`; once sealed, `sentences` are the translation in the reading's own timing, with words, for a read-along player, and `audio` is the MP3 kept in your storage.
41
41
  - `POST …/vocalstack/voices { voices: 'synthetic' | 'cloned' }`, `POST …/vocalstack/request { langs, speak? }` (translate, and read aloud unless `speak: false`; carried on by the server), `POST …/vocalstack/translate { langs }` (one step; answers `more: true` when it stopped for time), `DELETE …/vocalstack/translate?lang=`, `POST …/vocalstack/speak { langs }`, `GET …/vocalstack/speak`, and the public `GET …/vocalstack/audio?lang=`, which redirects to the reading's MP3 (or, with no `lang` or the spoken one, the recording's audio) for anyone who may read the document.
42
42
  - **Languages for listeners** (opt in with `listeners`): visitors pick any language VocalStack offers, and it is made for them and kept for everyone after. `GET /api/vocalstack/languages` is public, `POST …/vocalstack/listen { lang }` asks for a language and `GET …/vocalstack/listen?lang=` says where it stands; see below.
43
43
  - **Voices** (opt in with `voices`): documents of a collection of people get a sidebar panel to clone that person's voice from a minute of a recording they speak in, or from an uploaded sample, with their permission. Kept in a hidden `vocalstackVoice` group (`voiceId`, `state`: `none`/`training`/`ready`/`failed`, `progress`, `error`, `sampleS`, `consentAt`, `createdAt`), with `GET`/`POST`/`DELETE /api/{collection}/:id/vocalstack/voice`, `…/voice/sources` and `…/voice/preview`.
@@ -59,6 +59,7 @@ Then run `payload generate:importmap`. The plugin adds fields to the targeted co
59
59
  | `voices` | none | Collections of people who get a cloned voice; see below. |
60
60
  | `readings` | `{ slug: 'vocalstack-readings' }` | The upload collection finished readings are kept in, added by the plugin; `overrides: (collection) => collection` adjusts it. `false` streams readings from VocalStack instead. See below for bringing your own. |
61
61
  | `listeners` | off | `true`, or `{ languages?, speak?, access?, perHour? }`: let visitors ask for a transcript in their language; see below. |
62
+ | `voiceMode` | the transcript's toggle | `({ collection, doc, req, row }) => 'synthetic' \| 'cloned' \| undefined`: the site decides how transcripts are read aloud, and the toggle is hidden. See below. |
62
63
 
63
64
  ### Audio that isn't an upload
64
65
 
@@ -100,7 +101,16 @@ vocalstackPlugin({
100
101
 
101
102
  A sample from a recording can only come from the recordings `recordings` returns for that document: cloning, and hearing a stretch first (`GET /:id/vocalstack/voice/clip`), refuse any other.
102
103
 
103
- Cloning needs at least 30 seconds of the person speaking alone (a minute is better, at most two), and the editor confirms they have the person's permission. From a recording, the editor clicks where the stretch starts and hears it before cloning; the plugin takes it from VocalStack. An uploaded sample is sent through your server, so on hosts that cap request bodies (Vercel: 4.5 MB) keep it to a minute or two of MP3 or M4A. Training takes a few minutes; the panel follows it. Deleting the voice deletes it in VocalStack too. Readings don't name a voice: VocalStack picks it for each recording.
104
+ Cloning needs at least 30 seconds of the person speaking alone (a minute is better, at most two), and the editor confirms they have the person's permission. From a recording, the editor clicks where the stretch starts and hears it before cloning; the plugin takes it from VocalStack. An uploaded sample is sent through your server, so on hosts that cap request bodies (Vercel: 4.5 MB) keep it to a minute or two of MP3 or M4A. Training takes a few minutes; the panel follows it. Deleting the voice deletes it in VocalStack too. Voices are kept as library voices: when VocalStack transcribes a new recording, it checks the speakers against them first.
105
+
106
+ A cloned voice only ever reads words its own speaker said. With `cloned` (from the toggle, or from `voiceMode` once a person has a voice), each speaker VocalStack has matched to a clone is read in it: the speaker it was made from, or one VocalStack recognised as the same person when it transcribed the recording. Everyone else is read in a stock voice. VocalStack doesn't always recognise a speaker, and recordings transcribed before the voice existed are not matched, so a reading reports what it got as `speech[lang].readIn`: `cloned`, `synthetic`, or `mixed`.
107
+
108
+ ```ts
109
+ voiceMode: async ({ doc, req }) => {
110
+ const speaker = await req.payload.findByID({ collection: 'speakers', id: doc.speaker, depth: 0, req })
111
+ return speaker.vocalstackVoice?.state === 'ready' ? 'cloned' : 'synthetic'
112
+ }
113
+ ```
104
114
 
105
115
  ### Translations and readings
106
116
 
package/dist/api.d.ts CHANGED
@@ -72,7 +72,7 @@ export type VoiceOption = {
72
72
  quality: number;
73
73
  ready?: boolean;
74
74
  };
75
- /** A recording's spoken translation in one language and voice (`voiceKey` is `''` for the default voice). */
75
+ /** A recording's spoken translation in one language, in one cast of voices. */
76
76
  export type VoiceTrack = {
77
77
  /** Seconds each sentence's clip lasts, by sentence id. */
78
78
  clipDur?: Record<string, number>;
@@ -82,12 +82,19 @@ export type VoiceTrack = {
82
82
  lang: string;
83
83
  /** `queued`, `running`, `failed`, `sealed` (the track is ready), or `clips` (sentences only). */
84
84
  state: string;
85
- /** `synthetic` or `cloned` (the API's voice modes); older APIs answer a voice name here, or nothing. */
85
+ /** The voice it was asked in by name, if it was. */
86
86
  voice?: null | string;
87
+ /** The track's key: `''` for the default voice on older tracks, else its cast (`cast:0=M1;1=F1`). */
87
88
  voiceKey: string;
89
+ /** What it is read in: `cloned`, `synthetic`, or `mixed` (some speakers had no usable clone). Null on older tracks. */
90
+ voices?: 'cloned' | 'mixed' | 'synthetic' | null;
88
91
  /** Each sentence's words as [start, end] within its clip, by sentence id. */
89
92
  wordTimes?: Record<string, [number, number][]>;
90
93
  };
94
+ /** How a reading is voiced: in the speakers' cloned voices where VocalStack has them, or in stock voices. */
95
+ export type SpeakAs = {
96
+ cloned: boolean;
97
+ };
91
98
  export type Language = {
92
99
  code: string;
93
100
  name: string;
@@ -107,6 +114,7 @@ export declare class VocalStackAPIError extends Error {
107
114
  constructor(status: number, code: string, message: string);
108
115
  }
109
116
  export declare class VocalStackAPI {
117
+ #private;
110
118
  readonly sdk: VocalStack;
111
119
  constructor(apiKey: string, baseURL?: string);
112
120
  me(): Promise<Record<string, unknown>>;
@@ -136,13 +144,13 @@ export declare class VocalStackAPI {
136
144
  translations: Record<string, string>;
137
145
  }>;
138
146
  /**
139
- * Render spoken translations, one job per language, in the recording's default cast: VocalStack
140
- * picks each speaker's voice. `cloned` lets it use speakers' own cloned voices (each made with
141
- * that speaker's permission); otherwise it reads in stock voices.
147
+ * Read translations aloud, one job per language. `cloned` reads each speaker in their own cloned
148
+ * voice where VocalStack can use one (a clone of that speaker, made with their permission, or a
149
+ * saved voice VocalStack recognised as them) and in a stock voice otherwise; `synthetic` reads
150
+ * everyone in stock voices. Each track says which it got (`voices`: cloned, synthetic or mixed).
151
+ * A clone only ever reads words its own speaker said.
142
152
  */
143
- speak(recordingId: string, langs: string[], opts?: {
144
- cloned?: boolean;
145
- }): Promise<VoiceTrack[]>;
153
+ speak(recordingId: string, langs: string[], as?: SpeakAs): Promise<VoiceTrack[]>;
146
154
  voiceTracks(recordingId: string, lang?: string): Promise<VoiceTrack[]>;
147
155
  /** An address of the recording's audio, or of a spoken translation's, that works for an hour or so. */
148
156
  audioURL(recordingId: string, opts: {
@@ -161,7 +169,8 @@ export declare class VocalStackAPI {
161
169
  }, idempotencyKey: string): Promise<Voice>;
162
170
  /**
163
171
  * Clone a speaker's voice from stretches of a transcribed recording (5–60 s in all). `draft`
164
- * makes a trial voice to hear first; keep it with `keepVoice`, or delete it.
172
+ * makes a trial voice to hear first; keep it with `keepVoice`, or delete it. A library voice:
173
+ * VocalStack looks for library voices first when it works out who speaks in a new recording.
165
174
  */
166
175
  voiceFromSpeaker(opts: {
167
176
  draft: boolean;
@@ -173,7 +182,7 @@ export declare class VocalStackAPI {
173
182
  }[];
174
183
  speaker: number;
175
184
  }, idempotencyKey: string): Promise<Voice>;
176
- /** Keep a trial voice, as `name`, with the speaker's permission. */
185
+ /** Keep a trial voice, as `name`, with the speaker's permission, in the library. */
177
186
  keepVoice(id: string, name: string): Promise<Voice>;
178
187
  deleteVoice(id: string): Promise<unknown>;
179
188
  availableVoices(lang: string, recordingId?: string): Promise<{
package/dist/api.js CHANGED
@@ -52,7 +52,11 @@ const call = async (run) => {
52
52
  };
53
53
  export class VocalStackAPI {
54
54
  sdk;
55
+ #apiKey;
56
+ #baseURL;
55
57
  constructor(apiKey, baseURL = DEFAULT_API_URL) {
58
+ this.#apiKey = apiKey;
59
+ this.#baseURL = baseURL.replace(/\/+$/, '');
56
60
  this.sdk = new VocalStack({
57
61
  apiKey,
58
62
  baseUrl: baseURL,
@@ -102,21 +106,27 @@ export class VocalStackAPI {
102
106
  return call(() => this.sdk.recordings.translation(recordingId, lang, sentenceIds));
103
107
  }
104
108
  /**
105
- * Render spoken translations, one job per language, in the recording's default cast: VocalStack
106
- * picks each speaker's voice. `cloned` lets it use speakers' own cloned voices (each made with
107
- * that speaker's permission); otherwise it reads in stock voices.
109
+ * Read translations aloud, one job per language. `cloned` reads each speaker in their own cloned
110
+ * voice where VocalStack can use one (a clone of that speaker, made with their permission, or a
111
+ * saved voice VocalStack recognised as them) and in a stock voice otherwise; `synthetic` reads
112
+ * everyone in stock voices. Each track says which it got (`voices`: cloned, synthetic or mixed).
113
+ * A clone only ever reads words its own speaker said.
108
114
  */
109
- async speak(recordingId, langs, opts = {}) {
110
- const render = (body) => call(() => this.sdk.recordings.renderVoice(recordingId, body));
111
- try {
112
- return await render({ langs, voice: opts.cloned ? 'cloned' : 'synthetic' });
113
- }
114
- catch (err) {
115
- // An API from before `voice: 'synthetic' | 'cloned'` takes it for a voice id: there, consent turns clones on.
116
- if (!(err instanceof VocalStackAPIError && err.status === 400 && /no voice '(cloned|synthetic)'/.test(err.message)))
117
- throw err;
118
- return render({ consent: opts.cloned ? true : undefined, langs });
119
- }
115
+ async speak(recordingId, langs, as = { cloned: false }) {
116
+ const ask = { langs, voices: as.cloned ? 'cloned' : 'synthetic' };
117
+ // Straight to the API: the SDK on npm (2.0.0-alpha.1) leaves `voices` out of the body.
118
+ const res = await call(() => fetch(`${this.#baseURL}/v1/recordings/${encodeURIComponent(recordingId)}/voice`, {
119
+ body: JSON.stringify(ask),
120
+ headers: { authorization: `Bearer ${this.#apiKey}`, 'content-type': 'application/json' },
121
+ method: 'POST',
122
+ signal: AbortSignal.timeout(30_000),
123
+ }));
124
+ const body = (await res.json().catch(() => null));
125
+ if (res.ok)
126
+ return body;
127
+ if (res.status === 502 || res.status === 503 || res.status === 504)
128
+ throw new VocalStackAPIError(503, 'unavailable', UNAVAILABLE);
129
+ throw new VocalStackAPIError(res.status, body?.code ?? 'http_error', body?.message ?? `VocalStack answered ${res.status}`);
120
130
  }
121
131
  voiceTracks(recordingId, lang) {
122
132
  return call(() => this.sdk.recordings.voice(recordingId, lang));
@@ -143,14 +153,15 @@ export class VocalStackAPI {
143
153
  }
144
154
  /**
145
155
  * Clone a speaker's voice from stretches of a transcribed recording (5–60 s in all). `draft`
146
- * makes a trial voice to hear first; keep it with `keepVoice`, or delete it.
156
+ * makes a trial voice to hear first; keep it with `keepVoice`, or delete it. A library voice:
157
+ * VocalStack looks for library voices first when it works out who speaks in a new recording.
147
158
  */
148
159
  voiceFromSpeaker(opts, idempotencyKey) {
149
- return call(() => this.sdk.voices.createFromSpeaker({ ...opts, consent: true, library: false }, { idempotencyKey }));
160
+ return call(() => this.sdk.voices.createFromSpeaker({ ...opts, consent: true, library: true }, { idempotencyKey }));
150
161
  }
151
- /** Keep a trial voice, as `name`, with the speaker's permission. */
162
+ /** Keep a trial voice, as `name`, with the speaker's permission, in the library. */
152
163
  keepVoice(id, name) {
153
- return call(() => this.sdk.voices.update(id, { consent: true, draft: false, name }));
164
+ return call(() => this.sdk.voices.update(id, { consent: true, draft: false, library: true, name }));
154
165
  }
155
166
  deleteVoice(id) {
156
167
  return call(() => this.sdk.voices.delete(id));
@@ -169,7 +169,7 @@ export const SpeechField = ({ field, path = '' }) => {
169
169
  ? `${t.sentences.length} of ${total} sentences translated`
170
170
  : t
171
171
  ? `${t.sentences.length} sentences translated`
172
- : 'Not translated' })] }), _jsxs("div", { style: { display: 'grid', gap: 6 }, children: [t?.pending ? (_jsxs(_Fragment, { children: [_jsx(Progress, { done: t.sentences.length, label: TRANSLATING, since: t.requestedAt ?? undefined, total: total }), s?.state === 'translating' && _jsx("span", { className: "vs-speech-muted", children: "Read aloud once translated." }), t.error && _jsxs("span", { className: "vs-speech-muted", children: [t.error, " Trying again shortly."] })] })) : busy ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), busy] })) : s?.state === 'queued' || s?.state === 'running' ? (_jsx(Progress, { done: s.done ?? 0, label: s.state === 'queued' ? 'Waiting to be read aloud…' : 'Being read aloud…', since: s.requestedAt, total: t?.sentences.length ?? 0 })) : s?.state === 'sealed' ? (_jsx("audio", { controls: true, preload: "none", src: `${serverURL}${api}${base}/audio${withQuery({ lang, v: s.renderedAt ?? '' })}` }, s.renderedAt ?? '')) : t?.error && !t.sentences.length ? (_jsxs("p", { className: "vs-speech-error", children: ["Translating failed: ", t.error] })) : s?.state === 'translating' ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), "Waiting for VocalStack to read it aloud\u2026"] })) : s?.state === 'failed' ? (_jsxs("p", { className: "vs-speech-error", children: ["Reading failed: ", s.error ?? 'no reason given'] })) : !canSpeak.has(lang) ? (_jsxs("span", { className: "vs-speech-muted", children: ["VocalStack cannot read ", names.get(lang) ?? lang, " aloud yet."] })) : null, canSpeak.has(lang) && !busy && !t?.pending && (!s || s.state === 'failed' || (s.state === 'sealed' && (s.cast ?? 'synthetic') !== voices)) && (_jsx("div", { children: _jsx(Button, { buttonStyle: "secondary", margin: false, onClick: () => speak([lang]), size: "small", children: !s ? 'Read aloud' : s.state === 'failed' ? 'Try again' : `Read again in ${voices} voices` }) }))] }), _jsx(Button, { buttonStyle: "secondary", disabled: Boolean(busy), margin: false, onClick: () => remove(lang), size: "small", children: "Remove" })] }, lang));
172
+ : 'Not translated' })] }), _jsxs("div", { style: { display: 'grid', gap: 6 }, children: [t?.pending ? (_jsxs(_Fragment, { children: [_jsx(Progress, { done: t.sentences.length, label: TRANSLATING, since: t.requestedAt ?? undefined, total: total }), s?.state === 'translating' && _jsx("span", { className: "vs-speech-muted", children: "Read aloud once translated." }), t.error && _jsxs("span", { className: "vs-speech-muted", children: [t.error, " Trying again shortly."] })] })) : busy ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), busy] })) : s?.state === 'queued' || s?.state === 'running' ? (_jsx(Progress, { done: s.done ?? 0, label: s.state === 'queued' ? 'Waiting to be read aloud…' : 'Being read aloud…', since: s.requestedAt, total: t?.sentences.length ?? 0 })) : s?.state === 'sealed' ? (_jsxs(_Fragment, { children: [_jsx("audio", { controls: true, preload: "none", src: `${serverURL}${api}${base}/audio${withQuery({ lang, v: s.renderedAt ?? '' })}` }, s.renderedAt ?? ''), s.cast === 'cloned' && s.readIn === 'mixed' && (_jsx("span", { className: "vs-speech-muted", children: "Some speakers are read in stock voices: they have no cloned voice to use." })), s.cast === 'cloned' && s.readIn === 'synthetic' && (_jsx("span", { className: "vs-speech-muted", children: "Read in stock voices: no speaker has a cloned voice to use." }))] })) : t?.error && !t.sentences.length ? (_jsxs("p", { className: "vs-speech-error", children: ["Translating failed: ", t.error] })) : s?.state === 'translating' ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), "Waiting for VocalStack to read it aloud\u2026"] })) : s?.state === 'failed' ? (_jsxs("p", { className: "vs-speech-error", children: ["Reading failed: ", s.error ?? 'no reason given'] })) : !canSpeak.has(lang) ? (_jsxs("span", { className: "vs-speech-muted", children: ["VocalStack cannot read ", names.get(lang) ?? lang, " aloud yet."] })) : null, canSpeak.has(lang) && !busy && !t?.pending && (!s || s.state === 'failed' || (s.state === 'sealed' && (s.cast ?? 'synthetic') !== voices)) && (_jsx("div", { children: _jsx(Button, { buttonStyle: "secondary", margin: false, onClick: () => speak([lang]), size: "small", children: !s ? 'Read aloud' : s.state === 'failed' ? 'Try again' : `Read again in ${voices} voices` }) }))] }), _jsx(Button, { buttonStyle: "secondary", disabled: Boolean(busy), margin: false, onClick: () => remove(lang), size: "small", children: "Remove" })] }, lang));
173
173
  }), _jsx(AddLanguages, { busy: Object.keys(working).length > 0, canSpeak: canSpeak, exclude: new Set([...shown, ...(spoken ? [spoken] : [])]), langs: langs, left: LANGUAGE_LIMIT - shown.filter((l) => l !== spoken).length, onAdd: (list, speakToo) => run(list, 'Starting…', () => request(list, speakToo)) }), error && _jsx("p", { className: "vs-speech-error", children: error })] }));
174
174
  };
175
175
  /** Work under way: the share of sentences done, counted up as each step is saved, and the time it has taken. */
@@ -132,9 +132,9 @@ const readingName = (target, lang, voice) => `${(target.name || target.fileName.
132
132
  async function keepReading(req, api, slug, target, lang, speech) {
133
133
  if (speech.audio || speech.state !== 'sealed')
134
134
  return speech;
135
- // The reading's key as VocalStack knows it: its mode (`synthetic` | `cloned`) on newer APIs,
136
- // its cast key on older ones. A key the API does not take (400) is followed by the next.
137
- const keys = [...new Set([speech.voice ?? undefined, speech.cast ?? undefined, undefined])];
135
+ // The reading's track by its key (`cast:…`), or the default voice for older (`''`) tracks.
136
+ // A key the API does not take (400) is followed by the default.
137
+ const keys = [...new Set([speech.voice || undefined, undefined])];
138
138
  let res;
139
139
  for (const voice of keys) {
140
140
  const src = await api.audioURL(target.data.recordingId, { kind: 'voice', lang, voice });
@@ -192,8 +192,8 @@ function trackFor(tracks, lang, speech) {
192
192
  return mine.find((t) => keyOf(t) === speech.voice);
193
193
  return mine.find((t) => keyOf(t) && t.state !== 'clips') ?? mine.find((t) => t.voiceKey === '');
194
194
  }
195
- /** A track's key: its mode (`synthetic` | `cloned`) where the API names one, else its cast key. */
196
- const keyOf = (t) => (t.voice === 'synthetic' || t.voice === 'cloned' ? t.voice : t.voiceKey);
195
+ /** A track's key, which `/audio?voice=` takes: its cast (`cast:0=M1;1=F1`), or `''` on older tracks. */
196
+ const keyOf = (t) => t.voiceKey;
197
197
  /** The key VocalStack gave the reading it just took on for `lang`. */
198
198
  const askedKey = (tracks, lang) => {
199
199
  const mine = (Array.isArray(tracks) ? tracks : []).filter((t) => t.lang === lang);
@@ -204,8 +204,9 @@ const askedKey = (tracks, lang) => {
204
204
  async function voiceModeOf(req, collection, options, target) {
205
205
  const decided = await options.voiceMode?.({ collection, doc: target.doc, req, row: target.row });
206
206
  if (decided === 'cloned' || decided === 'synthetic')
207
- return { fixed: true, mode: decided };
208
- return { fixed: false, mode: target.data.voices === 'cloned' ? 'cloned' : 'synthetic' };
207
+ return { as: { cloned: decided === 'cloned' }, fixed: true, mode: decided };
208
+ const mode = target.data.voices === 'cloned' ? 'cloned' : 'synthetic';
209
+ return { as: { cloned: mode === 'cloned' }, fixed: false, mode };
209
210
  }
210
211
  /** A spoken translation brought up to date from VocalStack's track. */
211
212
  function settle(speech, track, translation) {
@@ -216,10 +217,12 @@ function settle(speech, track, translation) {
216
217
  }
217
218
  if (track.state === 'failed')
218
219
  return { ...speech, error: track.error ?? 'The reading failed.', state: 'failed' };
220
+ const readIn = track.voices ?? speech.readIn ?? null;
219
221
  if (track.state !== 'sealed')
220
- return { ...speech, done: track.clips?.length ?? 0, error: null, state: track.state === 'queued' ? 'queued' : 'running', voice: keyOf(track) || speech.voice };
222
+ return { ...speech, done: track.clips?.length ?? 0, error: null, readIn, state: track.state === 'queued' ? 'queued' : 'running', voice: keyOf(track) || speech.voice };
221
223
  return {
222
224
  ...speech,
225
+ readIn,
223
226
  voice: keyOf(track) || speech.voice,
224
227
  done: null,
225
228
  durationS: track.durationS ?? null,
@@ -315,7 +318,7 @@ async function refresh(req, api, readings, target, key) {
315
318
  * is asked for, step by step (each step saved), ask VocalStack to read each one aloud once its
316
319
  * translation is done, then bring readings up to date and keep their files. The field as saved.
317
320
  */
318
- async function advance(req, api, readings, target, key, budgetMs, cloned) {
321
+ async function advance(req, api, readings, target, key, budgetMs, speakAs) {
319
322
  const deadline = Date.now() + budgetMs;
320
323
  let data = target.data;
321
324
  const at = () => ({ ...target, data });
@@ -348,12 +351,12 @@ async function advance(req, api, readings, target, key, budgetMs, cloned) {
348
351
  if (s.state !== 'translating' || !isTranslated(data.translations?.[lang]) || Date.now() > deadline + 30_000)
349
352
  continue;
350
353
  try {
351
- const inClones = await cloned();
352
- const tracks = await api.speak(data.recordingId, [lang], { cloned: inClones });
354
+ const as = await speakAs();
355
+ const tracks = await api.speak(data.recordingId, [lang], as);
353
356
  const requestedAt = new Date().toISOString();
354
357
  const voice = askedKey(tracks, lang);
355
358
  data = await target.save((current) => ({
356
- speech: { ...current.speech, [lang]: { ...current.speech?.[lang], cast: inClones ? 'cloned' : 'synthetic', error: null, requestedAt, state: 'queued', voice } },
359
+ speech: { ...current.speech, [lang]: { ...current.speech?.[lang], cast: as.cloned ? 'cloned' : 'synthetic', error: null, requestedAt, state: 'queued', voice } },
357
360
  }));
358
361
  }
359
362
  catch (err) {
@@ -447,7 +450,7 @@ function background(payload, collection, options, rowFields, id, where, force =
447
450
  return;
448
451
  await advance(req, new VocalStackAPI(apiKey, options.apiURL ?? DEFAULT_API_URL), readingsSlug(options), target, key, BACKGROUND_MS, async () => {
449
452
  const fresh = await locate(req, collection, options, rowFields, 'admin');
450
- return (await voiceModeOf(req, collection, options, fresh instanceof Response ? target : fresh)).mode === 'cloned';
453
+ return (await voiceModeOf(req, collection, options, fresh instanceof Response ? target : fresh)).as;
451
454
  });
452
455
  };
453
456
  const run = () => work()
@@ -626,12 +629,12 @@ export function speechEndpoints(collection, options, rowFields) {
626
629
  const later = asked.langs.filter((l) => !ready.includes(l));
627
630
  let data = target.data;
628
631
  if (ready.length) {
629
- const cloned = (await voiceModeOf(req, collection, options, target)).mode === 'cloned';
630
- const tracks = await api.speak(target.data.recordingId, ready, { cloned });
632
+ const { as } = await voiceModeOf(req, collection, options, target);
633
+ const tracks = await api.speak(target.data.recordingId, ready, as);
631
634
  for (const lang of ready)
632
635
  await dropReading(req, readings, data.speech?.[lang]);
633
636
  const requestedAt = new Date().toISOString();
634
- const cast = cloned ? 'cloned' : 'synthetic';
637
+ const cast = as.cloned ? 'cloned' : 'synthetic';
635
638
  data = await target.save((current) => ({
636
639
  speech: {
637
640
  ...current.speech,
@@ -659,7 +662,8 @@ export function speechEndpoints(collection, options, rowFields) {
659
662
  const target = await locate(req, collection, options, rowFields, 'user');
660
663
  if (target instanceof Response)
661
664
  return target;
662
- const voiceMode = await voiceModeOf(req, collection, options, target);
665
+ const { fixed, mode } = await voiceModeOf(req, collection, options, target);
666
+ const voiceMode = { fixed, mode };
663
667
  const answer = (vocalstack) => json({ vocalstack, voiceMode });
664
668
  if (!target.data.recordingId || !hasWork(target.data, readings))
665
669
  return answer(target.data);
package/dist/types.d.ts CHANGED
@@ -75,8 +75,9 @@ export type VocalStackPluginOptions = {
75
75
  listeners?: boolean | ListenerOptions;
76
76
  /**
77
77
  * Whether a transcript is read in its speakers' cloned voices or in synthetic ones, decided by
78
- * the site (e.g. from the person speaking: `cloned` when they agreed to voice cloning). Answer
79
- * nothing to leave it to the transcript's own toggle. When set, the toggle is not shown.
78
+ * the site (e.g. from the person speaking: `cloned` once they have a voice). `cloned` reads each
79
+ * speaker in their clone where VocalStack has one for them, and in a stock voice otherwise.
80
+ * Answer nothing to leave it to the transcript's own toggle. When set, the toggle is not shown.
80
81
  */
81
82
  voiceMode?: (args: {
82
83
  collection: CollectionSlug;
@@ -154,6 +155,8 @@ export type Speech = {
154
155
  state: SpeechState;
155
156
  /** Read in speakers' cloned voices, or in stock (synthetic) ones. */
156
157
  cast?: null | VoiceMode;
158
+ /** What VocalStack read it in: `cloned`, `synthetic`, or `mixed` (some speakers had no usable clone). */
159
+ readIn?: 'cloned' | 'mixed' | 'synthetic' | null;
157
160
  /** VocalStack's key for the voices it is read in (e.g. `cast:-1=M1`); `null` until VocalStack says. */
158
161
  voice: null | string;
159
162
  /** Once sealed: the reading's MP3, saved once in the readings upload collection and served from there. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocalstack/payload",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "VocalStack for Payload CMS: transcribe audio, translate it into other languages and read it aloud, kept in your own database and storage.",
5
5
  "license": "MIT",
6
6
  "type": "module",