@audd/sdk 1.4.7
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/LICENSE +21 -0
- package/README.md +335 -0
- package/dist/http-y2YwjfAl.d.cts +37 -0
- package/dist/http-y2YwjfAl.d.ts +37 -0
- package/dist/index.cjs +1442 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +533 -0
- package/dist/index.d.ts +533 -0
- package/dist/index.js +1398 -0
- package/dist/index.js.map +1 -0
- package/dist/longpoll.cjs +246 -0
- package/dist/longpoll.cjs.map +1 -0
- package/dist/longpoll.d.cts +58 -0
- package/dist/longpoll.d.ts +58 -0
- package/dist/longpoll.js +244 -0
- package/dist/longpoll.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import { H as HttpClient, F as FetchLike } from './http-y2YwjfAl.js';
|
|
2
|
+
|
|
3
|
+
declare const VERSION = "1.4.6";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Typed models. Forward-compatible: each model captures unknown keys into
|
|
7
|
+
* `extras`, mirroring audd-python's Pydantic `extra="allow"` pattern.
|
|
8
|
+
*/
|
|
9
|
+
/** Streaming providers supported by the lis.tn redirect helper. */
|
|
10
|
+
type StreamingProvider = "spotify" | "apple_music" | "deezer" | "napster" | "youtube";
|
|
11
|
+
interface RecognitionResult {
|
|
12
|
+
/** Always present on a match. */
|
|
13
|
+
timecode: string;
|
|
14
|
+
/** Set on custom-catalog matches. */
|
|
15
|
+
audioId?: number | undefined;
|
|
16
|
+
artist?: string | undefined;
|
|
17
|
+
title?: string | undefined;
|
|
18
|
+
album?: string | undefined;
|
|
19
|
+
releaseDate?: string | undefined;
|
|
20
|
+
label?: string | undefined;
|
|
21
|
+
songLink?: string | undefined;
|
|
22
|
+
appleMusic?: Record<string, unknown> | undefined;
|
|
23
|
+
spotify?: Record<string, unknown> | undefined;
|
|
24
|
+
deezer?: Record<string, unknown> | undefined;
|
|
25
|
+
napster?: Record<string, unknown> | undefined;
|
|
26
|
+
musicbrainz?: ReadonlyArray<Record<string, unknown>> | undefined;
|
|
27
|
+
/** Forward-compat: any unknown keys from the server. */
|
|
28
|
+
extras: Record<string, unknown>;
|
|
29
|
+
/** Full unparsed payload for the caller's own inspection. */
|
|
30
|
+
rawResponse: Record<string, unknown>;
|
|
31
|
+
/** True when `audioId` is set (custom-catalog match). */
|
|
32
|
+
readonly isCustomMatch: boolean;
|
|
33
|
+
/** True when `audioId` is unset and `artist` or `title` are present. */
|
|
34
|
+
readonly isPublicMatch: boolean;
|
|
35
|
+
/** Cover-art URL for `lis.tn`-hosted song_links, else `null`. */
|
|
36
|
+
readonly thumbnailUrl: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Direct or redirect URL for a streaming provider, with smart fallback.
|
|
39
|
+
*
|
|
40
|
+
* Resolution order:
|
|
41
|
+
* 1. Direct URL from the metadata block (e.g. `apple_music.url`,
|
|
42
|
+
* `spotify.external_urls.spotify`, `deezer.link`, `napster.href`) when
|
|
43
|
+
* the user requested that provider via `return=`.
|
|
44
|
+
* 2. lis.tn redirect (`{songLink}?{provider}`) when `songLink` is on lis.tn.
|
|
45
|
+
* 3. `null` otherwise. YouTube has only the lis.tn-redirect path.
|
|
46
|
+
*/
|
|
47
|
+
streamingUrl(provider: StreamingProvider): string | null;
|
|
48
|
+
/** Map of every provider with a resolvable URL — direct or via lis.tn redirect. */
|
|
49
|
+
streamingUrls(): Partial<Record<StreamingProvider, string>>;
|
|
50
|
+
/**
|
|
51
|
+
* First available 30-second preview URL across providers, in priority order:
|
|
52
|
+
* `apple_music.previews[0].url` → `spotify.preview_url` → `deezer.preview`.
|
|
53
|
+
*
|
|
54
|
+
* **Note:** previews are governed by the respective providers' terms of use.
|
|
55
|
+
* The SDK consumer is responsible for honoring those terms (caching limits,
|
|
56
|
+
* attribution, redistribution constraints).
|
|
57
|
+
*/
|
|
58
|
+
previewUrl(): string | null;
|
|
59
|
+
}
|
|
60
|
+
interface EnterpriseMatch {
|
|
61
|
+
score: number;
|
|
62
|
+
timecode: string;
|
|
63
|
+
artist?: string | undefined;
|
|
64
|
+
title?: string | undefined;
|
|
65
|
+
album?: string | undefined;
|
|
66
|
+
releaseDate?: string | undefined;
|
|
67
|
+
label?: string | undefined;
|
|
68
|
+
isrc?: string | undefined;
|
|
69
|
+
upc?: string | undefined;
|
|
70
|
+
songLink?: string | undefined;
|
|
71
|
+
startOffset?: number | undefined;
|
|
72
|
+
endOffset?: number | undefined;
|
|
73
|
+
extras: Record<string, unknown>;
|
|
74
|
+
rawResponse: Record<string, unknown>;
|
|
75
|
+
readonly thumbnailUrl: string | null;
|
|
76
|
+
/** lis.tn redirect URL for the given streaming provider, or null if `songLink` is non-lis.tn. */
|
|
77
|
+
streamingUrl(provider: StreamingProvider): string | null;
|
|
78
|
+
/** All providers with a resolvable lis.tn redirect URL (or empty when `songLink` is off lis.tn). */
|
|
79
|
+
streamingUrls(): Partial<Record<StreamingProvider, string>>;
|
|
80
|
+
}
|
|
81
|
+
interface EnterpriseChunkResult {
|
|
82
|
+
songs: EnterpriseMatch[];
|
|
83
|
+
offset: string;
|
|
84
|
+
extras: Record<string, unknown>;
|
|
85
|
+
rawResponse: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
interface Stream {
|
|
88
|
+
radioId: number;
|
|
89
|
+
url: string;
|
|
90
|
+
streamRunning: boolean;
|
|
91
|
+
longpollCategory?: string | undefined;
|
|
92
|
+
extras: Record<string, unknown>;
|
|
93
|
+
rawResponse: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
interface StreamCallbackResultEntry {
|
|
96
|
+
artist: string;
|
|
97
|
+
title: string;
|
|
98
|
+
score: number;
|
|
99
|
+
album?: string | undefined;
|
|
100
|
+
releaseDate?: string | undefined;
|
|
101
|
+
label?: string | undefined;
|
|
102
|
+
songLink?: string | undefined;
|
|
103
|
+
appleMusic?: Record<string, unknown> | undefined;
|
|
104
|
+
spotify?: Record<string, unknown> | undefined;
|
|
105
|
+
deezer?: Record<string, unknown> | undefined;
|
|
106
|
+
napster?: Record<string, unknown> | undefined;
|
|
107
|
+
musicbrainz?: ReadonlyArray<Record<string, unknown>> | undefined;
|
|
108
|
+
extras: Record<string, unknown>;
|
|
109
|
+
rawResponse: Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
interface StreamCallbackResult {
|
|
112
|
+
radioId: number;
|
|
113
|
+
timestamp?: string | undefined;
|
|
114
|
+
playLength?: number | undefined;
|
|
115
|
+
results: StreamCallbackResultEntry[];
|
|
116
|
+
extras: Record<string, unknown>;
|
|
117
|
+
rawResponse: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
interface StreamCallbackNotification {
|
|
120
|
+
radioId: number;
|
|
121
|
+
streamRunning?: boolean | undefined;
|
|
122
|
+
notificationCode: number;
|
|
123
|
+
notificationMessage: string;
|
|
124
|
+
extras: Record<string, unknown>;
|
|
125
|
+
rawResponse: Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Discriminated union: a parsed callback payload is either a recognition
|
|
129
|
+
* result or a notification.
|
|
130
|
+
*/
|
|
131
|
+
interface StreamCallbackPayload {
|
|
132
|
+
/** Set when this is a recognition result delivery. */
|
|
133
|
+
result: StreamCallbackResult | null;
|
|
134
|
+
/** Set when this is a stream-state notification. */
|
|
135
|
+
notification: StreamCallbackNotification | null;
|
|
136
|
+
/** Notification time (epoch seconds). */
|
|
137
|
+
time: number | null;
|
|
138
|
+
/** Original parsed JSON body. */
|
|
139
|
+
rawPayload: Record<string, unknown>;
|
|
140
|
+
readonly isResult: boolean;
|
|
141
|
+
readonly isNotification: boolean;
|
|
142
|
+
}
|
|
143
|
+
declare function parseStreamCallback(raw: unknown): StreamCallbackPayload;
|
|
144
|
+
interface LyricsResult {
|
|
145
|
+
artist: string;
|
|
146
|
+
title: string;
|
|
147
|
+
lyrics?: string | undefined;
|
|
148
|
+
songId?: number | undefined;
|
|
149
|
+
fullTitle?: string | undefined;
|
|
150
|
+
artistId?: number | undefined;
|
|
151
|
+
songLink?: string | undefined;
|
|
152
|
+
media?: string | undefined;
|
|
153
|
+
extras: Record<string, unknown>;
|
|
154
|
+
rawResponse: Record<string, unknown>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Auto-detect what kind of audio source the caller passed and convert to
|
|
159
|
+
* the right multipart fields.
|
|
160
|
+
*
|
|
161
|
+
* Returns a *re-opener* — a 0-arg callable that yields fresh form fields
|
|
162
|
+
* on each call. The HTTP layer invokes it inside the retry-wrapped request
|
|
163
|
+
* closure, so retried attempts get fresh body content rather than an
|
|
164
|
+
* exhausted stream / spent buffer.
|
|
165
|
+
*
|
|
166
|
+
* Specifically: `fetch()` does NOT auto-rewind a `Blob` constructed over a
|
|
167
|
+
* stream once the body is consumed; the re-opener pattern is mandatory in
|
|
168
|
+
* Node/browsers (the audd-python C1 review note discusses this — Python's
|
|
169
|
+
* httpx auto-seeks; ours doesn't always).
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Audio source the caller passes to `recognize` / `recognizeEnterprise` /
|
|
174
|
+
* `customCatalog.add`. Auto-detected:
|
|
175
|
+
*
|
|
176
|
+
* - `string` starting with `http://` or `https://` → URL parameter
|
|
177
|
+
* - `string` other → resolved as a filesystem path on Node (TypeError in browsers)
|
|
178
|
+
* - `URL` → URL parameter
|
|
179
|
+
* - `Blob` / `File` → multipart upload
|
|
180
|
+
* - `Uint8Array` / `Buffer` → multipart upload
|
|
181
|
+
*/
|
|
182
|
+
type Source = string | URL | Blob | Uint8Array;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Cost-aware retry classes.
|
|
186
|
+
*
|
|
187
|
+
* - READ — idempotent reads (`streams.list`, `streams.getCallbackUrl`):
|
|
188
|
+
* retry on 408/429/5xx + any connection error.
|
|
189
|
+
* - RECOGNITION — `recognize`, `recognizeEnterprise`, `advanced.findLyrics`:
|
|
190
|
+
* retry on pre-upload connection failures + 5xx.
|
|
191
|
+
* DO NOT retry on read-timeout-after-upload (cost protection).
|
|
192
|
+
* - MUTATING — `streams.add`, `streams.delete`, etc., `customCatalog.add`:
|
|
193
|
+
* retry only on pre-upload connection failures. DO NOT retry
|
|
194
|
+
* 5xx (the side effect may have happened).
|
|
195
|
+
*/
|
|
196
|
+
type RetryClass = "read" | "recognition" | "mutating";
|
|
197
|
+
interface RetryPolicy {
|
|
198
|
+
retryClass: RetryClass;
|
|
199
|
+
maxAttempts: number;
|
|
200
|
+
backoffFactorMs: number;
|
|
201
|
+
backoffMaxMs: number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
interface SetCallbackUrlOptions {
|
|
205
|
+
returnMetadata?: string | string[];
|
|
206
|
+
}
|
|
207
|
+
interface AddStreamOptions {
|
|
208
|
+
url: string;
|
|
209
|
+
radioId: number;
|
|
210
|
+
/** "before" delivers callbacks at song start; default delivers at song end. */
|
|
211
|
+
callbacks?: "before" | string;
|
|
212
|
+
}
|
|
213
|
+
interface LongpollOptions {
|
|
214
|
+
sinceTime?: number;
|
|
215
|
+
/** Server-side timeout in seconds (default 50). */
|
|
216
|
+
timeout?: number;
|
|
217
|
+
/** Bypass the default-on `getCallbackUrl` preflight. */
|
|
218
|
+
skipCallbackCheck?: boolean;
|
|
219
|
+
}
|
|
220
|
+
declare class Streams {
|
|
221
|
+
private readonly http;
|
|
222
|
+
private readonly readPolicy;
|
|
223
|
+
private readonly mutatingPolicy;
|
|
224
|
+
private readonly apiToken;
|
|
225
|
+
constructor(http: HttpClient, readPolicy: RetryPolicy, mutatingPolicy: RetryPolicy, apiToken: string);
|
|
226
|
+
private post;
|
|
227
|
+
/**
|
|
228
|
+
* Set the callback URL where AudD will POST recognition events.
|
|
229
|
+
*
|
|
230
|
+
* @param url The URL to register.
|
|
231
|
+
* @param opts.returnMetadata Optional metadata block list — appended as
|
|
232
|
+
* `?return=...` to the URL. Raises `DuplicateReturnParameterError` if the
|
|
233
|
+
* URL already contains a `?return=` parameter.
|
|
234
|
+
*/
|
|
235
|
+
setCallbackUrl(url: string, opts?: SetCallbackUrlOptions): Promise<void>;
|
|
236
|
+
/** Get the currently registered callback URL. */
|
|
237
|
+
getCallbackUrl(): Promise<string>;
|
|
238
|
+
/** Register a new stream for real-time recognition. */
|
|
239
|
+
add(opts: AddStreamOptions): Promise<void>;
|
|
240
|
+
/** Update the upstream URL of an existing stream. */
|
|
241
|
+
setUrl(radioId: number, url: string): Promise<void>;
|
|
242
|
+
/** Delete an existing stream. */
|
|
243
|
+
delete(radioId: number): Promise<void>;
|
|
244
|
+
/** List all streams on this account. */
|
|
245
|
+
list(): Promise<Stream[]>;
|
|
246
|
+
/** Compute the 9-char longpoll category locally — pure, no network. */
|
|
247
|
+
deriveLongpollCategory(radioId: number): string;
|
|
248
|
+
/** Parse a callback POST body into a typed `StreamCallbackPayload`. */
|
|
249
|
+
parseCallback(body: unknown): StreamCallbackPayload;
|
|
250
|
+
/**
|
|
251
|
+
* Longpoll the AudD subscription endpoint, yielding parsed JSON dicts
|
|
252
|
+
* (recognition events, notifications, or `{ timeout: ... }` markers).
|
|
253
|
+
*
|
|
254
|
+
* By default, performs a one-time `getCallbackUrl` preflight. If the
|
|
255
|
+
* server returns code 19 (no callback URL configured), throws
|
|
256
|
+
* `AudDInvalidRequestError` with an actionable hint. Pass
|
|
257
|
+
* `skipCallbackCheck: true` to bypass.
|
|
258
|
+
*/
|
|
259
|
+
longpoll(category: string, opts?: LongpollOptions): AsyncIterable<Record<string, unknown>>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
interface CustomCatalogAddOptions {
|
|
263
|
+
audioId: number;
|
|
264
|
+
source: Source;
|
|
265
|
+
}
|
|
266
|
+
declare class CustomCatalog {
|
|
267
|
+
private readonly http;
|
|
268
|
+
private readonly mutatingPolicy;
|
|
269
|
+
constructor(http: HttpClient, mutatingPolicy: RetryPolicy);
|
|
270
|
+
/**
|
|
271
|
+
* **This is NOT how you submit audio for music recognition.** For
|
|
272
|
+
* recognition, use `audd.recognize()` (or `audd.recognizeEnterprise()` for
|
|
273
|
+
* files longer than 25 seconds). This method adds a song to your
|
|
274
|
+
* **private fingerprint catalog** so AudD's recognition can later identify
|
|
275
|
+
* *your own* tracks for *your account only*. Requires special access —
|
|
276
|
+
* contact api@audd.io if you need it enabled.
|
|
277
|
+
*
|
|
278
|
+
* Calling this again with the same `audioId` re-fingerprints that slot.
|
|
279
|
+
* There is no public list/delete endpoint; track `audioId` ↔ song
|
|
280
|
+
* mappings on your side.
|
|
281
|
+
*/
|
|
282
|
+
add(opts: CustomCatalogAddOptions): Promise<void>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
declare class Advanced {
|
|
286
|
+
private readonly http;
|
|
287
|
+
private readonly recognitionPolicy;
|
|
288
|
+
/**
|
|
289
|
+
* @param recognitionPolicy The findLyrics endpoint is metered and shouldn't
|
|
290
|
+
* double-bill on post-upload read timeout: Advanced uses RECOGNITION retry
|
|
291
|
+
* policy, not READ.
|
|
292
|
+
*/
|
|
293
|
+
constructor(http: HttpClient, recognitionPolicy: RetryPolicy);
|
|
294
|
+
/** Find lyrics by free-text query. Returns a list of matches (possibly empty). */
|
|
295
|
+
findLyrics(query: string): Promise<LyricsResult[]>;
|
|
296
|
+
/**
|
|
297
|
+
* Hit any AudD endpoint by method name and return the raw JSON object.
|
|
298
|
+
* Useful for endpoints not yet wrapped by typed methods on this SDK.
|
|
299
|
+
*/
|
|
300
|
+
rawRequest(method: string, params?: Record<string, string | number | boolean | undefined>): Promise<Record<string, unknown>>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Inspection event kinds emitted by the SDK request lifecycle.
|
|
305
|
+
* Hooks receive these via the `onEvent` callback.
|
|
306
|
+
*/
|
|
307
|
+
type AudDEventKind = "request" | "response" | "exception";
|
|
308
|
+
/**
|
|
309
|
+
* Inspection event emitted by the SDK request lifecycle.
|
|
310
|
+
* Frozen, plain-data; never includes the api_token or request body bytes.
|
|
311
|
+
*/
|
|
312
|
+
interface AudDEvent {
|
|
313
|
+
kind: AudDEventKind;
|
|
314
|
+
/** AudD method name, e.g. "recognize", "addStream". */
|
|
315
|
+
method: string;
|
|
316
|
+
url: string;
|
|
317
|
+
requestId: string | null;
|
|
318
|
+
httpStatus: number | null;
|
|
319
|
+
elapsedMs: number | null;
|
|
320
|
+
errorCode: number | null;
|
|
321
|
+
extras: Record<string, unknown>;
|
|
322
|
+
}
|
|
323
|
+
type OnEventHook = (event: AudDEvent) => void;
|
|
324
|
+
interface AudDOptions {
|
|
325
|
+
/** Required, but may be omitted if `AUDD_API_TOKEN` is in the environment. */
|
|
326
|
+
apiToken?: string;
|
|
327
|
+
/** Maximum retry attempts (default 3). */
|
|
328
|
+
maxRetries?: number;
|
|
329
|
+
/** Initial backoff in ms (default 500), jittered, exponential. */
|
|
330
|
+
backoffFactorMs?: number;
|
|
331
|
+
/** Custom fetch (e.g., for proxy/mTLS). */
|
|
332
|
+
fetch?: FetchLike;
|
|
333
|
+
/** Inspection hook (see {@link AudDEvent}). Off by default. */
|
|
334
|
+
onEvent?: OnEventHook;
|
|
335
|
+
}
|
|
336
|
+
type ReturnMetadata = "apple_music" | "spotify" | "deezer" | "napster" | "musicbrainz" | string;
|
|
337
|
+
interface RecognizeOptions {
|
|
338
|
+
return?: ReturnMetadata | ReturnMetadata[];
|
|
339
|
+
market?: string;
|
|
340
|
+
/** Per-call timeout in ms; overrides the client default. */
|
|
341
|
+
timeoutMs?: number;
|
|
342
|
+
/**
|
|
343
|
+
* User-supplied AbortSignal for cancellation.
|
|
344
|
+
*
|
|
345
|
+
* **Note:** cancellation aborts the local request. The server may have
|
|
346
|
+
* already done metered work and the credit is consumed regardless.
|
|
347
|
+
*/
|
|
348
|
+
signal?: AbortSignal;
|
|
349
|
+
}
|
|
350
|
+
interface RecognizeEnterpriseOptions {
|
|
351
|
+
return?: ReturnMetadata | ReturnMetadata[];
|
|
352
|
+
skip?: number;
|
|
353
|
+
every?: number;
|
|
354
|
+
limit?: number;
|
|
355
|
+
skipFirstSeconds?: number;
|
|
356
|
+
useTimecode?: boolean;
|
|
357
|
+
accurateOffsets?: boolean;
|
|
358
|
+
timeoutMs?: number;
|
|
359
|
+
/**
|
|
360
|
+
* User-supplied AbortSignal for cancellation. See {@link RecognizeOptions.signal}.
|
|
361
|
+
* For multi-hour enterprise calls, this is the right way to cancel.
|
|
362
|
+
*/
|
|
363
|
+
signal?: AbortSignal;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* The AudD client. Async-only — every method returns a `Promise`.
|
|
367
|
+
*
|
|
368
|
+
* ```ts
|
|
369
|
+
* const audd = new AudD({ apiToken: "test" });
|
|
370
|
+
* const result = await audd.recognize("https://audd.tech/example.mp3");
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* Closes underlying resources via `close()` (or `[Symbol.asyncDispose]` if
|
|
374
|
+
* the runtime supports explicit-resource-management).
|
|
375
|
+
*/
|
|
376
|
+
declare class AudD {
|
|
377
|
+
private readonly _http;
|
|
378
|
+
private readonly _enterpriseHttp;
|
|
379
|
+
private readonly _maxRetries;
|
|
380
|
+
private readonly _backoffFactorMs;
|
|
381
|
+
private _apiToken;
|
|
382
|
+
private _onEvent;
|
|
383
|
+
private _streams;
|
|
384
|
+
private _customCatalog;
|
|
385
|
+
private _advanced;
|
|
386
|
+
/** Construct with just an api_token. Falls back to AUDD_API_TOKEN env var if omitted. */
|
|
387
|
+
constructor(apiToken?: string);
|
|
388
|
+
/** Construct with an api_token and additional options (timeouts, retries, custom fetch, onEvent hook). */
|
|
389
|
+
constructor(apiToken: string, opts: Omit<AudDOptions, "apiToken">);
|
|
390
|
+
/** Construct with an options object (any combination of apiToken + extras). */
|
|
391
|
+
constructor(opts: AudDOptions);
|
|
392
|
+
/** Current api_token. Returns the in-effect token after any rotations. */
|
|
393
|
+
get apiToken(): string;
|
|
394
|
+
/**
|
|
395
|
+
* Rotate the api_token used for subsequent requests. In-flight requests
|
|
396
|
+
* continue with the old token (no abort).
|
|
397
|
+
*/
|
|
398
|
+
setApiToken(newToken: string): void;
|
|
399
|
+
private policyFor;
|
|
400
|
+
/** Sub-namespace for stream management + longpoll. Lazy-instantiated. */
|
|
401
|
+
get streams(): Streams;
|
|
402
|
+
/** Sub-namespace for the private fingerprint catalog. NOT for recognition. */
|
|
403
|
+
get customCatalog(): CustomCatalog;
|
|
404
|
+
/** Lyrics search + raw-request escape hatch. */
|
|
405
|
+
get advanced(): Advanced;
|
|
406
|
+
/**
|
|
407
|
+
* Recognize a short audio clip (≤25s) from a URL, file path, Blob, or bytes.
|
|
408
|
+
*
|
|
409
|
+
* Returns `null` when the server returns `status=success` with `result=null`
|
|
410
|
+
* (no match) — distinct from a thrown error.
|
|
411
|
+
*/
|
|
412
|
+
recognize(source: Source, opts?: RecognizeOptions): Promise<RecognitionResult | null>;
|
|
413
|
+
/**
|
|
414
|
+
* Enterprise recognition (long files). Returns a flat array of matches
|
|
415
|
+
* across all chunks in the upstream response.
|
|
416
|
+
*
|
|
417
|
+
* Recommended: pass `limit: N` to cap result count when developing.
|
|
418
|
+
*/
|
|
419
|
+
recognizeEnterprise(source: Source, opts?: RecognizeEnterpriseOptions): Promise<EnterpriseMatch[]>;
|
|
420
|
+
/** Release any underlying resources. (Currently a no-op for `fetch`-based transport.) */
|
|
421
|
+
close(): void;
|
|
422
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Exception hierarchy for AudD API errors. */
|
|
426
|
+
interface AudDApiErrorFields {
|
|
427
|
+
errorCode: number;
|
|
428
|
+
message: string;
|
|
429
|
+
httpStatus: number;
|
|
430
|
+
requestId: string | null;
|
|
431
|
+
requestedParams: Record<string, unknown>;
|
|
432
|
+
requestMethod: string | null;
|
|
433
|
+
brandedMessage: string | null;
|
|
434
|
+
rawResponse: unknown;
|
|
435
|
+
}
|
|
436
|
+
type AudDApiErrorInit = Partial<AudDApiErrorFields> & Pick<AudDApiErrorFields, "errorCode" | "message" | "httpStatus">;
|
|
437
|
+
/** Base for everything thrown by this SDK. */
|
|
438
|
+
declare class AudDError extends Error {
|
|
439
|
+
name: string;
|
|
440
|
+
}
|
|
441
|
+
/** Server returned `status: error`. Carries the AudD error code + the full echo. */
|
|
442
|
+
declare class AudDAPIError extends AudDError {
|
|
443
|
+
name: string;
|
|
444
|
+
errorCode: number;
|
|
445
|
+
httpStatus: number;
|
|
446
|
+
requestId: string | null;
|
|
447
|
+
requestedParams: Record<string, unknown>;
|
|
448
|
+
requestMethod: string | null;
|
|
449
|
+
brandedMessage: string | null;
|
|
450
|
+
rawResponse: unknown;
|
|
451
|
+
/** Original `error_message` from the server. (`Error.message` may be overridden by subclasses.) */
|
|
452
|
+
serverMessage: string;
|
|
453
|
+
constructor(init: AudDApiErrorInit);
|
|
454
|
+
}
|
|
455
|
+
declare class AudDAuthenticationError extends AudDAPIError {
|
|
456
|
+
name: string;
|
|
457
|
+
}
|
|
458
|
+
declare class AudDQuotaError extends AudDAPIError {
|
|
459
|
+
name: string;
|
|
460
|
+
}
|
|
461
|
+
declare class AudDSubscriptionError extends AudDAPIError {
|
|
462
|
+
name: string;
|
|
463
|
+
}
|
|
464
|
+
declare class AudDCustomCatalogAccessError extends AudDSubscriptionError {
|
|
465
|
+
name: string;
|
|
466
|
+
}
|
|
467
|
+
declare class AudDInvalidRequestError extends AudDAPIError {
|
|
468
|
+
name: string;
|
|
469
|
+
}
|
|
470
|
+
declare class AudDInvalidAudioError extends AudDAPIError {
|
|
471
|
+
name: string;
|
|
472
|
+
}
|
|
473
|
+
declare class AudDRateLimitError extends AudDAPIError {
|
|
474
|
+
name: string;
|
|
475
|
+
}
|
|
476
|
+
declare class AudDStreamLimitError extends AudDAPIError {
|
|
477
|
+
name: string;
|
|
478
|
+
}
|
|
479
|
+
declare class AudDNotReleasedError extends AudDAPIError {
|
|
480
|
+
name: string;
|
|
481
|
+
}
|
|
482
|
+
declare class AudDBlockedError extends AudDAPIError {
|
|
483
|
+
name: string;
|
|
484
|
+
}
|
|
485
|
+
declare class AudDNeedsUpdateError extends AudDAPIError {
|
|
486
|
+
name: string;
|
|
487
|
+
}
|
|
488
|
+
declare class AudDServerError extends AudDAPIError {
|
|
489
|
+
name: string;
|
|
490
|
+
}
|
|
491
|
+
declare class AudDConnectionError extends AudDError {
|
|
492
|
+
name: string;
|
|
493
|
+
cause?: unknown;
|
|
494
|
+
constructor(message: string, cause?: unknown);
|
|
495
|
+
}
|
|
496
|
+
declare class AudDSerializationError extends AudDError {
|
|
497
|
+
name: string;
|
|
498
|
+
rawText: string;
|
|
499
|
+
constructor(message: string, rawText?: string);
|
|
500
|
+
}
|
|
501
|
+
type AudDAPIErrorCtor = new (init: AudDApiErrorInit) => AudDAPIError;
|
|
502
|
+
declare function errorClassForCode(code: number): AudDAPIErrorCtor;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Raised by `addReturnToUrl` (and therefore by `streams.setCallbackUrl`)
|
|
506
|
+
* when the URL already contains a `return` query parameter and a
|
|
507
|
+
* `returnMetadata` argument is also passed — conflicting intent.
|
|
508
|
+
*/
|
|
509
|
+
declare class DuplicateReturnParameterError extends AudDInvalidRequestError {
|
|
510
|
+
name: string;
|
|
511
|
+
constructor();
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Compute the 9-char longpoll category locally from the API token + radio_id.
|
|
515
|
+
*
|
|
516
|
+
* Formula (per docs.audd.io/streams.md): hex-MD5 of (hex-MD5 of api_token,
|
|
517
|
+
* concatenated with the radio_id rendered as a decimal string), truncated
|
|
518
|
+
* to the first 9 hex chars.
|
|
519
|
+
*
|
|
520
|
+
* Pure function — no network call. Lets servers share a longpoll category
|
|
521
|
+
* with browser/mobile clients without leaking the api_token.
|
|
522
|
+
*/
|
|
523
|
+
declare function deriveLongpollCategory(apiToken: string, radioId: number): string;
|
|
524
|
+
/**
|
|
525
|
+
* Append `?return=<metadata>` (or merge as `&return=`) to the callback URL.
|
|
526
|
+
*
|
|
527
|
+
* - If `returnMetadata` is `undefined`, returns the URL unchanged.
|
|
528
|
+
* - If the URL already has a `return` query parameter, raises rather than
|
|
529
|
+
* silently overwriting.
|
|
530
|
+
*/
|
|
531
|
+
declare function addReturnToUrl(url: string, returnMetadata: string | string[] | undefined): string;
|
|
532
|
+
|
|
533
|
+
export { type AddStreamOptions, Advanced, AudD, AudDAPIError, AudDAuthenticationError, AudDBlockedError, AudDConnectionError, AudDCustomCatalogAccessError, AudDError, type AudDEvent, type AudDEventKind, AudDInvalidAudioError, AudDInvalidRequestError, AudDNeedsUpdateError, AudDNotReleasedError, type AudDOptions, AudDQuotaError, AudDRateLimitError, AudDSerializationError, AudDServerError, AudDStreamLimitError, AudDSubscriptionError, CustomCatalog, type CustomCatalogAddOptions, DuplicateReturnParameterError, type EnterpriseChunkResult, type EnterpriseMatch, type LongpollOptions, type LyricsResult, type OnEventHook, type RecognitionResult, type RecognizeEnterpriseOptions, type RecognizeOptions, type ReturnMetadata, type SetCallbackUrlOptions, type Source, type StreamCallbackNotification, type StreamCallbackPayload, type StreamCallbackResult, type StreamCallbackResultEntry, type Stream as StreamRecord, type StreamingProvider, Streams, VERSION, addReturnToUrl, deriveLongpollCategory, errorClassForCode, parseStreamCallback as parseCallback };
|