当前位置: 首页>>代码示例>>Golang>>正文


Golang VoiceConnection.Speaking方法代码示例

本文整理汇总了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
	}
}
开发者ID:t11230,项目名称:airhornbot,代码行数:9,代码来源:sound_utils.go

示例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
	}
}
开发者ID:Rassilon216,项目名称:dgvoice,代码行数:51,代码来源:dgvoice.go

示例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
	}
}
开发者ID:Rassilon216,项目名称:dgvoice,代码行数:22,代码来源:main.go


注:本文中的github.com/bwmarrin/discordgo.VoiceConnection.Speaking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。