SonusLabSonusLab

Quickstart

Get up and running in under 5 minutes.

1

Install the SDK

bun add sonuslab
2

Get your API key

Sign in to the dashboard and create an API key. Keys start with sl_live_.

3

Create a client

import { SonusLab } from 'sonuslab'

const sonus = new SonusLab('sl_live_...')
4

Make your first request

Clip audio from a video, generate speech, or clone a voice:

Clip audio from a URL
const { metadata } = await sonus.clips.getMetadata({
  url: 'https://example.com/episode.mp3',
})

const { clip, error } = await sonus.clips.create({
  url: 'https://example.com/episode.mp3',
  start: 0,
  end: 10,
  name: 'intro',
})

if (error) throw error

console.log(clip.audioUrl)
Generate speech
const { sound, error } = await sonus.tts.generate({
  text: 'Hello from SonusLab!',
  voiceId: 'voice_id_here',
  provider: 'elevenlabs',
})

if (error) throw error

console.log(sound.audioUrl)
Clone a voice
const { sample } = await sonus.voices.prepareSample({
  url: 'https://example.com/voice-sample.mp3',
})

const { voice } = await sonus.voices.create({
  name: 'My Custom Voice',
  audio: sample.audio,
  format: sample.format,
  sampleRate: sample.sampleRate,
})
5

Handle errors

const { clip, error } = await sonus.clips.create({
  url: 'https://example.com/episode.mp3',
  start: 0,
  end: 10,
  name: 'intro',
})

if (error) {
  console.error(error.status)
  console.error(error.message)
  console.error(error.body)
  return
}

console.log(clip.audioUrl)

Automatic retries

The SDK retries on 429 and 5xx errors up to 2 times with exponential backoff. Check your usage in the dashboard.