@vocalstack/payload 0.6.0 → 0.6.2

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/api.js CHANGED
@@ -198,6 +198,9 @@ export class VocalStackAPI {
198
198
  throw new VocalStackAPIError(res.status, body?.code ?? 'http_error', body?.message ?? `VocalStack answered ${res.status}`);
199
199
  }
200
200
  savedSpeaker(id) {
201
+ // An empty id would read GET /v1/speakers/, the list, as if it were one speaker.
202
+ if (!id)
203
+ return Promise.reject(new VocalStackAPIError(404, 'not_found', 'No such speaker.'));
201
204
  return this.#speaker('GET', both(`/${encodeURIComponent(id)}`));
202
205
  }
203
206
  /** Save a speaker from a recorded sample (30 s or more), cloning their voice. Needs the speaker's permission. */
@@ -216,7 +219,8 @@ export class VocalStackAPI {
216
219
  const { recordingId, speaker, transcriptionId, ...rest } = opts;
217
220
  const common = { ...rest, consent: true, library: true };
218
221
  return this.#speaker('POST', { speakers: transcriptionId ? '/v1/speakers/from-appearance' : undefined, voices: '/v1/voices/from-speaker' }, {
219
- body: (route) => (route === 'speakers' ? { ...common, appearance: speaker, transcriptionId } : { ...common, recordingId, speaker }),
222
+ // The spans are times in this recording: name it, or the server takes the latest one the speaker is heard in.
223
+ body: (route) => (route === 'speakers' ? { ...common, appearance: speaker, recordingId, transcriptionId } : { ...common, recordingId, speaker }),
220
224
  idempotencyKey,
221
225
  });
222
226
  }
@@ -144,6 +144,11 @@ async function keepReading(req, api, slug, target, lang, speech) {
144
144
  if (res.status !== 400)
145
145
  break;
146
146
  }
147
+ // The track is not there to keep any more (VocalStack re-reads a reading when its clone is
148
+ // rebuilt, or found nothing to read aloud): follow it as being made again, so the next look
149
+ // reads its state instead of downloading it forever.
150
+ if (res?.status === 404)
151
+ return { ...speech, done: 0, error: null, requestedAt: new Date().toISOString(), state: 'running' };
147
152
  if (!res?.ok)
148
153
  throw new VocalStackAPIError(502, 'unavailable', UNAVAILABLE);
149
154
  const data = Buffer.from(await res.arrayBuffer());
@@ -263,7 +263,8 @@ export function speakerEndpoints(config, options) {
263
263
  if (!source)
264
264
  return json({ error: 'That recording is not one of theirs.' }, 403);
265
265
  try {
266
- const transcriptionId = source.transcriptionId ?? (await api.job(source.recordingId).then((j) => j.transcriptionId, () => undefined));
266
+ // A failed lookup is an error to show, not a reason to try the retired /v1/voices/from-speaker.
267
+ const transcriptionId = source.transcriptionId ?? (await api.job(source.recordingId)).transcriptionId;
267
268
  const trial = await api.speakerFromAppearance({ draft: true, name: nameOf(req, doc), recordingId: source.recordingId, spans, speaker: body.speaker, transcriptionId }, `payload:${collection}:${id}:trial:${randomUUID()}`);
268
269
  // The trial it replaces (other samples picked) is not wanted any more.
269
270
  if (typeof body.replace === 'string' && body.replace !== trial.id)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocalstack/payload",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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",