{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exemplos de carregamento de sinais de áudio e vídeo de urls e arquivos locais" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import io\n", "from urllib.request import urlopen\n", "import scipy.io.wavfile as wavfile\n", "import soundfile as sf\n", "from imageio import imread\n", "import matplotlib.pyplot as plt\n", "import IPython.display as ipd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# para abrir arquivo wav de url:\n", "url=\"http://static1.grsites.com/archive/sounds/bells/bells004.wav\"\n", "x, rate = sf.read(io.BytesIO(urlopen(url).read()))\n", "plt.plot(x)\n", "plt.show()\n", "ipd.Audio(x.T, rate=rate)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# para abrir arquivo wav local (use um arquivo que esteja no mesmo local):\n", "rate, x = wavfile.read('bells004.wav')\n", "plt.plot(x)\n", "plt.show()\n", "ipd.Audio(x.T, rate=rate)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# para abrir imagem de url\n", "url = \"http://sutherncharm.files.wordpress.com/2009/09/double-ferris.jpg\"\n", "M = imread(urlopen(url).read())\n", "plt.imshow(M)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# escolha um arquivo que esteja no mesmo local\n", "M = imread(\"double-ferris.jpg\")\n", "plt.imshow(M)" ] } ], "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.7.6" } }, "nbformat": 4, "nbformat_minor": 2 }