i fucking hope multiple return values aren't good Go practices
createAudio send a mp3 file created with espeak
This commit is contained in:
@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
@ -33,19 +34,21 @@ func MessageAudio(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
var prefix string = "/gogodisco audio"
|
||||
if strings.HasPrefix(m.Content, prefix) {
|
||||
var message string = strings.TrimLeft(m.Content, prefix)
|
||||
createAudio(message)
|
||||
_, _, filename := createAudio(message)
|
||||
// func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (*Message, error)
|
||||
file, _ := os.Open(filename)
|
||||
s.ChannelFileSend(m.ChannelID, filename, file)
|
||||
}
|
||||
}
|
||||
|
||||
func createAudio(msg string) ([]byte, error){
|
||||
func createAudio(msg string) ([]byte, error, string){
|
||||
curr_time := time.Now().Unix()
|
||||
var filename string = fmt.Sprintf("/tmp/%d.mp3", curr_time)
|
||||
fmt.Println(filename)
|
||||
var cmd_args string = fmt.Sprintf("-s 120 -v mb-fr2 -p 30 '%s'", msg)
|
||||
cmd := exec.Command("espeak-ng", cmd_args)
|
||||
var cmd_args string = fmt.Sprintf("espeak-ng -s 120 -v mb-fr2 -p 30 %q -w %s", msg, filename)
|
||||
cmd := exec.Command("sh","-c", cmd_args)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprint(err) + ": " + string(out))
|
||||
}
|
||||
return out, err
|
||||
return out, err, filename
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user