Go
Install
go get github.com/resemble-ai/resemble-go/v2
Usage
Authentication
Before using the library, set your api key.
1
2
3
4
5
6
7
8
9
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
func main() {
client := resemble.NewClient("YOUR_API_TOKEN")
}
Now you're ready! All the examples below can be found here.
Projects
Get all projects
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
projects, err := client.Project.All(1)
if err != nil {
panic(err)
}
fmt.Printf("%+v \n", projects.Items)
Create a project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
project, err := client.Project.Create(request.Payload{
"name": "Project 1",
"description": "project description",
"is_public": false,
"is_collaborative": false,
"is_archived": false,
})
if err != nil {
panic(err)
}
uuid := project.Item.UUID
Update a project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
project, err = client.Project.Update(uuid, request.Payload{
"name": "Project 1",
"description": "project update description",
"is_public": false,
"is_collaborative": false,
"is_archived": false,
})
if err != nil {
panic(err)
}
fmt.Println(project.Item.Description)
Get a project
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
project, err = client.Project.Get(uuid)
if err != nil {
panic(err)
}
fmt.Println(project.Item.Name)
Delete a project
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
message, err := client.Project.Delete(uuid)
if err != nil {
panic(err)
}
fmt.Println(message.Success)
Voices
Get all voices
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
voices, err := client.Voice.All(1)
if err != nil {
panic(err)
}
fmt.Printf("%+v
", voices.Items)
Create a voice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
voice, err := client.Voice.Create(request.Payload{
"name": "test voide",
"dataset_url": "https://../dataset.zip",
"callback_uri": "http://example.com/cb"
})
if err != nil {
panic(err)
}
fmt.Println(voice.Item.UUID)
uuid := voice.Item.UUID
Build a voice
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
message, err := client.Voice.Build(uuid)
if err != nil {
panic(err)
}
fmt.Println(message.Success)
Get a voice
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
voice, err = client.Voice.Get(uuid)
if err != nil {
panic(err)
}
fmt.Println(voice.Item.Name)
Delete a voice
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
message, err := client.Voice.Delete(uuid)
if err != nil {
panic(err)
}
fmt.Println(message.Success)
Recordings
Get all recordings
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
r, err = client.Recording.Get(voiceUUId, r.Item.UUID)
if err != nil {
panic(err)
}
fmt.Printf("%+v \n", r)
Create a recording
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
recordingFile, err := filepath.Abs("./spec_sample_audio.wav")
if err != nil {
panic(err)
}
r, err := client.Recording.Create(voiceUUId, recordingFile, request.Payload{
"name": "test recording",
"text": "transcription",
"is_active": true,
"emotion": "neutral",
})
if err != nil {
panic(err)
}
fmt.Printf("%+v \n", r)
Update a recording
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
r, err = client.Recording.Update(voiceUUId, r.Item.UUID, request.Payload{
"name": "test update recording",
"text": "new transcription",
"is_active": true,
"emotion": "neutral",
})
if err != nil {
panic(err)
}
fmt.Printf("%+v \n", r)
Get a recording
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
r, err = client.Recording.Get(voiceUUId, r.Item.UUID)
if err != nil {
panic(err)
}
fmt.Printf("%+v \n", r)
Delete a recording
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
m, err := client.Recording.Delete(voiceUUId, r.Item.UUID)
if err != nil {
panic(err)
}
fmt.Println(m.Success)
Clips
Get all clips
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
clip, err = client.Clip.Get(projectUUID, clip.Item.UUID)
if err != nil {
panic(err)
}
fmt.Println(clip.Success)
Create a clip (sync)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
clip, err := client.Clip.CreateSync(projectUUID, request.Payload{
"body": "this is test.",
"voice_uuid": voiceUUID,
})
if err != nil {
panic(err)
}
fmt.Println(clip.Success)
Create a clip (async)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
clip2, err := client.Clip.CreateAsync(projectUUID, callbackUrl, request.Payload{
"voice_uuid": voiceUUID,
"body": "test async.",
})
if err != nil {
panic(err)
}
fmt.Printf("%+v \n", clip2)
Create a clip (streaming)
Don't forget to set your synth server URL!
1
client.SetSyncServerUrl("YOUR_STREAMING_ENDPOINT")
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
// helper type
type WavFile struct {
Data []byte `json:"data"`
}
body := "This is a streaming test."
cMeta, cChunk, cDone, cErr := client.Clip.Stream(request.Payload{
"voice_uuid": voiceUUID,
"project_uuid": projectUUID,
"data": body,
})
for {
select {
// receive error. print error then exit
case err := <-cErr:
log.Fatal(err)
// receive metadata
case meta := <-cMeta:
b, _ := json.Marshal(meta)
fmt.Println(string(b))
// receive chunk
case chunk := <-cChunk:
fmt.Println("chunk size", len(chunk))
// receive done signal. exit
case <-cDone:
return
}
}
Update a clip (async)
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
clip, err = client.Clip.UpdateAsync(projectUUID, clip.Item.UUID, callbackUrl, request.Payload{"body": "test update.", "voice_uuid": voiceUUID})
if err != nil {
panic(err)
}
fmt.Println(clip.Success)
Get a clip
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
clip, err = client.Clip.Get(projectUUID, clip.Item.UUID)
if err != nil {
panic(err)
}
fmt.Println(clip.Success)
Delete a clip
1
2
3
4
5
6
7
8
9
10
11
12
13
import (
"github.com/resemble-ai/resemble-go/v2"
"github.com/resemble-ai/resemble-go/v2/request"
"github.com/resemble-ai/resemble-go/v2/response"
)
client := resemble.NewClient("YOUR_API_TOKEN")
m, err := client.Clip.Delete(projectUUID, clip.Item.UUID)
if err != nil {
panic(err)
}
fmt.Println(m.Success)