Quickstart
Get up and running in under 5 minutes.
Install the SDK
bun add sonuslab
npm install sonuslab
pnpm add sonuslab
Get your API key
Sign in to the dashboard and create an API key. Keys start with sl_live_.
Create a client
import { SonusLab } from 'sonuslab'
const sonus = new SonusLab('sl_live_...')
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)
metadata is { title, duration, thumbnail }. clip is { id, name, audioKey, audioUrl, duration, sourceUrl, createdAt }.
Generate speech
const { sound, error } = await sonus.tts.generate({
text: 'Hello from SonusLab!',
voiceId: 'voice_id_here',
})
if (error) throw error
console.log(sound.audioUrl)
sound is { id, name, audioKey, 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,
})
sample is { audio, format, sampleRate }.
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)
The SDK retries on
429 and 5xx errors up to 2 times with exponential backoff. Check your usage in the dashboard.