Skip to main content
Version: 2.0.0

Node

Install

npm install @resemble/node

Usage

Authentication

Before using the library, set your api key.

1 2 3 import { Resemble } from '@resemble/node' // If you are using es modules // const { Resemble } = require('@resemble/node') // If you are using commonjs Resemble.setApiKey('YOUR_API_TOKEN')

Projects

Get all projects

1 2 3 4 5 6 7 8 9 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') let page = 1 let pageSize = 10 const response = await Resemble.v2.projects.all(page, pageSize) const projects = response.items

Create a project

1 2 3 4 5 6 7 8 9 10 11 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.projects.create({ name: "Cooking Podcast", description: "Clips generated for our Thursday night cooking podcast", is_public: false, is_collaborative: true, is_archived: false })

Update a project

1 2 3 4 5 6 7 8 9 10 11 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.projects.update(projectUuid, { name: "Friday Night Cooking Podcast", description: "Clips generated for the podcast", is_public: true, is_collaborative: true, is_archived: false })

Get a project

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.projects.get(projectUuid)

Delete a project

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.projects.delete(projectUuid)

Voices

Get all voices

1 2 3 4 5 6 7 8 9 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const page = 1 const pageSize = 10 const response = await Resemble.v2.voices.all(page, pageSize) const voices = response.items

Create a voice

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.voices.create({ name: "Chef", dataset_url: "https://../dataset.zip", callback_uri: "http://example.com/cb" })

Build a voice

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.voices.build(voiceUuid)

Get a voice

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.voices.get(voiceUuid)

Delete a voice

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.voices.delete(voiceUuid)

Recordings

Get all recordings

1 2 3 4 5 6 7 8 9 10 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const voiceUuid = '...' const page = 1 const pageSize = 10 const response = await Resemble.v2.recordings.all(voiceUuid, page, pageSize) const recordings = response.items

Create a recording

1 2 3 4 5 6 7 8 9 10 11 12 13 14 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const fs = require('fs') const file = fs.createReadStream('happy_sample.wav') const fileSize = fs.statSync('happy_sample.wav').size await Resemble.v2.recordings.create(voiceUuid, { emotion: 'happy', is_active: true, name: 'happy_sample', text: 'Hey, this is a happy sample!' }, file, fileSize)

Update a recording

1 2 3 4 5 6 7 8 9 10 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.recordings.update(voiceUuid, { emotion: 'happy', is_active: false, name: 'happy_sample', text: 'Hey, this is a happy sample!' })

Get a recording

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.recordings.get(voiceUuid, recordingUuid)

Delete a recording

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.recordings.delete(voiceUuid, recordingUuid)

Clips

Get all clips

1 2 3 4 5 6 7 8 9 10 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const projectUuid = '..' const page = 1 const pageSize = 10 const response = await Resemble.v2.clips.all(projectUuid, page, pageSize) const clips = response.items

Create a clip (sync)

1 2 3 4 5 6 7 8 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const response = await Resemble.v2.clips.createSync(projectUuid, { body: 'This audio was synthesized', voice_uuid: 'my_voice_uuid' })

Create a clip (async)

1 2 3 4 5 6 7 8 9 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.clips.createAsync(projectUuid, { body: 'This audio was synthesized ', voice_uuid: 'my_voice_uuid', callback_uri: 'https://...' })

Create a clip (streaming)

Signature:

  stream: async function* (
streamInput: {
data: string
project_uuid: string
voice_uuid: string
sample_rate?: 8000 | 16000 | 22050 | 44100 | 32000
precision?: 'MULAW' | 'PCM_16' | 'PCM_24' | 'PCM_32'
},
streamConfig?: {
bufferSize?: number
ignoreWavHeader?: boolean
getTimeStamps?: boolean
} // Optional parameter and any prop not passed is taken from the default stream config:
): AsyncGenerator

// default stream config:
const defaultStreamConfig = {
bufferSize: DEFAULT_BUFFER_SIZE, // 4 * 1024
ignoreWavHeader: false,
getTimeStamps: false,
}

Usage:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import { Resemble } from '@resemble/node' // NOTE: this example uses ES Modules, modify accordingly if you are using CommonJS // It's very important that you configure the resemble library with the synServerUrl option. Streaming will not // work otherwise. You can obtain this URL by contacting resemble. Resemble.setApiKey('YOUR_API_TOKEN') Resemble.setSynthesisUrl('YOUR_SYNTH_ENDPOINT') const projectUuid = '<project_uuid>' const voiceUuid = '<voice_uuid>' try { for await (const chunk of Resemble.v2.clips.stream( { data: 'This is a streaming test', project_uuid: projectUuid, voice_uuid: voiceUuid, }, { getTimeStamps: true, }, )) { const { data, timestamps } = chunk if (data) { // The data variable is a byte array representing a chunk of a WAV audio file. console.log(data) } if (timestamps) { console.log(timestamps) } } } catch (e) { // Handle errors here }

