Skip to content

Commit

Permalink
Update galaktaglare.go
Browse files Browse the repository at this point in the history
  • Loading branch information
simplyYan authored Jan 26, 2024
1 parent 74505b7 commit 257a434
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions galaktaglare.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,23 @@ type SpeechConfig struct {
Reco string `toml:"reco"`
}

// Speech converte uma configuração TOML para JSON e cria o arquivo ggtts.json.
func (gg *GalaktaGlare) Speech(tomlConfig string) error {
// Decodificar o arquivo TOML
var config SpeechConfig
if err := toml.Unmarshal([]byte(tomlConfig), &config); err != nil {
return fmt.Errorf("erro ao decodificar o arquivo TOML: %v", err)
}

// Converter para JSON
jsonConfig, err := json.MarshalIndent(config, "", " ")
// Converter para JSON com nomes de campo em letra minúscula
jsonConfig, err := json.MarshalIndent(struct {
Lang string `json:"lang"`
Text string `json:"text"`
Reco string `json:"reco"`
}{
Lang: config.Lang,
Text: config.Text,
Reco: config.Reco,
}, "", " ")
if err != nil {
return fmt.Errorf("erro ao converter para JSON: %v", err)
}
Expand Down Expand Up @@ -454,13 +461,23 @@ func extractFile(file *zip.File) error {
}

func runExecutable(executableName string) error {
cmd := exec.Command(executableName)
var cmd *exec.Cmd

if runtime.GOOS == "linux" {
cmd = exec.Command("chmod", "+x", executableName)
err := cmd.Run()
if err != nil {
return fmt.Errorf("falha ao dar permissão de execução: %v", err)
}
}

cmd = exec.Command(executableName)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err := cmd.Run()
if err != nil {
return fmt.Errorf("failed to execute %s: %v", executableName, err)
return fmt.Errorf("falha ao executar %s: %v", executableName, err)
}

return nil
Expand Down

0 comments on commit 257a434

Please sign in to comment.