|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Get started with JupyterLab\n", |
| 8 | + "\n", |
| 9 | + "JupyterLab is a web-based interactive development environment for Jupyter notebooks. It allows you to create and share documents that contain live code, equations, visualizations and narrative text. \n", |
| 10 | + "In this document, you can run python or shell scripts to play sound, plot." |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "metadata": {}, |
| 17 | + "outputs": [], |
| 18 | + "source": [ |
| 19 | + "# run python code\n", |
| 20 | + "import sys\n", |
| 21 | + "print(sys.version)" |
| 22 | + ] |
| 23 | + }, |
| 24 | + { |
| 25 | + "cell_type": "code", |
| 26 | + "execution_count": null, |
| 27 | + "metadata": {}, |
| 28 | + "outputs": [], |
| 29 | + "source": [ |
| 30 | + "# run shell command\n", |
| 31 | + "!uname -a" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": null, |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "# record audio\n", |
| 41 | + "!arecord -f S16_LE -c 1 -r 48000 -d 3 -Vmono 48k.wav" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "code", |
| 46 | + "execution_count": null, |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [], |
| 49 | + "source": [ |
| 50 | + "# play audio on the device\n", |
| 51 | + "!play 48k.wav" |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "execution_count": null, |
| 57 | + "metadata": {}, |
| 58 | + "outputs": [], |
| 59 | + "source": [ |
| 60 | + "# play audio on the browser\n", |
| 61 | + "import IPython.display as ipd\n", |
| 62 | + "ipd.Audio('48k.wav')" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "code", |
| 67 | + "execution_count": null, |
| 68 | + "metadata": {}, |
| 69 | + "outputs": [], |
| 70 | + "source": [ |
| 71 | + "# mix python code and shell command\n", |
| 72 | + "import getpass\n", |
| 73 | + "\n", |
| 74 | + "# get password and install matplotlib\n", |
| 75 | + "password = getpass.getpass()\n", |
| 76 | + "!echo {password} | sudo -S apt install -y python3-matplotlib python3-scipy" |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + "cell_type": "code", |
| 81 | + "execution_count": null, |
| 82 | + "metadata": {}, |
| 83 | + "outputs": [], |
| 84 | + "source": [ |
| 85 | + "import numpy as np\n", |
| 86 | + "import matplotlib.pyplot as plt\n", |
| 87 | + "import scipy.io.wavfile\n", |
| 88 | + "\n", |
| 89 | + "data = scipy.io.wavfile.read('48k.wav')\n", |
| 90 | + "plt.plot(data[1])\n", |
| 91 | + "plt.show()" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": null, |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [], |
| 99 | + "source": [ |
| 100 | + "# Fixing random state for reproducibility\n", |
| 101 | + "np.random.seed(19680801)\n", |
| 102 | + "\n", |
| 103 | + "# Compute pie slices\n", |
| 104 | + "N = 20\n", |
| 105 | + "theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)\n", |
| 106 | + "radii = 10 * np.random.rand(N)\n", |
| 107 | + "width = np.pi / 4 * np.random.rand(N)\n", |
| 108 | + "colors = plt.cm.viridis(radii / 10.)\n", |
| 109 | + "\n", |
| 110 | + "ax = plt.subplot(111, projection='polar')\n", |
| 111 | + "ax.bar(theta, radii, width=width, bottom=0.0, color=colors, alpha=0.5)\n", |
| 112 | + "\n", |
| 113 | + "plt.show()" |
| 114 | + ] |
| 115 | + } |
| 116 | + ], |
| 117 | + "metadata": { |
| 118 | + "kernelspec": { |
| 119 | + "display_name": "Python 3", |
| 120 | + "language": "python", |
| 121 | + "name": "python3" |
| 122 | + }, |
| 123 | + "language_info": { |
| 124 | + "codemirror_mode": { |
| 125 | + "name": "ipython", |
| 126 | + "version": 3 |
| 127 | + }, |
| 128 | + "file_extension": ".py", |
| 129 | + "mimetype": "text/x-python", |
| 130 | + "name": "python", |
| 131 | + "nbconvert_exporter": "python", |
| 132 | + "pygments_lexer": "ipython3", |
| 133 | + "version": "3.6.8" |
| 134 | + } |
| 135 | + }, |
| 136 | + "nbformat": 4, |
| 137 | + "nbformat_minor": 4 |
| 138 | +} |
0 commit comments