Update a clip (async)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.clips.updateAsync(projectUuid, clipUuid, { voice_uuid: voiceUuid, body: 'This is an updated async test', callback_uri: 'https://example.com/callback/resemble-clip', title: undefined, sample_rate: undefined, output_format: undefined, precision: undefined, include_timestamps: undefined, is_public: undefined, is_archived: undefined, })

Get a clip

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.clips.delete(projectUuid, clipUuid)

Delete a clip

1 2 3 4 5 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') await Resemble.v2.clips.delete(projectUuid, clipUuid)

Phoneme

Get all phonemes

1 2 3 4 5 6 7 8 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const page = 1 const pageSize = 10 # optional parameter const response = Resemble.v2.phonemes.all(page, page_size) const phonemes = response.items

Create a phoneme

1 2 3 4 5 6 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const response = Resemble.v2.phonemes.create('Vodaphone', 'Voduhphone') const phoneme = response.item

Get a phoneme

1 2 3 4 5 6 7 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const phonemeUuid = '...' const response = Resemble.v2.phonemes.get(phonemeUuid) const phoneme = response.item

Delete a phoneme

1 2 3 4 5 6 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const phonemeUuid = '...' Resemble.v2.phonemes.delete(phonemeUuid)

Term Substitution

Get all term substitutions

1 2 3 4 5 6 7 8 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const page = 1 const pageSize = 10 # optional parameter const response = Resemble.v2.termSubstitutions.all(page, page_size) const substitutions = response.items

Create a term substitution

1 2 3 4 5 6 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const response = Resemble.v2.termSubstitutions.create('Original', 'Replacement') const substitution = response.item

Get a term substitution

1 2 3 4 5 6 7 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const tsUuid = '...' const response = Resemble.v2.termSubstitutions.get(tsUuid) const substitution = response.item

Delete a term substitution

1 2 3 4 5 6 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const substitutionUuid = '...' Resemble.v2.termSubstitutions.delete(substitutionUuid)

Batch

Get all batches

1 2 3 4 5 6 7 8 9 10 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const projectUuid = '..' const page = 1 const pageSize = 10 // optional parameter const response = await Resemble.v2.batch.all(projectUuid, page, pageSize) const batches = response.items

Create a batch

Without title for each clip

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const projectUuid = '..' const voiceUuid = '..' // you can pass an additional options object as the last parameter with following structure. each option is optional // refer https://docs.app.resemble.ai/docs/generate_speech/action_synthesize/resource_batch/create for more info // const options = { // callbackUri: <CALLBACK_URI> // precision: 'PCM_32' | 'PCM_24' | 'PCM_16' | 'MULAW' // sampleRate: 8000 | 16000 | 22050 | 44100 // outputFormat: 'wav' | 'mp3' // } const res = await Resemble.v2.batch.create( projectUuid, voiceUuid, ['Content A', 'Content B', 'Content C'], options )

With title for each clip

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const projectUuid = '..' const voiceUuid = '..' // you can pass an additional options object as the last parameter with following structure. each option is optional // refer https://docs.app.resemble.ai/docs/generate_speech/action_synthesize/resource_batch/create for more info // const options = { // callbackUri: <CALLBACK_URI> // precision: 'PCM_32' | 'PCM_24' | 'PCM_16' | 'MULAW' // sampleRate: 8000 | 16000 | 22050 | 44100 // outputFormat: 'wav' | 'mp3' // } const res = await Resemble.v2.batch.create( projectUuid, voiceUuid, [["Title A", "Content A"], ["Title B", "Content B"], ["Title C", "Content C"]], options )

Get a batch

1 2 3 4 5 6 7 8 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const projectUuid = '..' const batchUuid = '..' const res = await Resemble.v2.batch.get(projectUuid, batchUuid)

Delete a batch

1 2 3 4 5 6 7 8 import { Resemble } from '@resemble/node' Resemble.setApiKey('YOUR_API_TOKEN') const projectUuid = '..' const batchUuid = '..' const res = await Resemble.v2.batch.delete( projectUuid, batchUuid)