Skip to content

moutend/go-wav

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-wav

MIT License CircleCI

Package go-wav reads and writes WAV file.

Example

The following example concatinates input1.wav and input2.wav into output.wav.

package main

import (
	"io"
	"io/ioutil"

	"github.com/moutend/go-wav"
)

func main() {
	// Read input1.wav and input2.wav
	i1, _ := ioutil.ReadFile("input1.wav")
	i2, _ := ioutil.ReadFile("input2.wav")

	// Create wav.File.
	a := &wav.File{}
	b := &wav.File{}

	// Unmarshal input1.wav and input2.wav.
	wav.Unmarshal(i1, a)
	wav.Unmarshal(i2, b)

	// Add input2.wav to input1.wav.
	c, _ := wav.New(a.SamplesPerSec(), a.BitsPerSample(), a.Channels())
	io.Copy(c, a)
	io.Copy(c, b)

	// Marshal input1.wav and save result.
	file, _ := wav.Marshal(c)
	ioutil.WriteFile("output.wav", file, 0644)
}

Note that the example assumes that the two input files have same sample rate, bit depth and channels.

Contributing

  1. Fork (https://github.com/moutend/go-wca/fork)
  2. Create a feature branch
  3. Add changes
  4. Run go fmt and go test
  5. Commit your changes
  6. Open a new Pull Request

Author

Yoshiyuki Koyanagi

About

Package go-wav reads and writes WAV file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages