forked from neosapience/cast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoices.go
More file actions
74 lines (62 loc) · 1.32 KB
/
voices.go
File metadata and controls
74 lines (62 loc) · 1.32 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package client
import (
"encoding/json"
"net/url"
)
type Voice struct {
VoiceID string `json:"voice_id"`
VoiceName string `json:"voice_name"`
Models []VoiceModel `json:"models"`
Gender string `json:"gender"`
Age string `json:"age"`
UseCases []string `json:"use_cases"`
}
type VoiceModel struct {
Version string `json:"version"`
Emotions []string `json:"emotions"`
}
type ListVoicesParams struct {
Model string
Gender string
Age string
UseCase string
}
func (c *Client) ListVoices(p ListVoicesParams) ([]Voice, error) {
q := url.Values{}
if p.Model != "" {
q.Set("model", p.Model)
}
if p.Gender != "" {
q.Set("gender", p.Gender)
}
if p.Age != "" {
q.Set("age", p.Age)
}
if p.UseCase != "" {
q.Set("use_cases", p.UseCase)
}
path := "/v2/voices"
if len(q) > 0 {
path += "?" + q.Encode()
}
data, err := c.get(path)
if err != nil {
return nil, err
}
var voices []Voice
if err := json.Unmarshal(data, &voices); err != nil {
return nil, err
}
return voices, nil
}
func (c *Client) GetVoice(voiceID string) (*Voice, error) {
data, err := c.get("/v2/voices/" + url.PathEscape(voiceID))
if err != nil {
return nil, err
}
var voice Voice
if err := json.Unmarshal(data, &voice); err != nil {
return nil, err
}
return &voice, nil
}