Created
March 8, 2020 08:55
-
-
Save ik5/b00050f4a2bff458067f1cd8d725030e to your computer and use it in GitHub Desktop.
example on concating two (or more) wav files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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