Skip to main content

Function signature

function init(options: {
  apiKeys: string[];
  logger?: Logger;
}): void
Initializes the Tafrigh library with the provided Wit.ai API keys and optional custom logger. You must call this function before using transcribe() or other Tafrigh functions. The API keys are used to authenticate requests to the Wit.ai speech-to-text service.

Parameters

options
object
required
Configuration options for initialization

Returns

void
void
This function does not return a value.

Examples

Basic initialization

import { init } from 'tafrigh';

init({
  apiKeys: ['your-wit-ai-api-key']
});

Multiple API keys for concurrent transcription

import { init } from 'tafrigh';

init({
  apiKeys: [
    'wit-ai-key-1',
    'wit-ai-key-2',
    'wit-ai-key-3'
  ]
});
With multiple API keys, Tafrigh can transcribe audio chunks in parallel, significantly improving performance for large files.

Custom logger

import { init } from 'tafrigh';

const customLogger = {
  debug: (msg: string) => console.debug(`[DEBUG] ${msg}`),
  info: (msg: string) => console.info(`[INFO] ${msg}`),
  warn: (msg: string) => console.warn(`[WARN] ${msg}`),
  error: (msg: string) => console.error(`[ERROR] ${msg}`),
  trace: (msg: string) => console.trace(`[TRACE] ${msg}`)
};

init({
  apiKeys: ['your-wit-ai-api-key'],
  logger: customLogger
});

Using console as logger

import { init } from 'tafrigh';

init({
  apiKeys: ['your-wit-ai-api-key'],
  logger: console
});
The standard console object implements the Logger interface and can be used directly.
You must call init() before using any other Tafrigh functions. Attempting to transcribe without initialization will result in an error.

Build docs developers (and LLMs) love