Categorygithub.com/qiniu/audio
repositorypackage
0.2.1
Repository: https://github.com/qiniu/audio.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

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/v2"

	"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