Revoize SDK TypeScript API Reference
Installation
The TypeScript SDK consists of a core package and model-specific packages. For installation instructions, reach out to the Revoize support team using our contact form.
The core package implements utility functions and wrappers for using the wasm modules provided by the model-specific packages. The model-specific packages primarily consist of a wasm file implementing a Revoize AI Speech Enhancement model and of a configuration object which specifies relevant metadata of that wasm file.
Types
ModelConfig Interface
interface ModelConfig {
name: string;
packageName: string;
modelType: number;
sessionType: 'single' | 'multi';
description: string;
version: string;
jsAssetUrl: string;
wasmAssetUrl: string;
}Configuration object containing model metadata and asset URLs.
ModelInfo Interface
interface ModelInfo {
name: string;
packageName: string;
modelType: number;
sessionType: string;
description: string;
version: string;
}Information about the currently initialized model.
SDKError Class
class SDKError extends Error {
constructor(public code: string, message: string);
}Custom error class for Revoize SDK-related errors.
Functions
initialize Function
Signature
function initialize(config: ModelConfig): Promise<void>The initialize function sets up the SDK with the specified model configuration. This function must be called before any other SDK functions.
Parameters
config- AModelConfigobject containing model metadata and asset URLs. This is usually imported from the model-specific package.
Returns
Promise<void>- Resolves when initialization is complete.
Throws
SDKError- If initialization fails (e.g., WASM loading error, model loading failure).
Example
import { initialize } from "@revoize/sdk";
import { config as capellaConfig } from "@revoize/model-capella";
// Initialize the SDK with the Capella model
await initialize(capellaConfig);processAudio Function
Signature
function processAudio(audioData: number[]): number[]The processAudio function takes an input audio chunk and returns the enhanced audio directly.
WARNING
- Ensure
initialize()is called before using this function. - The
audioDatashould be from a 48 kHz recording. - Input must be an array of numbers (float32 values).
Parameters
audioData- An array of numbers representing single-channel audio samples recorded at 48 kHz.
Returns
number[]- Enhanced audio samples.
Throws
SDKError- If no model is initialized or processing fails. Specific error codes include:NO_MODEL_INITIALIZED- When no model is initializedBUFFER_ALLOCATION_FAILED- When buffer allocation failsAUDIO_PROCESSING_FAILED- When WASM processing returns non-zero resultAUDIO_PROCESSING_ERROR- For any other processing errors
Example
import { initialize, processAudio } from "@revoize/sdk";
import { config as capellaConfig } from "@revoize/model-capella";
// Initialize the SDK first
await initialize(capellaConfig);
// Process audio data in chunks
const audioData = new Array(4800).fill(0.1); // 10 frames of 480 samples each
const chunkSize = 480; // 10ms at 48kHz
const processedChunks: number[][] = [];
try {
for (let i = 0; i < audioData.length; i += chunkSize) {
const chunk = audioData.slice(i, i + chunkSize);
const enhancedChunk = processAudio(chunk);
processedChunks.push(enhancedChunk);
}
const enhancedAudio = processedChunks.flat();
console.log("Enhanced audio has", enhancedAudio.length, "samples");
} catch (error) {
console.error("Processing failed:", error.message);
}isModelInitialized Function
Signature
function isModelInitialized(): booleanChecks whether a model is currently initialized and ready for processing.
Returns
boolean-trueif a model is initialized,falseotherwise.
Example
import { isModelInitialized } from "@revoize/sdk";
if (isModelInitialized()) {
console.log("Model is ready for processing");
} else {
console.log("Please initialize a model first");
}getCurrentModelInfo Function
Signature
function getCurrentModelInfo(): ModelInfo | nullReturns information about the currently initialized model.
Returns
ModelInfo | null- Model information if a model is initialized,nullotherwise.
Example
import { getCurrentModelInfo } from "@revoize/sdk";
const modelInfo = getCurrentModelInfo();
if (modelInfo) {
console.log("Current model:", modelInfo.name);
console.log("Description:", modelInfo.description);
}getCurrentModelName Function
Signature
function getCurrentModelName(): string | nullReturns the name of the currently initialized model.
Returns
string | null- Model name if a model is initialized,nullotherwise.
Example
import { getCurrentModelName } from "@revoize/sdk";
const modelName = getCurrentModelName();
console.log("Current model:", modelName || "No model initialized");cleanup Function
Signature
function cleanup(): voidCleans up resources and resets the SDK state. Call this when you're done using the SDK.
Example
import { cleanup } from "@revoize/sdk";
// When done with the SDK
cleanup();Complete Example
import {
initialize,
processAudio,
isModelInitialized,
getCurrentModelInfo,
cleanup,
} from "@revoize/sdk";
import { config as capellaConfig } from "@revoize/model-capella";
async function processAudioFile(audioData: number[]) {
try {
// Initialize the SDK
await initialize(capellaConfig);
// Verify initialization
if (!isModelInitialized()) {
throw new Error("Failed to initialize model");
}
// Get model information
const modelInfo = getCurrentModelInfo();
console.log("Using model:", modelInfo?.name);
// Process audio in chunks
const chunkSize = 480; // 10ms at 48kHz
const processedChunks: number[][] = [];
for (let i = 0; i < audioData.length; i += chunkSize) {
const chunk = audioData.slice(i, i + chunkSize);
const outputChunk = processAudio(chunk);
processedChunks.push(outputChunk);
}
// Combine processed chunks
const enhancedAudio = processedChunks.flat();
console.log(
"Processing complete. Enhanced audio length:",
enhancedAudio.length,
);
return enhancedAudio;
} catch (error) {
console.error("Error processing audio:", error);
throw error;
} finally {
// Clean up resources
cleanup();
}
}