forked from haguro/elevenlabs-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.go
286 lines (255 loc) · 11 KB
/
models.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
package elevenlabs
import (
"bytes"
"encoding/json"
"fmt"
"io"
"mime/multipart"
"os"
"path/filepath"
)
type Language struct {
LanguageId string `json:"language_id"`
Name string `json:"name"`
}
type Model struct {
CanBeFineTuned bool `json:"can_be_finetuned"`
CanDoTextToSpeech bool `json:"can_do_text_to_speech"`
CanDoVoiceConversion bool `json:"can_do_voice_conversion"`
CanUseSpeakerBoost bool `json:"can_use_speaker_boost"`
CanUseStyle bool `json:"can_use_style"`
Description string `json:"description"`
Languages []Language `json:"languages"`
MaxCharactersRequestFreeUser int `json:"max_characters_request_free_user"`
MaxCharactersRequestSubscribedUser int `json:"max_characters_request_subscribed_user"`
ModelId string `json:"model_id"`
Name string `json:"name"`
RequiresAlphaAccess bool `json:"requires_alpha_access"`
ServesProVoices bool `json:"serves_pro_voices"`
TokenCostFactor float32 `json:"token_cost_factor"`
}
type TextToSpeechRequest struct {
Text string `json:"text"`
ModelID string `json:"model_id,omitempty"`
VoiceSettings *VoiceSettings `json:"voice_settings,omitempty"`
}
type GenerationConfig struct {
ChunkLengthSchedule []int `json:"chunk_length_schedule"`
}
type TextToSpeechInputStreamingRequest struct {
Text string `json:"text"`
TryTriggerGeneration bool `json:"try_trigger_generation"`
VoiceSettings *VoiceSettings `json:"voice_settings,omitempty"`
GenerationConfig *GenerationConfig `json:"generation_config,omitempty"`
}
type GetVoicesResponse struct {
Voices []Voice `json:"voices"`
}
type AddVoiceResponse struct {
VoiceId string `json:"voice_id"`
}
type Voice struct {
AvailableForTiers []string `json:"available_for_tiers"`
Category string `json:"category"`
Description string `json:"description"`
FineTuning FineTuning `json:"fine_tuning"`
HighQualityBaseModelIds []string `json:"high_quality_base_model_ids"`
Labels map[string]string `json:"labels"`
Name string `json:"name"`
PreviewUrl string `json:"preview_url"`
Samples []VoiceSample `json:"samples"`
Settings VoiceSettings `json:"settings,omitempty"`
Sharing VoiceSharing `json:"sharing"`
VoiceId string `json:"voice_id"`
}
type VoiceSettings struct {
SimilarityBoost float32 `json:"similarity_boost"`
Stability float32 `json:"stability"`
Style float32 `json:"style,omitempty"`
SpeakerBoost bool `json:"use_speaker_boost,omitempty"`
}
type VoiceSharing struct {
ClonedByCount int `json:"cloned_by_count"`
DateUnix int `json:"date_unix"`
Description string `json:"description"`
DisableAtUnix bool `json:"disable_at_unix"`
EnabledInLibrary bool `json:"enabled_in_library"`
FinancialRewardEnabled bool `json:"financial_reward_enabled"`
FreeUsersAllowed bool `json:"free_users_allowed"`
HistoryItemSampleId string `json:"history_item_sample_id"`
Labels map[string]string `json:"labels"`
LikedByCount int `json:"liked_by_count"`
LiveModerationEnabled bool `json:"live_moderation_enabled"`
Name string `json:"name"`
NoticePeriod int `json:"notice_period"`
OriginalVoiceId string `json:"original_voice_id"`
PublicOwnerId string `json:"public_owner_id"`
Rate float32 `json:"rate"`
ReviewMessage string `json:"review_message"`
ReviewStatus string `json:"review_status"`
Status string `json:"status"`
VoiceMixingAllowed bool `json:"voice_mixing_allowed"`
WhitelistedEmails []string `json:"whitelisted_emails"`
}
type VoiceSample struct {
FileName string `json:"file_name"`
Hash string `json:"hash"`
MimeType string `json:"mime_type"`
SampleId string `json:"sample_id"`
SizeBytes int `json:"size_bytes"`
}
type FineTuning struct {
FineTuningRequested bool `json:"fine_tuning_requested"`
FineTuningState string `json:"finetuning_state"`
IsAllowedToFineTune bool `json:"is_allowed_to_fine_tune"`
Language string `json:"language"`
ManualVerification ManualVerification `json:"manual_verification"`
ManualVerificationRequested bool `json:"manual_verification_requested"`
SliceIds []string `json:"slice_ids"`
VerificationAttempts []VerificationAttempt `json:"verification_attempts"`
VerificationAttemptsCount int `json:"verification_attempts_count"`
VerificationFailures []string `json:"verification_failures"`
}
type ManualVerification struct {
ExtraText string `json:"extra_text"`
Files []File `json:"files"`
RequestTimeUnix int `json:"request_time_unix"`
}
type File struct {
FileId string `json:"file_id"`
FileName string `json:"file_name"`
MimeType string `json:"mime_type"`
SizeBytes int `json:"size_bytes"`
UploadDateUnix int `json:"upload_date_unix"`
}
type VerificationAttempt struct {
Accepted bool `json:"accepted"`
DateUnix int `json:"date_unix"`
LevenshteinDistance float32 `json:"levenshtein_distance"`
Recording Recording `json:"recording"`
Similarity float32 `json:"similarity"`
Text string `json:"text"`
}
type Recording struct {
MimeType string `json:"mime_type"`
RecordingId string `json:"recording_id"`
SizeBytes int `json:"size_bytes"`
Transcription string `json:"transcription"`
UploadDateUnix int `json:"upload_date_unix"`
}
type DownloadHistoryRequest struct {
HistoryItemIds []string `json:"history_item_ids"`
}
type GetHistoryResponse struct {
History []HistoryItem `json:"history"`
LastHistoryItemId string `json:"last_history_item_id"`
HasMore bool `json:"has_more"`
}
type HistoryItem struct {
CharacterCountChangeFrom int `json:"character_count_change_from"`
CharacterCountChangeTo int `json:"character_count_change_to"`
ContentType string `json:"content_type"`
DateUnix int `json:"date_unix"`
Feedback Feedback `json:"feedback"`
HistoryItemId string `json:"history_item_id"`
ModelId string `json:"model_id"`
RequestId string `json:"request_id"`
Settings VoiceSettings `json:"settings"`
ShareLinkId string `json:"share_link_id"`
State string `json:"state"`
Text string `json:"text"`
VoiceCategory string `json:"voice_category"`
VoiceId string `json:"voice_id"`
VoiceName string `json:"voice_name"`
}
type Feedback struct {
AudioQuality bool `json:"audio_quality"`
Emotions bool `json:"emotions"`
Feedback string `json:"feedback"`
Glitches bool `json:"glitches"`
InaccurateClone bool `json:"inaccurate_clone"`
Other bool `json:"other"`
ReviewStatus *string `json:"review_status,omitempty"`
ThumbsUp bool `json:"thumbs_up"`
}
type Subscription struct {
AllowedToExtendCharacterLimit bool `json:"allowed_to_extend_character_limit"`
CanExtendCharacterLimit bool `json:"can_extend_character_limit"`
CanExtendVoiceLimit bool `json:"can_extend_voice_limit"`
CanUseInstantVoiceCloning bool `json:"can_use_instant_voice_cloning"`
CanUseProfessionalVoiceCloning bool `json:"can_use_professional_voice_cloning"`
CharacterCount int `json:"character_count"`
CharacterLimit int `json:"character_limit"`
Currency string `json:"currency"`
NextCharacterCountResetUnix int `json:"next_character_count_reset_unix"`
VoiceLimit int `json:"voice_limit"`
ProfessionalVoiceLimit int `json:"professional_voice_limit"`
Status string `json:"status"`
Tier string `json:"tier"`
MaxVoiceAddEdits int `json:"max_voice_add_edits"`
VoiceAddEditCounter int `json:"voice_add_edit_counter"`
HasOpenInvoices bool `json:"has_open_invoices"`
NextInvoice Invoice `json:"next_invoice"`
withInvoicingDetails bool
}
type Invoice struct {
AmountDueCents int `json:"amount_due_cents"`
NextPaymentAttemptUnix int `json:"next_payment_attempt_unix"`
}
type User struct {
Subscription Subscription `json:"subscription"`
FirstName string `json:"first_name,omitempty"`
IsNewUser bool `json:"is_new_user"`
IsOnboardingComplete bool `json:"is_onboarding_complete"`
XiApiKey string `json:"xi_api_key"`
CanUseDelayedPaymentMethods bool `json:"can_use_delayed_payment_methods"`
}
type AddEditVoiceRequest struct {
Name string
FilePaths []string
Description string
Labels map[string]string
}
func (r *AddEditVoiceRequest) buildRequestBody() (*bytes.Buffer, string, error) {
var b bytes.Buffer
w := multipart.NewWriter(&b)
buildFailed := func(err error) (*bytes.Buffer, string, error) {
return nil, "", fmt.Errorf("failed to build request body: %w", err)
}
if err := w.WriteField("name", r.Name); err != nil {
return buildFailed(err)
}
if r.Description != "" {
if err := w.WriteField("description", r.Description); err != nil {
return buildFailed(err)
}
}
if len(r.Labels) > 0 {
labelsJson, err := json.Marshal(r.Labels)
if err != nil {
return buildFailed(err)
}
if err := w.WriteField("labels", string(labelsJson)); err != nil {
return buildFailed(err)
}
}
for _, file := range r.FilePaths {
f, err := os.Open(file)
if err != nil {
return buildFailed(err)
}
defer f.Close()
fw, err := w.CreateFormFile("files", filepath.Base(file))
if err != nil {
return buildFailed(err)
}
if _, err = io.Copy(fw, f); err != nil {
return buildFailed(err)
}
}
err := w.Close()
if err != nil {
return buildFailed(err)
}
return &b, w.FormDataContentType(), nil
}