// Function based on DiscordGo's airhorn example (https://github.com/bwmarrin/discordgo/blob/master/examples/airhorn/main.go)
Function based on DiscordGo's airhorn example
// Function based on DiscordGo ' s airhorn example ( https : // github . com / bwmarrin / discordgo / blob / master / examples / airhorn / main . go )
func LoadAudioFile(fs http.FileSystem, path string) (buffer [][]byte, err error) {
	buffer = make([][]byte, 0)
	var opuslen int16
	file, err := fs.Open(path)
	if err != nil {
		return
	}
	defer func() {
		_ = file.Close()
	}()
	for {
		err = binary.Read(file, binary.LittleEndian, &opuslen)
		if err == io.EOF || err == io.ErrUnexpectedEOF {
			err = file.Close()
			if err != nil {
				return
			}
			return
		}
		if err != nil {
			return
		}
		InBuf := make([]byte, opuslen)
		err = binary.Read(file, binary.LittleEndian, &InBuf)
		if err != nil {
			return
		}
		buffer = append(buffer, InBuf)
	}
}
func LoadAudioFile ( fs http . FileSystem , path string ) ( buffer [ ] [ ] byte , err error ) { buffer = make ( [ ] [ ] byte , 0 ) var opuslen int16 file , err := fs . Open ( path ) if err != nil { return } defer func ( ) { _ = file . Close ( ) } ( ) for { err = binary . Read ( file , binary . LittleEndian , & opuslen ) if err == io . EOF || err == io . ErrUnexpectedEOF { err = file . Close ( ) if err != nil { return } return } if err != nil { return } InBuf := make ( [ ] byte , opuslen ) err = binary . Read ( file , binary . LittleEndian , & InBuf ) if err != nil { return } buffer = append ( buffer , InBuf ) } }
Function based on DiscordGo's airhorn example
Function based on DiscordGo ' s airhorn example
// If this is the end of the file, just return. // Should not be any end of file errors // Append encoded pcm data to the buffer.