-
Notifications
You must be signed in to change notification settings - Fork 0
/
tts.go
117 lines (104 loc) · 4.03 KB
/
tts.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
package omnicron
import (
"context"
"os"
)
// model is ranked from lowest to highest based on their strength and abilites to perform Text To Speech (TTS) generation. Check out the models on replicate.
type ReplicateLowTTSModel string
type ReplicateMediumTTSModel string
type ReplicateHighTTSModel string
const (
// Model on Replicate: https://replicate.com/lucataco/xtts-v2
XTTSV2Model ReplicateLowTTSModel = "lucataco/xtts-v2"
// Model on Replicate: https://replicate.com/zsxkib/realistic-voice-cloning
RealisticVoiceCloningModel ReplicateMediumTTSModel = "zsxkib/realistic-voice-cloning"
// Model on Replicate: https://replicate.com/chenxwh/openvoice
OpenVoiceModel ReplicateHighTTSModel = "chenxwh/openvoice"
)
type LowTTSParams struct {
Text string `form:"text"`
Speaker *os.File `form:"speaker"`
Language *string `form:"language,omitempty"`
CleanupVoice *bool `form:"cleanup_voice,omitempty"`
}
type MediumTTSParams struct {
SongInput *os.File `form:"song_input"`
RvcModel *string `form:"rvc_model,omitempty"`
CustomRvcModelDownloadURL *string `form:"custom_rvc_model_download_url,omitempty"`
PitchChange *string `form:"pitch_change,omitempty"`
IndexRate *float64 `form:"index_rate,omitempty"`
FilterRaidus *int `form:"filter_raidus,omitempty"`
RmsMixRate *float64 `form:"rms_mix_rate,omitempty"`
PitchDetectionAlgorithm *string `form:"pitch_detection_algorithm,omitempty"`
CrepeHopLength *int `form:"crepe_hop_length,omitempty"`
Protect *float64 `form:"protect,omitempty"`
MainVocalsVolumeChange *float64 `form:"main_vocals_volume_change,omitempty"`
BackupVocalsVolumeChange *float64 `form:"backup_vocals_volume_change,omitempty"`
InstrumentalVolumeChange *float64 `form:"instrumental_volume_change,omitempty"`
PitchChangeAll *float64 `form:"pitch_change_all,omitempty"`
ReverbSize *float64 `form:"reverb_size,omitempty"`
ReverbWetness *float64 `form:"reverb_wetness,omitempty"`
ReverbDryness *float64 `form:"reverb_dryness,omitempty"`
ReverbDamping *float64 `form:"reverb_damping,omitempty"`
OutputFormat *string `form:"output_format,omitempty"`
}
type HighTTSParams struct {
Audio *os.File `form:"audio"`
Text string `form:"text"`
Language *string `form:"language,omitempty"`
Speed *float64 `form:"speed,omitempty"`
}
type LowTTSModelAndParams struct {
Model ReplicateLowTTSModel
Parameters LowTTSParams
}
type MediumTTSModelAndParams struct {
Model ReplicateMediumTTSModel
Parameters MediumTTSParams
}
type HighTTSModelAndParams struct {
Model ReplicateHighTTSModel
Parameters HighTTSParams
}
func (c *Client) LowTTSGeneration(ctx context.Context, req LowTTSModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
body, err := c.newFormWithFilePostRequest(ctx, "/replicate/tts", string(req.Model), req.Parameters)
if err != nil {
return nil, err
}
lowTTSGenResponse, err := unmarshalJSONResponse(body)
if err != nil {
return nil, err
}
return lowTTSGenResponse, nil
}
func (c *Client) MediumTTSGeneration(ctx context.Context, req MediumTTSModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
body, err := c.newFormWithFilePostRequest(ctx, "/replicate/tts", string(req.Model), req.Parameters)
if err != nil {
return nil, err
}
mediumTTSGenResponse, err := unmarshalJSONResponse(body)
if err != nil {
return nil, err
}
return mediumTTSGenResponse, nil
}
func (c *Client) HighTTSGeneration(ctx context.Context, req HighTTSModelAndParams) (*GabsContainer, error) {
if req.Model == "" {
return nil, ErrModelNotFound
}
body, err := c.newFormWithFilePostRequest(ctx, "/replicate/tts", string(req.Model), req.Parameters)
if err != nil {
return nil, err
}
highTTSGenResponse, err := unmarshalJSONResponse(body)
if err != nil {
return nil, err
}
return highTTSGenResponse, nil
}