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
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_collaborative: true,
is_archived: false
})
Update a project
1
2
3
4
5
6
7
8
9
10
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_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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { Resemble } from '@resemble/node'
Resemble.setApiKey('YOUR_API_TOKEN')
Resemble.setSynthesisUrl('https://f.cluster.resemble.ai')
const response = await Resemble.v2.clips.createDirect({
voice_uuid: '<voice_uuid>',
project_uuid: '<project_uuid>',
title : '<title>',
data: 'Hello, how are you?',
precision: 'PCM_32',
output_format: 'wav',
sample_rate: 48000
})
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
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_archived: undefined,
})
Get a clip
1
2
3
4
5
import { Resemble } from '@resemble/node'
Resemble.setApiKey('YOUR_API_TOKEN')
await Resemble.v2.clips.get(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)
Audio Edits
Get all audio edits
1
2
3
4
5
6
import { Resemble } from '@resemble/node'
Resemble.setApiKey('YOUR_API_TOKEN')
const page = 1
await Resemble.v2.edits.all(page)
Get an audio edit
1
2
3
4
5
6
import { Resemble } from '@resemble/node'
Resemble.setApiKey('YOUR_API_TOKEN')
const audioEditUuid = '...'
await Resemble.v2.edits.get(audioEditUuid)
Create an audio edit
1
2
3
4
5
6
7
8
9
10
11
12
13
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.edits.create({
original_transcript: 'I am happy today',
target_transcript: 'You are happy today',
voice_uuid: '<voice_uuid>',
},file, fileSize)
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)