go-wav icon indicating copy to clipboard operation
go-wav copied to clipboard

return wav header data

Open ilaer opened this issue 2 years ago • 1 comments

hope to get wav header data from format attr. so i can detect wheater a 44 or 46-byte header.

ilaer avatar Jun 21 '22 02:06 ilaer

You can get the chunk size of fmt chunk with the following code If the chunk size <= 18, the header size will be 46

package main

import (
	"flag"
	"log"
	"os"

	riff "github.com/youpy/go-riff"
)

func main() {
	var path = flag.String("path", "", "WAV file path")

	flag.Parse()

	file, err := os.Open(*path)
	if err != nil {
		panic(err)
	}

	reader := riff.NewReader(file)
	r, err := reader.Read()
	if err != nil {
		panic(err)
	}

	for _, chunk := range r.Chunks {
		chunkID := string(chunk.ChunkID[:])

		log.Printf("Chunk ID: %s", chunkID)
		log.Printf("Chunk size: %d", chunk.ChunkSize)
	}
}

youpy avatar Jun 24 '22 15:06 youpy