I'm looking for some sample code to show me how to add metadata to the wav files we create. Anyone?
4 Answers
One option is to add your own chunk with a unique id. Most WAV players will ignore it.
Another idea would to be use a labl
chunk, associated with a que set at the beginning or end of the file. You'd also need a que
chunk. See here for a reference
How to write the data is simple
- Write
"RIFF"
. - save the file position.
- Write 4 bytes of 0's
- Write all the existing chunks. Keep count of bytes written.
- Add your chunk. Be sure to get the chunksize right. Keep count of bytes written.
- rewind to the saved position. Write the new size (as a 32-bit number).
- Close the file.
It's slightly more complicated if you are adding things to an existing list
chunk, but the same principle applies.

- 34,686
- 15
- 91
- 152
-
Beware that all chunks must have an even number of bytes. Pad with a NULL if needed! – mivk Apr 26 '12 at 07:19
Try code below
private void WaveTag()
{
string fileName = "in.wav";
WaveReadWriter wrw = new WaveReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite));
//removes INFO tags from audio stream
wrw.WriteInfoTag(null);
//writes INFO tags into audio stream
Dictionary<WaveInfo, string> tag = new Dictionary<WaveInfo, string>();
tag[WaveInfo.Comments] = "Comments...";
wrw.WriteInfoTag(tag);
wrw.Close();
//reads INFO tags from audio stream
WaveReader wr = new WaveReader(File.OpenRead(fileName));
Dictionary<WaveInfo, string> dir = wr.ReadInfoTag();
wr.Close();
if (dir.Count > 0)
{
foreach (string val in dir.Values)
{
Console.WriteLine(val);
}
}
}
from http://alvas.net/alvas.audio,articles.aspx#id3-tags-for-wave-files

- 455
- 7
- 18
-
6This code is unuseable without a license to 'Alvas Audio', a minimum $500 license would be required... – Mr Dog Apr 06 '15 at 14:13
If you examine the wave file spec you'll see that there does not seem to be room for annotations of any kind. An option would be to wrap the wave file with your own format that includes custom information but you would in effect be creating a whole new format that would not be readable by users who do not have your app. But you might be ok with that.

- 79,492
- 20
- 149
- 189
-
2From what I've read, I can embed it as part of the RIFF structure, I just can't figure out which structures and tags to use. – Curtis Aug 09 '10 at 21:30
Maybe the nist file format will give you what you want: NIST
Here is a lib that could help, but im afraid it looks old. NIST Lib
Cant find more useful information right now how exactly to use it, and im afraid the information papers from my company must stay there. :L/

- 3,616
- 3
- 26
- 23