本文整理汇总了Golang中github.com/bwmarrin/discordgo.VoiceConnection.Speaking方法的典型用法代码示例。如果您正苦于以下问题:Golang VoiceConnection.Speaking方法的具体用法?Golang VoiceConnection.Speaking怎么用?Golang VoiceConnection.Speaking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bwmarrin/discordgo.VoiceConnection
的用法示例。
在下文中一共展示了VoiceConnection.Speaking方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Play
// Plays this sound over the specified VoiceConnection
func (s *Sound) Play(vc *discordgo.VoiceConnection) {
vc.Speaking(true)
defer vc.Speaking(false)
for _, buff := range s.buffer {
vc.OpusSend <- buff
}
}
示例2: PlayAudioFile
// PlayAudioFile will play the given filename to the already connected
// Discord voice server/channel. voice websocket and udp socket
// must already be setup before this will work.
func PlayAudioFile(v *discordgo.VoiceConnection, filename string) {
// Create a shell command "object" to run.
run = exec.Command("ffmpeg", "-i", filename, "-f", "s16le", "-ar", strconv.Itoa(frameRate), "-ac", strconv.Itoa(channels), "pipe:1")
ffmpegout, err := run.StdoutPipe()
if err != nil {
fmt.Println("StdoutPipe Error:", err)
return
}
ffmpegbuf := bufio.NewReaderSize(ffmpegout, 16384)
// Starts the ffmpeg command
err = run.Start()
if err != nil {
fmt.Println("RunStart Error:", err)
return
}
// Send "speaking" packet over the voice websocket
v.Speaking(true)
// Send not "speaking" packet over the websocket when we finish
defer v.Speaking(false)
// will actually only spawn one instance, a bit hacky.
if send == nil {
send = make(chan []int16, 2)
}
go SendPCM(v, send)
for {
// read data from ffmpeg stdout
audiobuf := make([]int16, frameSize*channels)
err = binary.Read(ffmpegbuf, binary.LittleEndian, &audiobuf)
if err == io.EOF || err == io.ErrUnexpectedEOF {
return
}
if err != nil {
fmt.Println("error reading from ffmpeg stdout :", err)
return
}
// Send received PCM to the sendPCM channel
send <- audiobuf
}
}
示例3: Echo
// Takes inbound audio and sends it right back out.
func Echo(v *discordgo.VoiceConnection) {
recv := make(chan *discordgo.Packet, 2)
go dgvoice.ReceivePCM(v, recv)
send := make(chan []int16, 2)
go dgvoice.SendPCM(v, send)
v.Speaking(true)
defer v.Speaking(false)
for {
p, ok := <-recv
if !ok {
return
}
send <- p.PCM
}
}