|
| 1 | +# Engine API reference |
| 2 | + |
| 3 | +Import the engine and GPU helpers from `@zeon.net/ace-step-webgpu`. Checkpoint sources, WAV utilities, schedule constructors, error classes and other CPU helpers are exported from `@zeon.net/ace-step-webgpu/core`. |
| 4 | + |
| 5 | +## Setup and state |
| 6 | + |
| 7 | +| API | Purpose | |
| 8 | +| ------------------------------------------------------- | ---------------------------------------------------------------------------- | |
| 9 | +| `inspectWebGpuSupport()` | Inspect adapter capabilities without creating the inference engine | |
| 10 | +| `requestAceDevice(options?)` | Request a GPU device and return its context, support report and loss promise | |
| 11 | +| `AceStepWebGpu.create({ device, sources?, revision? })` | Create an engine; default sources are the pinned Turbo bundle | |
| 12 | +| `engine.variant` | Detected model family | |
| 13 | +| `engine.capabilities` | Supported tasks for the selected checkpoint | |
| 14 | +| `engine.lmLoaded` | Whether a language model is loaded | |
| 15 | +| `engine.loras` / `engine.useLora` | Loaded inference adapters and whether they apply | |
| 16 | +| `engine.dispose()` / `context.destroy()` | Release engine resources, then the GPU device after active calls settle | |
| 17 | + |
| 18 | +## Generation and audio |
| 19 | + |
| 20 | +| Method | Inputs beyond generation options | Output | |
| 21 | +| ---------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------- | |
| 22 | +| `generate(input)` | `prompt`; optional lyrics, metadata and audio codes | `AceStepGenerationResult` | |
| 23 | +| `cover(input)` | `sourceLatents` or `audioCodes`; optional `noFsq` | Generation result | |
| 24 | +| `repaint(input)` | `sourceLatents`, `startSeconds`, `endSeconds`; optional `sourcePcm` and repaint settings | Generation result | |
| 25 | +| `repaintAudio(input)` | `audio`, `startSeconds`, `endSeconds`; optional PCM rate/channels and repaint settings | Generation result | |
| 26 | +| `extract(input)` | `sourceLatents`; optional `track`; Base model required | Generation result | |
| 27 | +| `lego(input)` | `sourceLatents`; optional `track`, range and mask settings; Base model required | Generation result | |
| 28 | +| `complete(input)` | `sourceLatents`; optional `trackClasses`; Base model required | Generation result | |
| 29 | +| `encodeAudio(audio, options?)` | WAV bytes or PCM; rate, channels, planar layout, sample, seed, signal | `Float32Array` latents | |
| 30 | +| `encodeAudioCodes(latents, { signal }?)` | Encoded latents | `Int32Array` audio codes | |
| 31 | +| `decodeAudioCodes(codes, signal?)` | Code string or number array | `Float32Array` latent hints | |
| 32 | + |
| 33 | +Generation task inputs require `prompt` and support `lyrics`, `durationSeconds`, `seed`, `bpm`, `keyscale`, `timeSignature`, `language`, `metas`, `instruction`, `schedule`, `guidanceScale`, `guidance`, `dcw`, `onProgress`, and `signal`. Source tasks also accept `audioCoverStrength` and `coverNoiseStrength`. See [generation](generation.md) and [audio editing](audio-editing.md) for examples and defaults. |
| 34 | + |
| 35 | +## Language models and adapters |
| 36 | + |
| 37 | +| Method | Purpose | |
| 38 | +| ---------------------------------------------------------- | ------------------------------------------------------------------------ | |
| 39 | +| `loadLm({ source?, signal?, onProgress? }?)` | Load a resident 5 Hz LM; defaults to pinned 1.7B | |
| 40 | +| `planWithLm(input)` | Generate metadata and optionally audio codes from `caption` and `lyrics` | |
| 41 | +| `unloadLm()` | Free LM resources | |
| 42 | +| `addLora(source, options?)` / `loadLora(source, options?)` | Load an adapter and return its name | |
| 43 | +| `setLoraScale(name, scale)` / `setLoraScale(scale)` | Adjust a named or most recently added adapter | |
| 44 | +| `setUseLora(enabled)` | Enable or disable all loaded adapters | |
| 45 | +| `removeLora(name)` / `unloadLora()` | Free one or all adapters | |
| 46 | + |
| 47 | +See [language models and adapters](lm-and-adapters.md) for detailed inputs. Exact optional fields are available in the package's TypeScript declarations and editor autocomplete. |
| 48 | + |
| 49 | +## Generation result |
| 50 | + |
| 51 | +A result includes planar `pcm`, frame-major `latents`, `sampleRate`, `audioChannels`, `samplesPerChannel`, `durationSeconds`, and `seed`. `lm` contains the optional LM output. `encodeWav(bitDepth?)`, `toBlob(bitDepth?)`, and `createAudioUrl(bitDepth?)` export WAV audio; supported depths are 16 and 32 bits. |
| 52 | + |
| 53 | +## Error handling |
| 54 | + |
| 55 | +```ts |
| 56 | +import { AceStepError } from "@zeon.net/ace-step-webgpu/core"; |
| 57 | + |
| 58 | +try { |
| 59 | + const result = await engine.generate({ prompt: "Gentle piano", seed: 42 }); |
| 60 | + console.log(result.durationSeconds); |
| 61 | +} catch (error) { |
| 62 | + if (error instanceof AceStepError) { |
| 63 | + console.error(error.code, error.message); |
| 64 | + } else { |
| 65 | + console.error(error); |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +Handle cancellation separately using the operation's `AbortSignal`. Not every failure is an `AceStepError`: device loss, allocation failures, fetch errors and invalid inputs may use other error types. Check capability flags before enabling Base-only tasks, show actionable download/GPU errors, and release resources in `finally` when your workflow ends. |
| 71 | + |
| 72 | +[Documentation index](README.md) · [Getting started](getting-started.md) |
0 commit comments