File tree Expand file tree Collapse file tree 3 files changed +14
-9
lines changed
Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1414 "outputs": [],
1515 "source": [
1616 "from io import BytesIO\n",
17+ "import tempfile\n",
1718 "import requests\n",
1819 "import numpy as np\n",
1920 "import scipy.signal as sg\n",
3233 "def speak(data):\n",
3334 " # We convert the mp3 bytes to wav.\n",
3435 " audio = pydub.AudioSegment.from_mp3(BytesIO(data))\n",
35- " wave = audio.export('_', format='wav')\n",
36- " wave.seek(0)\n",
37- " wave = wave.read()\n",
36+ " with tempfile.TemporaryFile() as fn:\n",
37+ " wavef = audio.export(fn, format='wav')\n",
38+ " wavef.seek(0)\n",
39+ " wave = wavef.read()\n",
3840 " # We get the raw data by removing the 24 first bytes\n",
3941 " # of the header.\n",
4042 " x = np.frombuffer(wave, np.int16)[24:] / 2.**15\n",
Original file line number Diff line number Diff line change 114114 " # in a dedicated Output widget.\n " ,
115115 " with widgets.Output():\n " ,
116116 " synth(f)\n " ,
117+ " \n " ,
117118 " button.on_click(partial(on_button_clicked, f))\n " ,
118119 " buttons.append(button)\n " ,
120+ " \n " ,
119121 " # We place all buttons horizontally.\n " ,
120122 " widgets.Box(children=buttons)"
121123 ]
You can’t perform that action at this time.
0 commit comments