2020-10-22 00:11:59 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
|
2020-10-22 18:54:37 +02:00
|
|
|
"log"
|
|
|
|
|
2020-10-22 00:11:59 +02:00
|
|
|
"layeh.com/gumble/gumble"
|
|
|
|
"layeh.com/gumble/gumbleutil"
|
|
|
|
_ "layeh.com/gumble/opus" // it's a good idea to load this: botamusique crashes because of a CodecNotSupportedError EXception
|
|
|
|
)
|
|
|
|
|
|
|
|
func audiolistener(e *gumble.AudioStreamEvent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
type AudioListener struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (audiolistener AudioListener) OnAudioStream(e *gumble.AudioStreamEvent) {
|
|
|
|
fmt.Printf("Received AudioStreamEvent from %s\n", e.User.Name)
|
|
|
|
go ReadPacket(e.C)
|
|
|
|
}
|
|
|
|
|
2020-10-22 00:20:10 +02:00
|
|
|
// func PcmToMp3(pcmFileName, mp3FileName string) {
|
|
|
|
// pcmFile, _ := os.OpenFile(pcmFileName, os.O_RDONLY, 0555)
|
|
|
|
// mp3File, _ := os.OpenFile(mp3FileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
|
|
|
|
// defer mp3File.Close()
|
|
|
|
// wr, err := lame.NewWriter(mp3File)
|
|
|
|
// if err != nil {
|
|
|
|
// panic("cannot create lame writer, err: " + err.Error())
|
2020-10-22 00:11:59 +02:00
|
|
|
|
2020-10-22 00:20:10 +02:00
|
|
|
// }
|
|
|
|
// io.Copy(wr, pcmFile)
|
|
|
|
// wr.Close()
|
2020-10-22 00:11:59 +02:00
|
|
|
|
2020-10-22 00:20:10 +02:00
|
|
|
// }
|
2020-10-22 00:11:59 +02:00
|
|
|
|
|
|
|
type AudioEncoder struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func ReadPacket(ch <-chan *gumble.AudioPacket) { // receive-only channel
|
|
|
|
pcm_out, _ := os.OpenFile("pcm_out.raw", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
|
|
|
|
defer pcm_out.Close()
|
|
|
|
//func (f *File) Write(b []byte) (n int, err error)
|
|
|
|
for packet := range ch {
|
|
|
|
fmt.Println(packet.Sender.Name)
|
|
|
|
// fmt.Printf("%:+v\n", packet)
|
|
|
|
// pkt := <-ch
|
|
|
|
// buf := pkt.AudioBuffer
|
|
|
|
// pcm_out.Write(UnsafeCastInt16sToBytes(buf))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
config := gumble.NewConfig()
|
|
|
|
config.Username = "bon-bot"
|
|
|
|
|
|
|
|
config.Attach(gumbleutil.Listener{
|
|
|
|
TextMessage: func(e *gumble.TextMessageEvent) {
|
|
|
|
fmt.Printf("Received text message: %s\n", e.Message)
|
|
|
|
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
l := AudioListener{name: "Eventprinter"}
|
|
|
|
config.AttachAudio(l)
|
2020-10-22 18:54:37 +02:00
|
|
|
mumbleServer := os.Getenv("MUMBLE_SERVER")
|
|
|
|
if len(mumbleServer) == 0 {
|
|
|
|
mumbleServer = "mumble:64738"
|
|
|
|
log.Printf("Mumble server not defined, falling back to default value: %s", mumbleServer)
|
|
|
|
}
|
|
|
|
client, err := gumble.DialWithDialer(&net.Dialer{}, mumbleServer, config, &tls.Config{InsecureSkipVerify: true}) // TODO: fix cert or make it an option
|
2020-10-22 00:11:59 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Channels:\n")
|
|
|
|
for idx, channel := range client.Channels {
|
|
|
|
fmt.Printf("\t%d - %s\n", idx, channel.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
}
|