Skip to content

Commit

Permalink
Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
iluvcapra committed Nov 7, 2023
1 parent 6f6a90a commit 96f79b5
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 244 deletions.
162 changes: 133 additions & 29 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
"source": [
"# `wavinfo` Demonstration\n",
"\n",
"The entry point for wavinfo is the WavInfoReader class."
"The `wavinfo` module allows you to read most of the metadata formats that are available for WAV files."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Opening a WAV file for reading metadata\n",
"\n",
"The entry point for wavinfo is the `WavInfoReader` class:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -26,14 +35,32 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic WAV Data\n",
"Once you have a `WavInfoReader`, you can access different metadata systems or \"scopes.\"\n",
"\n",
"The scopes that are presently supported are: `fmt`, `data`, `ixml`, `bext`, `info`, `adm`, `cues`, and `dolby`. Each of these is an attribute of a `WavInfoReader` object.\n",
"\n",
"Each scope roughly corresponds to a vendor-defined metadata system. Many scopes directly represent a specific file *chunk*, like `fmt` or `ixml`, and some may involve data read from many chunks. Examples of this would include `cues` or `adm`.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Metadata Scopes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### `data` and `fmt`: Basic WAV Data\n",
"\n",
"The length of the file in frames (interleaved samples) and bytes is available, as is the contents of the format chunk."
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -42,7 +69,7 @@
"(240239, 1441434)"
]
},
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -51,9 +78,16 @@
"(info.data.frame_count, info.data.byte_count)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `fmt` scope allows the client to read metadata from the WAVE format description."
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -62,7 +96,7 @@
"(48000, 2, 6, 24)"
]
},
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -75,37 +109,39 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Broadcast WAV Extension"
"### `bext`: Broadcast WAV Extension\n",
"\n",
"The `bext` scope allows the client to access Broadcast-WAV metadata. "
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sSPEED=023.976-ND\r\n",
"sTAKE=1\r\n",
"sUBITS=$12311801\r\n",
"sSWVER=2.67\r\n",
"sPROJECT=BMH\r\n",
"sSCENE=A101\r\n",
"sFILENAME=A101_1.WAV\r\n",
"sTAPE=18Y12M31\r\n",
"sTRK1=MKH516 A\r\n",
"sTRK2=Boom\r\n",
"sNOTE=\r\n",
"sSPEED=023.976-ND\n",
"sTAKE=1\n",
"sUBITS=$12311801\n",
"sSWVER=2.67\n",
"sPROJECT=BMH\n",
"sSCENE=A101\n",
"sFILENAME=A101_1.WAV\n",
"sTAPE=18Y12M31\n",
"sTRK1=MKH516 A\n",
"sTRK2=Boom\n",
"sNOTE=\n",
"\n",
"----------\n",
"Originator: Sound Dev: 702T S#GR1112089007\n",
"Originator Ref: USSDVGR1112089007124001008206301\n",
"Originator Date: 2018-12-31\n",
"Originator Time: 12:40:00\n",
"Time Reference: 2190940753\n",
"A=PCM,F=48000,W=24,M=stereo,R=48000,T=2 Ch\r\n",
"A=PCM,F=48000,W=24,M=stereo,R=48000,T=2 Ch\n",
"\n"
]
}
Expand All @@ -125,12 +161,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## iXML Production Recorder Metadata"
"### `ixml`: iXML Production Recorder Metadata"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -155,12 +191,80 @@
"print(\"iXML File Family UID:\", info.ixml.family_uid)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### `cues`: Cues Metadata\n",
"\n",
"Cue time markers are accessible through the `cues` scope. The `each_cue` method returns an iterator that yields a tuple of each cue \"name\" or integer UID, and sample location. "
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cue ID: 1\n",
"Cue Offset: 29616\n",
"Cue ID: 2\n",
"Cue Offset: 74592\n",
"Cue ID: 3\n",
"Cue Offset: 121200\n"
]
}
],
"source": [
"path = \"../tests/test_files/cue_chunks/STE-000.wav\"\n",
"info = WavInfoReader(path)\n",
"\n",
"for cue in info.cues.each_cue():\n",
" print(f\"Cue ID: {cue[0]}\")\n",
" print(f\"Cue Offset: {cue[1]}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are also convenience methods to get the appropriate label and note for a given marker. (Note here also `WavInfoReader`'s facility for overriding default text encodings.)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cue ID: 1\n",
" Label: Marker 1\n",
" Note: <NO NOTE>\n",
"Cue ID: 2\n",
" Label: Marker 2\n",
" Note: Marker Comment 1\n",
"Cue ID: 3\n",
" Label: Marker 3\n",
" Note: Лорем ипсум долор сит амет, тимеам вивендум хас ет, цу адолесценс дефинитионес еам.\n"
]
}
],
"source": [
"path = \"../tests/test_files/cue_chunks/izotoperx_cues_test.wav\"\n",
"info = WavInfoReader(path, info_encoding=\"utf-8\")\n",
"\n",
"for cue in info.cues.each_cue():\n",
" print(f\"Cue ID: {cue[0]}\")\n",
" label, note = info.cues.label_and_note(cue[0])\n",
" print(f\" Label: {label}\")\n",
" print(f\" Note: {note or '<NO NOTE>'}\")"
]
},
{
"cell_type": "code",
Expand All @@ -172,7 +276,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -186,9 +290,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading

0 comments on commit 96f79b5

Please sign in to comment.