package module
Version: v0.0.0-...-caaac75 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0



GoDoc Go report Build Status Discord Gophers

dgVoice is a Go package that provides an example of adding opus audio and play file support for DiscordGo.

  • You must use the current develop branch of Discordgo
  • You must have ffmpeg in your path and Opus libs already installed.

This code should be considered just a proof of concept, or an example, of accomplishing this task and not a defacto standard.

Please send feedback on any performance improvements that can be made for sound quality, stability, or efficiency.

For help with this package or general Go discussion, please join the Discord Gophers chat server.

Getting Started


This assumes you already have a working Go environment, if not please see this page first.

go get github.com/bwmarrin/dgvoice

Usage Example

See example folder



Package dgvoice provides opus encoding and audio file playback for the Discordgo package.



This section is empty.


View Source
var OnError = func(str string, err error) {
	prefix := "dgVoice: " + str

	if err != nil {
		os.Stderr.WriteString(prefix + ": " + err.Error())
	} else {

OnError gets called by dgvoice when an error is encountered. By default logs to STDERR


func PlayAudioFile

func PlayAudioFile(v *discordgo.VoiceConnection, filename string, stop <-chan bool)

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 ReceivePCM

func ReceivePCM(v *discordgo.VoiceConnection, c chan *discordgo.Packet)

ReceivePCM will receive on the the Discordgo OpusRecv channel and decode the opus audio into PCM then send it on the provided channel.

func SendPCM

func SendPCM(v *discordgo.VoiceConnection, pcm <-chan []int16)

SendPCM will receive on the provied channel encode received PCM data into Opus then send that to Discordgo


This section is empty.

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL