@vocalstack/payload 0.9.0 → 0.9.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/api.js CHANGED
@@ -21,8 +21,7 @@ function savedSpeakerOf(raw) {
21
21
  state: clone?.state ?? 'none',
22
22
  };
23
23
  }
24
- const speakerRoutes = new Map();
25
- const both = (rest) => ({ speakers: `/v1/speakers${rest}`, voices: `/v1/voices${rest}` });
24
+ const speakerPath = (rest) => `/v1/speakers${rest}`;
26
25
  export const UNAVAILABLE = 'VocalStack is unavailable, try again shortly.';
27
26
  /** A stored transcription the connected key cannot see: made in another workspace (the workspace was changed), or deleted. */
28
27
  export const NOT_IN_WORKSPACE = 'This transcript is not in the connected VocalStack workspace: it was made in another workspace, or deleted in VocalStack. Transcribe the file again to work with it here.';
@@ -41,7 +40,7 @@ function timeoutFor(url, method = 'GET') {
41
40
  const path = new URL(url).pathname;
42
41
  if (path.endsWith('/translation'))
43
42
  return 180_000;
44
- if (method === 'POST' && (path === '/v1/speakers' || path === '/v1/voices'))
43
+ if (method === 'POST' && path === '/v1/speakers')
45
44
  return 120_000;
46
45
  if (path.endsWith('/audio/clip') || path.endsWith('/preview'))
47
46
  return 60_000;
@@ -160,36 +159,20 @@ export class VocalStackAPI {
160
159
  clip(transcriptionId, startS, endS) {
161
160
  return call(() => this.sdk.transcriptions.audioClip(transcriptionId, startS, endS));
162
161
  }
163
- async #speakerRequest(method, paths, init = {}) {
164
- const first = speakerRoutes.get(this.#baseURL) ?? 'speakers';
165
- const order = first === 'speakers' ? ['speakers', 'voices'] : ['voices', 'speakers'];
162
+ #speakerRequest(method, path, init = {}) {
166
163
  const query = Object.entries(init.query ?? {}).filter((e) => e[1] !== undefined);
167
164
  const qs = query.length ? `?${new URLSearchParams(query)}` : '';
168
- let last;
169
- for (const route of order) {
170
- const path = paths[route];
171
- if (!path)
172
- continue;
173
- const url = `${this.#baseURL}${path}${qs}`;
174
- const headers = { accept: init.audio ? '*/*' : 'application/json', authorization: `Bearer ${this.#apiKey}` };
175
- if (init.body)
176
- headers['content-type'] = 'application/json';
177
- if (init.idempotencyKey)
178
- headers['idempotency-key'] = init.idempotencyKey;
179
- const body = init.form ?? (init.body ? JSON.stringify(init.body(route)) : undefined);
180
- const res = await call(() => fetch(url, { body, headers, method, signal: AbortSignal.timeout(timeoutFor(url, method)) }));
181
- if (res.status !== 404) {
182
- speakerRoutes.set(this.#baseURL, route);
183
- return res;
184
- }
185
- last = res;
186
- }
187
- if (!last)
188
- throw new VocalStackAPIError(404, 'not_found', 'Not found.');
189
- return last;
190
- }
191
- async #speaker(method, paths, init) {
192
- const res = await this.#speakerRequest(method, paths, init);
165
+ const url = `${this.#baseURL}${path}${qs}`;
166
+ const headers = { accept: init.audio ? '*/*' : 'application/json', authorization: `Bearer ${this.#apiKey}` };
167
+ if (init.body)
168
+ headers['content-type'] = 'application/json';
169
+ if (init.idempotencyKey)
170
+ headers['idempotency-key'] = init.idempotencyKey;
171
+ const body = init.form ?? (init.body ? JSON.stringify(init.body) : undefined);
172
+ return call(() => fetch(url, { body, headers, method, signal: AbortSignal.timeout(timeoutFor(url, method)) }));
173
+ }
174
+ async #speaker(method, path, init) {
175
+ const res = await this.#speakerRequest(method, path, init);
193
176
  const body = (await res.json().catch(() => null));
194
177
  if (res.ok && body)
195
178
  return savedSpeakerOf(body);
@@ -201,14 +184,14 @@ export class VocalStackAPI {
201
184
  // An empty id would read GET /v1/speakers/, the list, as if it were one speaker.
202
185
  if (!id)
203
186
  return Promise.reject(new VocalStackAPIError(404, 'not_found', 'No such speaker.'));
204
- return this.#speaker('GET', both(`/${encodeURIComponent(id)}`));
187
+ return this.#speaker('GET', speakerPath(`/${encodeURIComponent(id)}`));
205
188
  }
206
189
  /** Save a speaker from a recorded sample (30 s or more), cloning their voice. Needs the speaker's permission. */
207
190
  createSpeaker(sample, fileName, meta, idempotencyKey) {
208
191
  const form = new FormData();
209
192
  form.append('meta', JSON.stringify(meta));
210
193
  form.append('sample', sample, fileName);
211
- return this.#speaker('POST', both(''), { form, idempotencyKey });
194
+ return this.#speaker('POST', speakerPath(''), { form, idempotencyKey });
212
195
  }
213
196
  /**
214
197
  * Save a speaker from stretches of a transcription (5–60 s in all), cloning their voice.
@@ -217,17 +200,17 @@ export class VocalStackAPI {
217
200
  */
218
201
  speakerFromAppearance(opts, idempotencyKey) {
219
202
  const { speaker, ...rest } = opts;
220
- return this.#speaker('POST', { speakers: '/v1/speakers/from-appearance' }, {
221
- body: () => ({ ...rest, appearance: speaker, consent: true, library: true }),
203
+ return this.#speaker('POST', speakerPath('/from-appearance'), {
204
+ body: { ...rest, appearance: speaker, consent: true, library: true },
222
205
  idempotencyKey,
223
206
  });
224
207
  }
