Skip to content

Commit

Permalink
Updated Audio docs
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 15, 2019
1 parent 2d55450 commit 56d64b6
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions examples/reference/widgets/Audio.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,51 @@
"___"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `Audio` widget can be constructed with a URL pointing to a remote audio file or a local audio file (in which case the data is embedded)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"audio = pn.widgets.Audio(name='Audio', value='http://ccrma.stanford.edu/~jos/mp3/pno-cs.mp3')\n",
"pn.widgets.Audio(name='Audio', value='http://ccrma.stanford.edu/~jos/mp3/pno-cs.mp3')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, if SciPy is available, the widget may also be constructed from a NumPy array containing int16 values and a `sample_rate`, e.g. in this example we plot a frequency modulated signal:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sps = 44100 # Samples per second\n",
"duration = 10 # Duration in seconds\n",
"\n",
"modulator_frequency = 2.0\n",
"carrier_frequency = 120.0\n",
"modulation_index = 2.0\n",
"\n",
"time = np.arange(sps*duration) / sps\n",
"modulator = np.sin(2.0 * np.pi * modulator_frequency * time) * modulation_index\n",
"carrier = np.sin(2.0 * np.pi * carrier_frequency * time)\n",
"waveform = np.sin(2. * np.pi * (carrier_frequency * time + modulator))\n",
" \n",
"waveform_quiet = waveform * 0.3\n",
"waveform_int = np.int16(waveform_quiet * 32767)\n",
"\n",
"audio = pn.widgets.Audio(value=waveform_int, sample_rate=sps)\n",
"audio"
]
},
Expand Down Expand Up @@ -99,5 +137,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit 56d64b6

Please sign in to comment.