{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "ecf13510",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "efd467f2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from os.path import dirname, join as pjoin\nfrom scipy.io import wavfile\nimport scipy.io",
            "outputs": []
        },
        {
            "id": "6bbd1fcf",
            "cell_type": "markdown",
            "source": "Get the filename for an example .wav file from the tests/data directory.\n",
            "metadata": {}
        },
        {
            "id": "a9474d33",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "data_dir = pjoin(dirname(scipy.io.__file__), 'tests', 'data')\nwav_fname = pjoin(data_dir, 'test-44100Hz-2ch-32bit-float-be.wav')",
            "outputs": []
        },
        {
            "id": "b3e8edb1",
            "cell_type": "markdown",
            "source": "Load the .wav file contents.\n",
            "metadata": {}
        },
        {
            "id": "6fbff777",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "samplerate, data = wavfile.read(wav_fname)\nprint(f\"number of channels = {data.shape[1]}\")",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "number of channels = 2"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "6104fd94",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "length = data.shape[0] / samplerate\nprint(f\"length = {length}s\")",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "length = 0.01s"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "5943f997",
            "cell_type": "markdown",
            "source": "Plot the waveform.\n",
            "metadata": {}
        },
        {
            "id": "210896d3",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nimport numpy as np\ntime = np.linspace(0., length, data.shape[0])\nplt.plot(time, data[:, 0], label=\"Left channel\")\nplt.plot(time, data[:, 1], label=\"Right channel\")\nplt.legend()\nplt.xlabel(\"Time [s]\")\nplt.ylabel(\"Amplitude\")\nplt.show()",
            "outputs": []
        }
    ]
}