Skip to content

Instantly share code, notes, and snippets.

@ik5
Created March 8, 2020 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/b00050f4a2bff458067f1cd8d725030e to your computer and use it in GitHub Desktop.
Save ik5/b00050f4a2bff458067f1cd8d725030e to your computer and use it in GitHub Desktop.
example on concating two (or more) wav files
package main
import (
"io"
"io/ioutil"
"github.com/moutend/go-wav"
)
func main() {
// Read input1.wav and input2.wav
i1, _ := ioutil.ReadFile("1.wav")
i2, _ := ioutil.ReadFile("2.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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment