{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%cd ..\n", "import sys\n", "\n", "sys.path.append(\"/workspaces/waloviz/src\")\n", "sys.path.append(\"/home/runner/work/waloviz/waloviz/src\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import panel as pn\n", "import waloviz as wv\n", "\n", "wv.extension()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In WaloViz there are a few features which are situational and nuanced, these advanced options make WaloViz more than just simple, but powerful. \n", "\n", "The following demonstrations are examples of advanced options and their effects in action, for the full list of options go to the [Reference Manual](../reference-manual/waloviz.__init__.html).\n", "\n", "## Resampling\n", "To display an audio with a different sample-rate, just set the `sr` variable in addition to the source:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True),\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True, sr=8000),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This has a \"crop\" like effect in the frequency axis. \n", "Notice how the audio quality has degraded. \n", "\n", "## Axes Limits\n", "If you desire a \"crop\" like effect without any audio degradation, you can use the `axes_limits` option:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def waveform(wav, sr):\n", " return wav\n", "\n", "\n", "pn.Row(\n", " wv.Audio(\n", " \"local_data/Yoshi.wav\",\n", " waveform,\n", " minimal=True,\n", " axes_limits=dict(Hz=(0, 4000), y=(0, 0.5)),\n", " ),\n", " wv.Audio(\n", " \"local_data/Yoshi.wav\",\n", " waveform,\n", " minimal=True,\n", " axes_limits=dict(Hz=(1000, 9000), y=(-0.5, 0)),\n", " ),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Over Curve Axes\n", "When you have multiple overlaid curves you can set each of them to a different axis with the ``over_curve_axes``:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import torch\n", "\n", "\n", "def envelope(wav, sr):\n", " return torch.nn.functional.max_pool1d(wav, kernel_size=101, stride=50, padding=50)\n", "\n", "\n", "pn.Row(\n", " wv.Audio(\n", " \"local_data/Yoshi.wav\",\n", " {\"wav\": waveform, \"env\": envelope},\n", " over_curve_axes={\"wav\": \"y\", \"env\": \"y\"},\n", " minimal=True,\n", " ),\n", " wv.Audio(\n", " \"local_data/Yoshi.wav\",\n", " {\"wav\": waveform, \"env\": envelope},\n", " over_curve_axes={\"wav\": \"y\", \"env\": \"z\"},\n", " minimal=True,\n", " ),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Spectrogram Resolution\n", "To set the spectrogram to a different resolution in frequency or time, use the `frame_ms` and `hop_ms` variables:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True, frame_ms=50, hop_ms=25),\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True, frame_ms=0.5, hop_ms=0.25),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Colors\n", "To set the colormap use `cmap`, and set `colorbar=True` for a log scale color bar:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True, cmap=\"viridis\", colorbar=True),\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True, cmap=\"jet\", colorbar=True),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Theme\n", "You can set the `bokeh` theme with the `theme` option, a string will load one of the predefined themes of bokeh:\n", "1. `\"dark_minimal\"`\n", "2. `\"light_minimal\"`\n", "3. `\"caliber\"`\n", "4. `\"contrast\"`\n", "5. `\"night_sky\"`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True, theme=\"light_minimal\"),\n", " wv.Audio(\"local_data/Yoshi.wav\", minimal=True, theme=\"night_sky\"),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download & Native Player\n", "You can use the `download_button` and `native_player` options to show or hide them: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(\n", " wv.Audio(\"local_data/Yoshi.wav\"),\n", " wv.Audio(\"local_data/Yoshi.wav\", download_button=False, native_player=True),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Title\n", "Use the `title` to set an name for the player, it will be used when saving the plot to an HTML file, also you can embed the title with the player with the `embed_title` option:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(\n", " wv.Audio(\"local_data/Yoshi.wav\"),\n", " wv.Audio(\"local_data/Yoshi.wav\", title=\"Big Yoshi\", embed_title=True),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Other options\n", "There are more options to WaloViz, for example:\n", "* `sync_legends` - makes the over curves appear and disappear over both channels with a single click\n", "* `freq_label` - sets the frequency axis label, when set to `None` no label is displayed and some width space is cleared\n", "Find out more in the [Reference Manual](../reference-manual/waloviz._user_functions." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }