Cozy Wav Parser is a basic module for parsing WAV file header metadata for the Nim programming language. It provides a simple way to extract common information about the audio stream, such as sample rate, bit depth, and the number of channels. While the actual PCM format specification is complex, this module focuses on supporting the most common formats, which easily covers 99% of use-cases.
- Supports parsing headers for the most common WAVE files
- Extracts essential audio stream information: sample rate, bit depth, number of channels, byte rate, and float/integer sample format
Warning
This code is not thoroughly tested and might not work correctly for all valid WAV files. PRs welcome.
Cozy Wav Parser is not yet in the nimble directory. You can git clone
or download the module directly.
Upon acceptance in the nimble directory, you can install it using atlas
or nimble
:
atlas use cozywavparser
nimble install cozywavparser
import pkg/cozywavparser
# Parse WAV header from a file
let wavHeader = readWavFileHeader("audio.wav")
# Print audio stream information
echo "Wave Format: ", wavHeader.waveFormat
echo "Channels: ", wavHeader.numChannels
echo "Sample Rate: ", wavHeader.sampleRate, "Hz"
echo "Bits per Sample: ", wavHeader.bitsPerSample
echo "Float Samples: ", wavHeader.isFloat
# Parse WAV header from a stream
import std/streams
let stream = newFileStream("audio.wav", fmRead)
if not isNil(stream):
let wavHeaderFromStream = readWavHeader(stream)
echo wavHeaderFromStream
stream.close()
Documentation is included. You can generate it locally with nim doc cozywavparser.nim
.
Cozy Log Writer is licensed under GNU General Public License version 2.0 or later. See the LICENSE file for details.