Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return wav header data #11

Open
ilaer opened this issue Jun 21, 2022 · 1 comment
Open

return wav header data #11

ilaer opened this issue Jun 21, 2022 · 1 comment

Comments

@ilaer
Copy link

ilaer commented Jun 21, 2022

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

@youpy
Copy link
Owner

youpy commented Jun 24, 2022

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)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants