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 const Resemble = require('@resemble/node') const resemble = new Resemble('v2', '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)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 const Resemble = require('@resemble/node') // 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. const synServerUrl = 'YOUR_SYNTH_ENDPOINT' const resemble = new Resemble('v2', 'YOUR_API_TOKEN', { synServerUrl: synServerUrl }) const projectUuid = '<project_uuid>' const voiceUuid = '<voice_uuid>' try { for await (const chunk of resemble.clips.stream({ data: 'This is a streaming test', project_uuid: projectUuid, voice_uuid: voiceUuid, })) { // handle the returned chunk of data contained in the chunk variable // The chunk variable is a byte array of shorts (int 16) representing a chunk of a WAV audio file. } } 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)