Skip to content
qiniuPublic

About

Audio support for Go language.

Topics

Resources

Stars

81 stars

Watchers

3 watching

Forks

Latest commit

 

History

42 Commits

Folders and files

Repository files navigation

Audio support for Go language

LICENSE Build Status Go Report Card GitHub release Coverage Status GoDoc

Qiniu Logo

The package github.com/qiniu/audio is an extensible audio library with simple API for multi platforms in the Go programming language.

Platforms

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • Android
  • iOS
  • Web browsers (Chrome, Firefox, Safari and Edge)
    • GopherJS
    • WebAssembly (Experimental)

Features

  • Pluggable audio decoders. And now it supports the following formats:
    • wav/pcm: import _ "github.com/qiniu/audio/wav"
    • wav/adpcm: import _ "github.com/qiniu/audio/wav/adpcm"
    • mp3: import _ "github.com/qiniu/audio/mp3"
  • Audio encoders (TODO).
  • Convert decoded audio stream.

Example

import (
	"io"
	"os"

	"github.com/hajimehoshi/oto"

	"github.com/qiniu/audio"
	_ "github.com/qiniu/audio/mp3"
	_ "github.com/qiniu/audio/wav"
	_ "github.com/qiniu/audio/wav/adpcm"
)

func playAudio(file string) error {
	f, err := os.Open(file)
	if err != nil {
		return err
	}
	defer f.Close()

	d, _, err := audio.Decode(f)
	if err != nil {
		return err
	}

	c, err := oto.NewContext(d.SampleRate(), d.Channels(), d.BytesPerSample(), 8192)
	if err != nil {
		return err
	}
	defer c.Close()

	p := c.NewPlayer()
	defer p.Close()

	_, err = io.Copy(p, d)
	return err
}

Document

About

Audio support for Go language.

Topics

Resources

Stars

81 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages