-
-
Save jsgoecke/ca8fe5b4e0901ed04ee0 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"github.com/krig/go-sox" | |
"log" | |
) | |
func init() { | |
if !sox.Init() { | |
log.Fatal("Failed to initialize SoX") | |
} | |
// Make sure to call Quit before terminating | |
defer sox.Quit() | |
} | |
func main() { | |
splitAudioFile("./0d61c931-999b-4f60-a023-ce9b38cfc633-1.0.wav", "left.wav", "1") | |
splitAudioFile("./0d61c931-999b-4f60-a023-ce9b38cfc633-1.0.wav", "right.wav", "2") | |
} | |
func splitAudioFile(inputName string, outputName string, channel string) { | |
in := sox.OpenRead(inputName) | |
if in == nil { | |
log.Fatal("Failed to open " + inputName) | |
} | |
defer in.Release() | |
out := sox.OpenWrite(outputName, in.Signal(), in.Encoding(), nil) | |
if out == nil { | |
log.Fatal("Failed to open " + outputName) | |
} | |
defer out.Release() | |
chain := sox.CreateEffectsChain(in.Encoding(), out.Encoding()) | |
e := sox.CreateEffect(sox.FindEffect("input")) | |
e.Options(in) | |
chain.Add(e, in.Signal(), in.Signal()) | |
e.Release() | |
e = sox.CreateEffect(sox.FindEffect("remix")) | |
e.Options(channel) | |
chain.Add(e, in.Signal(), in.Signal()) | |
e.Release() | |
e = sox.CreateEffect(sox.FindEffect("output")) | |
e.Options(out) | |
chain.Add(e, in.Signal(), in.Signal()) | |
e.Release() | |
chain.Flow() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment