forked from neosapience/cast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoices_clone.go
More file actions
80 lines (68 loc) · 1.95 KB
/
Copy pathvoices_clone.go
File metadata and controls
80 lines (68 loc) · 1.95 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
75
76
77
78
79
80
package cmd
import (
"encoding/json"
"fmt"
"os"
"strings"
"github.com/neosapience/cast/internal/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var voicesCloneCmd = &cobra.Command{
Use: "clone <audio_file>",
Short: "Clone a voice from a WAV or MP3 sample",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name, _ := cmd.Flags().GetString("name")
model, _ := cmd.Flags().GetString("model")
asJSON, _ := cmd.Flags().GetBool("json")
c := newTypecastClient()
voice, err := c.CloneVoice(client.CloneVoiceRequest{
Name: name,
Model: model,
AudioFilePath: args[0],
})
if err != nil {
return err
}
if asJSON {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
return enc.Encode(voice)
}
fmt.Println(voice.VoiceID)
return nil
},
}
var voicesDeleteCmd = &cobra.Command{
Use: "delete <voice_id>",
Short: "Delete a quick-cloned voice",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
voiceID := args[0]
if !strings.HasPrefix(voiceID, "uc_") {
return fmt.Errorf("only cloned voice IDs that start with 'uc_' can be deleted")
}
c := newTypecastClient()
if err := c.DeleteClonedVoice(voiceID); err != nil {
return err
}
fmt.Fprintf(os.Stderr, "deleted %s\n", voiceID)
return nil
},
}
func newTypecastClient() *client.Client {
baseURL := viper.GetString("base_url")
if baseURL != "" {
return client.NewWithBaseURL(viper.GetString("api_key"), baseURL)
}
return client.New(viper.GetString("api_key"))
}
func init() {
voicesCloneCmd.Flags().String("name", "", "Display name for the cloned voice (1-30 characters)")
_ = voicesCloneCmd.MarkFlagRequired("name")
voicesCloneCmd.Flags().String("model", defaultModel, "Voice cloning model (ssfm-v30)")
voicesCloneCmd.Flags().Bool("json", false, "Output clone response as JSON")
voicesCmd.AddCommand(voicesCloneCmd)
voicesCmd.AddCommand(voicesDeleteCmd)
}