talk in audio channel (not working yet)
This commit is contained in:
53
core/audio.go
Normal file
53
core/audio.go
Normal file
@ -0,0 +1,53 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
// playSound plays the current buffer to the provided channel.
|
||||
func playSound(s *discordgo.Session, guildID, channelID string, buffer []byte) (err error) {
|
||||
|
||||
// Join the provided voice channel.
|
||||
vc, err := s.ChannelVoiceJoin(guildID, channelID, false, true)
|
||||
if err != nil {
|
||||
log.Println("Could not find channel.")
|
||||
return err
|
||||
}
|
||||
|
||||
// Sleep for a specified amount of time before playing the sound
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
|
||||
// Start speaking.
|
||||
vc.Speaking(true)
|
||||
|
||||
vc.OpusSend <- buffer
|
||||
|
||||
// Stop speaking
|
||||
vc.Speaking(false)
|
||||
|
||||
// Sleep for a specificed amount of time before ending.
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
|
||||
// Disconnect from the provided voice channel.
|
||||
vc.Disconnect()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAudioMessage(msg string) (filename string, out []byte) {
|
||||
curr_time := time.Now().Unix()
|
||||
filename = fmt.Sprintf("%d.ogg", curr_time)
|
||||
var cmd_args string = fmt.Sprintf("espeak-ng -s 120 -v mb-fr2 -p 30 '%s' --stdout | ffmpeg -i - -c:a libopus -f ogg pipe:1 2>/dev/null",
|
||||
maxString(msg, 300))
|
||||
cmd := exec.Command("sh", "-c", cmd_args)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprint(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user