225
208
  /** Keep a trial speaker, as `name`, with the speaker's permission. */
226
209
  keepSpeaker(id, name) {
227
- return this.#speaker('PATCH', both(`/${encodeURIComponent(id)}`), { body: () => ({ consent: true, draft: false, library: true, name }) });
210
+ return this.#speaker('PATCH', speakerPath(`/${encodeURIComponent(id)}`), { body: { consent: true, draft: false, library: true, name } });
228
211
  }
229
212
  async deleteSpeaker(id) {
230
- const res = await this.#speakerRequest('DELETE', both(`/${encodeURIComponent(id)}`));
213
+ const res = await this.#speakerRequest('DELETE', speakerPath(`/${encodeURIComponent(id)}`));
231
214
  if (res.ok)
232
215
  return;
233
216
  const body = (await res.json().catch(() => null));
@@ -237,7 +220,7 @@ export class VocalStackAPI {
237
220
  }
238
221
  /** The saved speaker's cloned voice speaking a few seconds of `lang`, Ogg/Opus or CAF. 202 while it is being made. */
239
222
  speakerVoicePreview(id, lang, format = 'ogg') {
240
- return this.#speakerRequest('GET', both(`/${encodeURIComponent(id)}/preview`), { audio: true, query: { format, lang } });
223
+ return this.#speakerRequest('GET', speakerPath(`/${encodeURIComponent(id)}/preview`), { audio: true, query: { format, lang } });
241
224
  }
242
225
  availableVoices(lang, transcriptionId) {
243
226
  return call(() => this.sdk.voices.available(lang, { transcription: transcriptionId }));
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const PACKAGE_NAME = "@vocalstack/payload";
2
- export declare const VERSION = "0.9.0";
2
+ export declare const VERSION = "0.9.1";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Written by scripts/version.mjs from package.json. Do not edit.
2
2
  export const PACKAGE_NAME = "@vocalstack/payload";
3
- export const VERSION = "0.9.0";
3
+ export const VERSION = "0.9.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocalstack/payload",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
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",
@@ -50,6 +50,6 @@
50
50
  },
51
51
  "packageManager": "pnpm@10.15.1",
52
52
  "dependencies": {
53
- "@vocalstack/js-sdk": "2.0.0-alpha.15"
53
+ "@vocalstack/js-sdk": "2.0.0"
54
54
  }
55
55
  }