func (k *Mumble) Command_Audio_Play_File(text string) { if k.Audio != nil && k.Audio.State() == gumbleffmpeg.StatePlaying { return } filepath := utils.GetAudioFilePath(text) if filepath != "" { k.Audio = gumbleffmpeg.New(k.Client, gumbleffmpeg.SourceFile(filepath)) k.Audio.Volume = k.conf_volume k.Audio.Play() } }
func (s *State) apiAudioNew(tbl *lua.LTable) *audioStream { filename := tbl.RawGetString("filename") exec := tbl.RawGetString("exec") args := tbl.RawGetString("args") offset := tbl.RawGetString("offset") callback := tbl.RawGetString("callback") if enc, ok := s.Client.AudioEncoder.(*opus.Encoder); ok { enc.SetApplication(gopus.Audio) } var source gumbleffmpeg.Source switch { // source file case filename != lua.LNil && exec == lua.LNil && args == lua.LNil: source = gumbleffmpeg.SourceFile(filename.String()) // source exec case filename == lua.LNil && exec != lua.LNil: var argsStr []string if argsTable, ok := args.(*lua.LTable); ok { for i := 1; ; i++ { arg := argsTable.RawGetInt(i) if arg == lua.LNil { break } argsStr = append(argsStr, arg.String()) } } source = gumbleffmpeg.SourceExec(exec.String(), argsStr...) default: panic("invalid piepan.Audio.New source type") } stream := &audioStream{ state: s, s: gumbleffmpeg.New(s.Client, source), callback: callback, } stream.s.Command = s.AudioCommand if number, ok := offset.(lua.LNumber); ok { stream.s.Offset = time.Second * time.Duration(number) } return stream }
// PlayCurrent creates a new audio stream and begins playing the current track. func (q *Queue) PlayCurrent() error { currentTrack := q.GetTrack(0) filepath := os.ExpandEnv(viper.GetString("cache.directory") + "/" + currentTrack.GetFilename()) if _, err := os.Stat(filepath); os.IsNotExist(err) { if err := DJ.YouTubeDL.Download(q.GetTrack(0)); err != nil { return err } } source := gumbleffmpeg.SourceFile(filepath) DJ.AudioStream = gumbleffmpeg.New(DJ.Client, source) DJ.AudioStream.Offset = currentTrack.GetPlaybackOffset() DJ.AudioStream.Volume = DJ.Volume if viper.GetString("defaults.player_command") == "avconv" { DJ.AudioStream.Command = "avconv" } if viper.GetBool("queue.announce_new_tracks") { message := `<table> <tr> <td align="center"><img src="%s" width=150 /></td> </tr> <tr> <td align="center"><b><a href="%s">%s</a> (%s)</b></td> </tr> <tr> <td align="center">Added by %s</td> </tr> ` message = fmt.Sprintf(message, currentTrack.GetThumbnailURL(), currentTrack.GetURL(), currentTrack.GetTitle(), currentTrack.GetDuration().String(), currentTrack.GetSubmitter()) if currentTrack.GetPlaylist() != nil { message = fmt.Sprintf(message+`<tr><td align="center">From playlist "%s"</td></tr>`, currentTrack.GetPlaylist().GetTitle()) } message += `</table>` DJ.Client.Self.Channel.Send(message, false) } DJ.AudioStream.Play() go func() { DJ.AudioStream.Wait() q.Skip() }() return nil }
func main() { files := make(map[string]string) var stream *gumbleffmpeg.Stream flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage of %s: [flags] [audio files...]\n", os.Args[0]) flag.PrintDefaults() } gumbleutil.Main(gumbleutil.AutoBitrate, gumbleutil.Listener{ Connect: func(e *gumble.ConnectEvent) { for _, file := range flag.Args() { key := filepath.Base(file) files[key] = file } fmt.Printf("audio player loaded! (%d files)\n", len(files)) }, TextMessage: func(e *gumble.TextMessageEvent) { if e.Sender == nil { return } file, ok := files[e.Message] if !ok { return } if stream != nil && stream.State() == gumbleffmpeg.StatePlaying { return } stream = gumbleffmpeg.New(e.Client, gumbleffmpeg.SourceFile(file)) if err := stream.Play(); err != nil { fmt.Printf("%s\n", err) } else { fmt.Printf("Playing %s\n", file) } }, }) }
func (k *Mumble) Command_Audio_Play_Ivona(text string, language string) { if k.Audio != nil && k.Audio.State() == gumbleffmpeg.StatePlaying { return } var tt string if strings.HasPrefix(text, "$$$") { tt = strings.Split(text, "$$$")[1] } else { tt = strings.SplitN(text, " ", 2)[1] } fmt.Println(utils.Timestamp() + "backends/mumble: command_audio_play_ivona(): " + language + ":" + tt) if language == "" { language = k.services.YTranslate.Detect(tt) } rc := k.services.Ivona.GetAudio_ReadCloser(tt, language) k.Audio = gumbleffmpeg.New(k.Client, gumbleffmpeg.SourceReader(rc)) k.Audio.Volume = k.conf_volume k.Audio.Play() }
func main() { files := make(map[string]string) var stream *gumbleffmpeg.Stream //targetChannel := flag.String("channel", "Root", "channel the bot will join") gumbleutil.Main(func(client *gumble.Client) { /* var err error stream, err = gumbleffmpeg.New(client) if err != nil { fmt.Printf("%s\n", err) os.Exit(1) } */ client.Attach(gumbleutil.AutoBitrate) for _, file := range flag.Args() { key := filepath.Base(file) files[key] = file } }, gumbleutil.Listener{ // Connect event Connect: func(e *gumble.ConnectEvent) { fmt.Printf("GoMumbleSoundboard loaded (%d files)\n", len(files)) /* fmt.Printf("Connected to %s\n", e.Client.Conn().RemoteAddr()) if e.WelcomeMessage != "" { fmt.Printf("Welcome message: %s\n", e.WelcomeMessage) } fmt.Printf("Channel: %s\n", e.Client.Self().Channel().Name()) if *targetChannel != "" && e.Client.Self().Channel().Name() != *targetChannel { target := e.Client.Self().Channel().Find(*targetChannel) e.Client.Self().Move(target) fmt.Printf("Moved to: %s\n", target.Name()) } */ // Start webserver m := martini.Classic() // martini.Static() is used, so public/index.html gets automagically served m.Get("/files.json", func() string { keys := make([]string, 0, len(files)) for k := range files { keys = append(keys, k) } js, _ := json.Marshal(keys) return string(js) }) m.Get("/play/:file", func(params martini.Params) (int, string) { file, ok := files[params["file"]] if !ok { return 404, "not found" } if stream != nil && stream.State() == gumbleffmpeg.StatePlaying { stream.Stop() } stream = gumbleffmpeg.New(e.Client, gumbleffmpeg.SourceFile(file)) if err := stream.Play(); err != nil { return 400, fmt.Sprintf("%s\n", err) } else { return 200, fmt.Sprintf("Playing %s\n", file) } }) m.Get("/stream", func(params martini.Params) (int, string) { file := "http://radiobrony.fr:8000/live" if stream != nil && stream.State() == gumbleffmpeg.StatePlaying { stream.Stop() } stream = gumbleffmpeg.New(e.Client, gumbleffmpeg.SourceFile(file)) if err := stream.Play(); err != nil { return 400, fmt.Sprintf("%s\n", err) } else { stream.Volume = 0.02 return 200, fmt.Sprintf("Playing %s\n", file) } }) m.Get("/stop", func() string { stream.Stop() return "ok" }) m.Run() }, }) }