Created
November 21, 2018 12:31
-
-
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
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 ( | |
"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