Skip to content

Instantly share code, notes, and snippets.

@ik5
Created November 21, 2018 12:31
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/67e6014f5ce1984c7f1a66bd2d293930 to your computer and use it in GitHub Desktop.
Save ik5/67e6014f5ce1984c7f1a66bd2d293930 to your computer and use it in GitHub Desktop.
fast example to see if a wav duration is a minute or more
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"time"
"github.com/go-audio/wav"
)
func main() {
files, err := filepath.Glob("/tmp/*wav")
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
for _, file := range files {
fi, _ := os.Stat(file)
if fi.IsDir() {
continue
}
f, err := os.Open(file)
if err != nil {
log.Fatal(err)
}
defer f.Close()
dur, err := wav.NewDecoder(f).Duration()
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Printf("%s duration: %t\n", f.Name(), dur >= time.Minute)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment