-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaudio_voices.go
135 lines (122 loc) · 3.6 KB
/
audio_voices.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package coze
import (
"context"
"fmt"
"io"
"net/http"
"strconv"
)
func (r *audioVoices) Clone(ctx context.Context, req *CloneAudioVoicesReq) (*CloneAudioVoicesResp, error) {
path := "/v1/audio/voices/clone"
if req.File == nil {
return nil, fmt.Errorf("file is required")
}
fields := map[string]string{
"voice_name": req.VoiceName,
"audio_format": req.AudioFormat.String(),
}
// Add other fields
if req.Language != nil {
fields["language"] = req.Language.String()
}
if req.VoiceID != nil {
fields["voice_id"] = *req.VoiceID
}
if req.PreviewText != nil {
fields["preview_text"] = *req.PreviewText
}
if req.Text != nil {
fields["text"] = *req.Text
}
if req.Description != nil {
fields["description"] = *req.Description
}
if req.SpaceID != nil {
fields["space_id"] = *req.SpaceID
}
resp := &cloneAudioVoicesResp{}
if err := r.core.UploadFile(ctx, path, req.File, req.VoiceName, fields, resp); err != nil {
return nil, err
}
resp.Data.setHTTPResponse(resp.HTTPResponse)
return resp.Data, nil
}
func (r *audioVoices) List(ctx context.Context, req *ListAudioVoicesReq) (NumberPaged[Voice], error) {
if req.PageSize == 0 {
req.PageSize = 20
}
if req.PageNum == 0 {
req.PageNum = 1
}
return NewNumberPaged[Voice](
func(request *pageRequest) (*pageResponse[Voice], error) {
uri := "/v1/audio/voices"
resp := &ListAudioVoicesResp{}
err := r.core.Request(ctx, http.MethodGet, uri, nil, resp,
withHTTPQuery("page_num", strconv.Itoa(request.PageNum)),
withHTTPQuery("page_size", strconv.Itoa(request.PageSize)),
withHTTPQuery("filter_system_voice", strconv.FormatBool(req.FilterSystemVoice)))
if err != nil {
return nil, err
}
return &pageResponse[Voice]{
HasMore: len(resp.Data.VoiceList) >= request.PageSize,
Data: resp.Data.VoiceList,
LogID: resp.HTTPResponse.LogID(),
}, nil
}, req.PageSize, req.PageNum)
}
type audioVoices struct {
core *core
}
func newVoice(core *core) *audioVoices {
return &audioVoices{core: core}
}
// Voice represents the voice model
type Voice struct {
VoiceID string `json:"voice_id"`
Name string `json:"name"`
IsSystemVoice bool `json:"is_system_voice"`
LanguageCode string `json:"language_code"`
LanguageName string `json:"language_name"`
PreviewText string `json:"preview_text"`
PreviewAudio string `json:"preview_audio"`
AvailableTrainingTimes int `json:"available_training_times"`
CreateTime int `json:"create_time"`
UpdateTime int `json:"update_time"`
}
// CloneAudioVoicesReq represents the request for cloning a voice
type CloneAudioVoicesReq struct {
VoiceName string
File io.Reader
AudioFormat AudioFormat
Language *LanguageCode
VoiceID *string
PreviewText *string
Text *string
SpaceID *string
Description *string
}
// cloneAudioVoicesResp represents the response for cloning a voice
type cloneAudioVoicesResp struct {
baseResponse
Data *CloneAudioVoicesResp `json:"data"`
}
// CloneAudioVoicesResp represents the response for cloning a voice
type CloneAudioVoicesResp struct {
baseModel
VoiceID string `json:"voice_id"`
}
// ListAudioVoicesReq represents the request for listing voices
type ListAudioVoicesReq struct {
FilterSystemVoice bool `json:"filter_system_voice,omitempty"`
PageNum int `json:"page_num"`
PageSize int `json:"page_size"`
}
// ListAudioVoicesResp represents the response for listing voices
type ListAudioVoicesResp struct {
baseResponse
Data struct {
VoiceList []*Voice `json:"voice_list"`
} `json:"data"`
}