ipyaudio 0.1.9__tar.gz → 0.1.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ipyaudio-0.1.11/.yarn/install-state.gz +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.yarnrc.yml +0 -1
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/PKG-INFO +1 -1
- ipyaudio-0.1.11/examples/Untitled.ipynb +103 -0
- ipyaudio-0.1.11/examples/introduction.ipynb +60 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/_frontend.py +1 -1
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/_version.py +1 -1
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/package.json +2 -2
- ipyaudio-0.1.11/ipyaudio/labextension/static/424.ca45437f3ff02b14458c.js +1 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/nbextension/index.js +1 -1
- ipyaudio-0.1.11/ipyaudio/nbextension/index.js.map +1 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/player.py +9 -7
- ipyaudio-0.1.11/ipyaudio/recorder.py +135 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/widget.py +5 -1
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/package.json +1 -1
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/pyproject.toml +2 -2
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/recorder.ts +44 -10
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/wavesurfer/recorder.ts +17 -6
- ipyaudio-0.1.9/.yarn/install-state.gz +0 -0
- ipyaudio-0.1.9/examples/introduction.ipynb +0 -138
- ipyaudio-0.1.9/ipyaudio/labextension/static/424.6dd9a8a74e4a88bf8b52.js +0 -1
- ipyaudio-0.1.9/ipyaudio/labextension/static/remoteEntry.f9ac547af445a24b6fc2.js +0 -1
- ipyaudio-0.1.9/ipyaudio/nbextension/index.js.map +0 -1
- ipyaudio-0.1.9/ipyaudio/recorder.py +0 -96
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.coveragerc +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.eslintignore +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.eslintrc.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.gitignore +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.npmignore +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.prettierignore +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.prettierrc +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/.yarn/releases/yarn-4.8.1.cjs +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/LICENSE.txt +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/MANIFEST.in +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/README.md +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/babel.config.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/codecov.yml +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/css/widget.css +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/Makefile +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/environment.yml +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/make.bat +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/_static/embed-bundle.js.LICENSE.txt +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/_static/helper.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/conf.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/develop-install.rst +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/examples/index.rst +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/examples/introduction.nblink +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/index.rst +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/installing.rst +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/docs/source/introduction.rst +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/examples/sam_altman.wav +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/install.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/__init__.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/configs/player.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/configs/recorder.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/static/122.3700f0454aee82938e32.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/static/509.a9d6860fe38ae60aa71f.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/static/570.97f2a8196b7f1703e636.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/static/570.97f2a8196b7f1703e636.js.LICENSE.txt +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/static/58.0e2f3d700c41688625fe.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/static/style.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/labextension/static/third-party-licenses.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/nbextension/extension.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/nbextension/index.js.LICENSE.txt +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/tests/__init__.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/tests/conftest.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/tests/test_example.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/tests/test_nbextension_path.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio/utils.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/ipyaudio.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/jest.config.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/package-lock.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/pytest.ini +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/readthedocs.yml +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/setup.py +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/__tests__/index.spec.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/__tests__/utils.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/extension.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/index.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/player.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/plugin.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/version.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/wavesurfer/pcm_player.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/wavesurfer/player.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/src/wavesurfer/utils.ts +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/tsconfig.eslint.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/tsconfig.json +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/webpack.config.js +0 -0
- {ipyaudio-0.1.9 → ipyaudio-0.1.11}/yarn.lock +0 -0
Binary file
|
@@ -0,0 +1,103 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": 1,
|
6
|
+
"id": "66603572-848a-4585-bd04-d2e8cec85ba0",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [
|
9
|
+
{
|
10
|
+
"data": {
|
11
|
+
"application/vnd.jupyter.widget-view+json": {
|
12
|
+
"model_id": "af1d05bb4c8d4bbbb68b95b60e58c0fc",
|
13
|
+
"version_major": 2,
|
14
|
+
"version_minor": 0
|
15
|
+
},
|
16
|
+
"text/plain": [
|
17
|
+
"Recorder(value=None, config={'options': {'backend': 'WebAudio', 'container': '', 'waveColor': '#4BF2A7'}, 'rec…"
|
18
|
+
]
|
19
|
+
},
|
20
|
+
"metadata": {},
|
21
|
+
"output_type": "display_data"
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"source": [
|
25
|
+
"from ipyaudio import Recorder, play\n",
|
26
|
+
"recorder = Recorder(verbose=True)"
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"cell_type": "code",
|
31
|
+
"execution_count": 4,
|
32
|
+
"id": "3c8cc80a-6272-4f13-93ae-f437d45d7735",
|
33
|
+
"metadata": {},
|
34
|
+
"outputs": [
|
35
|
+
{
|
36
|
+
"data": {
|
37
|
+
"application/vnd.jupyter.widget-view+json": {
|
38
|
+
"model_id": "c1ceee2887c74976baf2b07a9b284562",
|
39
|
+
"version_major": 2,
|
40
|
+
"version_minor": 0
|
41
|
+
},
|
42
|
+
"text/plain": [
|
43
|
+
"Player(value=None, config={'options': {'autoScroll': True, 'backend': 'WebAudio', 'container': '', 'cursorColo…"
|
44
|
+
]
|
45
|
+
},
|
46
|
+
"metadata": {},
|
47
|
+
"output_type": "display_data"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"ename": "ValueError",
|
51
|
+
"evalue": "zero-size array to reduction operation maximum which has no identity",
|
52
|
+
"output_type": "error",
|
53
|
+
"traceback": [
|
54
|
+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
55
|
+
"\u001b[31mValueError\u001b[39m Traceback (most recent call last)",
|
56
|
+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mplay\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecorder\u001b[49m\u001b[43m.\u001b[49m\u001b[43maudio\u001b[49m\u001b[43m)\u001b[49m\n",
|
57
|
+
"\u001b[36mFile \u001b[39m\u001b[32m~/code/ipyaudio/ipyaudio/widget.py:27\u001b[39m, in \u001b[36mplay\u001b[39m\u001b[34m(audio, rate, config, language, verbose)\u001b[39m\n\u001b[32m 20\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mplay\u001b[39m(\n\u001b[32m 21\u001b[39m audio: Union[\u001b[38;5;28mstr\u001b[39m, Path, np.ndarray, torch.Tensor, Cut, Recording, AsyncGeneratorType, GeneratorType],\n\u001b[32m 22\u001b[39m rate: Optional[\u001b[38;5;28mint\u001b[39m] = \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m (...)\u001b[39m\u001b[32m 25\u001b[39m verbose: \u001b[38;5;28mbool\u001b[39m = \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[32m 26\u001b[39m ):\n\u001b[32m---> \u001b[39m\u001b[32m27\u001b[39m \u001b[43mPlayer\u001b[49m\u001b[43m(\u001b[49m\u001b[43maudio\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrate\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlanguage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mverbose\u001b[49m\u001b[43m)\u001b[49m\u001b[43m.\u001b[49m\u001b[43mplay\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
|
58
|
+
"\u001b[36mFile \u001b[39m\u001b[32m~/code/ipyaudio/ipyaudio/player.py:101\u001b[39m, in \u001b[36mPlayer.play\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 98\u001b[39m start = time.time()\n\u001b[32m 99\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m._audio, (\u001b[38;5;28mstr\u001b[39m, Path, np.ndarray, torch.Tensor, Cut, Recording)):\n\u001b[32m 100\u001b[39m \u001b[38;5;66;03m# [num_channels, num_samples]\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m101\u001b[39m \u001b[38;5;28mself\u001b[39m.audio, \u001b[38;5;28mself\u001b[39m.rate = \u001b[43mencode\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_audio\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrate\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 102\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m._audio, AsyncGeneratorType):\n\u001b[32m 103\u001b[39m asyncio.create_task(\u001b[38;5;28mself\u001b[39m.async_encode(\u001b[38;5;28mself\u001b[39m._audio, \u001b[38;5;28mself\u001b[39m.rate, start))\n",
|
59
|
+
"\u001b[36mFile \u001b[39m\u001b[32m~/code/ipyaudio/ipyaudio/utils.py:34\u001b[39m, in \u001b[36mencode\u001b[39m\u001b[34m(audio, rate, make_wav)\u001b[39m\n\u001b[32m 32\u001b[39m audio = audio.load_audio()\n\u001b[32m 33\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m make_wav:\n\u001b[32m---> \u001b[39m\u001b[32m34\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mAudio\u001b[49m\u001b[43m(\u001b[49m\u001b[43maudio\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrate\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrate\u001b[49m\u001b[43m)\u001b[49m.src_attr(), rate\n\u001b[32m 35\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m audio.dtype == np.int16:\n\u001b[32m 36\u001b[39m audio = audio.astype(np.float32) / \u001b[32m32768\u001b[39m\n",
|
60
|
+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniforge/base/envs/ipyaudio-dev/lib/python3.13/site-packages/IPython/lib/display.py:130\u001b[39m, in \u001b[36mAudio.__init__\u001b[39m\u001b[34m(self, data, filename, url, embed, rate, autoplay, normalize, element_id)\u001b[39m\n\u001b[32m 128\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m rate \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m 129\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[33m\"\u001b[39m\u001b[33mrate must be specified when data is a numpy array or list of audio samples.\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m--> \u001b[39m\u001b[32m130\u001b[39m \u001b[38;5;28mself\u001b[39m.data = \u001b[43mAudio\u001b[49m\u001b[43m.\u001b[49m\u001b[43m_make_wav\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrate\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnormalize\u001b[49m\u001b[43m)\u001b[49m\n",
|
61
|
+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniforge/base/envs/ipyaudio-dev/lib/python3.13/site-packages/IPython/lib/display.py:152\u001b[39m, in \u001b[36mAudio._make_wav\u001b[39m\u001b[34m(data, rate, normalize)\u001b[39m\n\u001b[32m 149\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mwave\u001b[39;00m\n\u001b[32m 151\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m152\u001b[39m scaled, nchan = \u001b[43mAudio\u001b[49m\u001b[43m.\u001b[49m\u001b[43m_validate_and_normalize_with_numpy\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnormalize\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 153\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m:\n\u001b[32m 154\u001b[39m scaled, nchan = Audio._validate_and_normalize_without_numpy(data, normalize)\n",
|
62
|
+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniforge/base/envs/ipyaudio-dev/lib/python3.13/site-packages/IPython/lib/display.py:185\u001b[39m, in \u001b[36mAudio._validate_and_normalize_with_numpy\u001b[39m\u001b[34m(data, normalize)\u001b[39m\n\u001b[32m 182\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 183\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[33m'\u001b[39m\u001b[33mArray audio input must be a 1D or 2D array\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m--> \u001b[39m\u001b[32m185\u001b[39m max_abs_value = \u001b[43mnp\u001b[49m\u001b[43m.\u001b[49m\u001b[43mmax\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnp\u001b[49m\u001b[43m.\u001b[49m\u001b[43mabs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 186\u001b[39m normalization_factor = Audio._get_normalization_factor(max_abs_value, normalize)\n\u001b[32m 187\u001b[39m scaled = data / normalization_factor * \u001b[32m32767\u001b[39m\n",
|
63
|
+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniforge/base/envs/ipyaudio-dev/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3164\u001b[39m, in \u001b[36mmax\u001b[39m\u001b[34m(a, axis, out, keepdims, initial, where)\u001b[39m\n\u001b[32m 3052\u001b[39m \u001b[38;5;129m@array_function_dispatch\u001b[39m(_max_dispatcher)\n\u001b[32m 3053\u001b[39m \u001b[38;5;129m@set_module\u001b[39m(\u001b[33m'\u001b[39m\u001b[33mnumpy\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m 3054\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mmax\u001b[39m(a, axis=\u001b[38;5;28;01mNone\u001b[39;00m, out=\u001b[38;5;28;01mNone\u001b[39;00m, keepdims=np._NoValue, initial=np._NoValue,\n\u001b[32m 3055\u001b[39m where=np._NoValue):\n\u001b[32m 3056\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 3057\u001b[39m \u001b[33;03m Return the maximum of an array or maximum along an axis.\u001b[39;00m\n\u001b[32m 3058\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 3162\u001b[39m \u001b[33;03m 5\u001b[39;00m\n\u001b[32m 3163\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m3164\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_wrapreduction\u001b[49m\u001b[43m(\u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnp\u001b[49m\u001b[43m.\u001b[49m\u001b[43mmaximum\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mmax\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 3165\u001b[39m \u001b[43m \u001b[49m\u001b[43mkeepdims\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkeepdims\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minitial\u001b[49m\u001b[43m=\u001b[49m\u001b[43minitial\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mwhere\u001b[49m\u001b[43m=\u001b[49m\u001b[43mwhere\u001b[49m\u001b[43m)\u001b[49m\n",
|
64
|
+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniforge/base/envs/ipyaudio-dev/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:86\u001b[39m, in \u001b[36m_wrapreduction\u001b[39m\u001b[34m(obj, ufunc, method, axis, dtype, out, **kwargs)\u001b[39m\n\u001b[32m 83\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 84\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m reduction(axis=axis, out=out, **passkwargs)\n\u001b[32m---> \u001b[39m\u001b[32m86\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mufunc\u001b[49m\u001b[43m.\u001b[49m\u001b[43mreduce\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mpasskwargs\u001b[49m\u001b[43m)\u001b[49m\n",
|
65
|
+
"\u001b[31mValueError\u001b[39m: zero-size array to reduction operation maximum which has no identity"
|
66
|
+
]
|
67
|
+
}
|
68
|
+
],
|
69
|
+
"source": [
|
70
|
+
"play(recorder.audio)"
|
71
|
+
]
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"cell_type": "code",
|
75
|
+
"execution_count": null,
|
76
|
+
"id": "af3d9186-a81a-4b76-b910-a90e222a92b0",
|
77
|
+
"metadata": {},
|
78
|
+
"outputs": [],
|
79
|
+
"source": []
|
80
|
+
}
|
81
|
+
],
|
82
|
+
"metadata": {
|
83
|
+
"kernelspec": {
|
84
|
+
"display_name": "Python 3 (ipykernel)",
|
85
|
+
"language": "python",
|
86
|
+
"name": "python3"
|
87
|
+
},
|
88
|
+
"language_info": {
|
89
|
+
"codemirror_mode": {
|
90
|
+
"name": "ipython",
|
91
|
+
"version": 3
|
92
|
+
},
|
93
|
+
"file_extension": ".py",
|
94
|
+
"mimetype": "text/x-python",
|
95
|
+
"name": "python",
|
96
|
+
"nbconvert_exporter": "python",
|
97
|
+
"pygments_lexer": "ipython3",
|
98
|
+
"version": "3.13.2"
|
99
|
+
}
|
100
|
+
},
|
101
|
+
"nbformat": 4,
|
102
|
+
"nbformat_minor": 5
|
103
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "markdown",
|
5
|
+
"metadata": {},
|
6
|
+
"source": [
|
7
|
+
"# Introduction"
|
8
|
+
]
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"cell_type": "code",
|
12
|
+
"execution_count": null,
|
13
|
+
"metadata": {},
|
14
|
+
"outputs": [],
|
15
|
+
"source": [
|
16
|
+
"import ipyaudio"
|
17
|
+
]
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"cell_type": "code",
|
21
|
+
"execution_count": null,
|
22
|
+
"metadata": {},
|
23
|
+
"outputs": [],
|
24
|
+
"source": [
|
25
|
+
"w = ipyaudio.ExampleWidget()\n",
|
26
|
+
"w"
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"cell_type": "code",
|
31
|
+
"execution_count": null,
|
32
|
+
"metadata": {},
|
33
|
+
"outputs": [],
|
34
|
+
"source": [
|
35
|
+
"assert w.value == 'Hello World'"
|
36
|
+
]
|
37
|
+
}
|
38
|
+
],
|
39
|
+
"metadata": {
|
40
|
+
"kernelspec": {
|
41
|
+
"display_name": "Python 3",
|
42
|
+
"language": "python",
|
43
|
+
"name": "python3"
|
44
|
+
},
|
45
|
+
"language_info": {
|
46
|
+
"codemirror_mode": {
|
47
|
+
"name": "ipython",
|
48
|
+
"version": 3
|
49
|
+
},
|
50
|
+
"file_extension": ".py",
|
51
|
+
"mimetype": "text/x-python",
|
52
|
+
"name": "python",
|
53
|
+
"nbconvert_exporter": "python",
|
54
|
+
"pygments_lexer": "ipython3",
|
55
|
+
"version": "3.6.3"
|
56
|
+
}
|
57
|
+
},
|
58
|
+
"nbformat": 4,
|
59
|
+
"nbformat_minor": 2
|
60
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ipyaudio",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.11",
|
4
4
|
"description": "A Custom Jupyter Widget Library",
|
5
5
|
"keywords": [
|
6
6
|
"jupyter",
|
@@ -101,7 +101,7 @@
|
|
101
101
|
}
|
102
102
|
},
|
103
103
|
"_build": {
|
104
|
-
"load": "static
|
104
|
+
"load": "static",
|
105
105
|
"extension": "./extension"
|
106
106
|
}
|
107
107
|
},
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";(self.webpackChunkipyaudio=self.webpackChunkipyaudio||[]).push([[424],{319:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function r(e){try{l(n.next(e))}catch(e){a(e)}}function o(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.RecorderView=t.RecorderModel=void 0;const a=s(i(5364)),r=i(3459),o=i(3983),l=i(1797),c=s(i(8020));i(6378),i(1463);class d extends o.DOMWidgetModel{defaults(){return Object.assign(Object.assign({},super.defaults()),{_model_name:d.model_name,_model_module:d.model_module,_model_module_version:d.model_module_version,_view_name:d.view_name,_view_module:d.view_module,_view_module_version:d.view_module_version,chunk:new Uint8Array(0),rate:16e3,end:!1})}}t.RecorderModel=d,d.serializers=Object.assign(Object.assign({},o.DOMWidgetModel.serializers),{chunk:r.simplearray_serialization}),d.model_name="RecorderModel",d.model_module=l.MODULE_NAME,d.model_module_version=l.MODULE_VERSION,d.view_name="RecorderView",d.view_module=l.MODULE_NAME,d.view_module_version=l.MODULE_VERSION;class u extends o.DOMWidgetView{constructor(){super(...arguments),this._chunks=[],this._isFirstChunk=!0,this._isCompleted=!1}_sendChunk(){if(this._chunks.length>0){const e=this._chunks[0];this.model.set("chunk",{array:e,shape:[e.length]}),this.model.save_changes(),this._chunks.shift()}else this._isCompleted&&(this.model.set("completed",!0),this.model.save_changes())}render(){super.render(),this.displayed.then((()=>n(this,void 0,void 0,(function*(){const e=this.model.get("language");this._recorder=c.default.create((0,a.default)({},this.model.get("config"),{language:e}),(0,a.default)({},this.model.get("player_config"),{language:e})),this.el.appendChild(this._recorder.el),this.model.on("msg:custom",(e=>n(this,void 0,void 0,(function*(){var t;const i=3e3+(null!==(t=this._recorder.timeSlice)&&void 0!==t?t:32),n=Date.now();if("chunk_received"===e.msg_type){for(;0===this._chunks.length&&Date.now()-n<i;)yield new Promise((e=>setTimeout(e,32)));this._sendChunk()}})))),this._recorder.onRecordStart((()=>{this._isCompleted=!1,this._isFirstChunk=!0,this.model.set("completed",!1),this.model.set("rate",this._recorder.sampleRate),this.model.save_changes()})),this._recorder.onRecordChunk((e=>n(this,void 0,void 0,(function*(){this._chunks.push(new Uint8Array(yield e.arrayBuffer())),this.model.get("sync")&&this._isFirstChunk&&(this._isFirstChunk=!1,this._sendChunk())})))),this._recorder.onRecordEnd((e=>n(this,void 0,void 0,(function*(){this._isCompleted=!0,this.model.get("sync")||(this.model.set("completed",!0),this.model.save_changes())}))))}))))}}t.RecorderView=u},1144:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 fill=%27%23fff%27%3e%3cpath d=%27M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z%27/%3e%3c/svg%3e"},1463:(e,t,i)=>{i.r(t),i.d(t,{default:()=>v});var n=i(5072),s=i.n(n),a=i(7825),r=i.n(a),o=i(7659),l=i.n(o),c=i(5056),d=i.n(c),u=i(540),h=i.n(u),m=i(1113),p=i.n(m),_=i(4930),g={};g.styleTagTransform=p(),g.setAttributes=d(),g.insert=l().bind(null,"head"),g.domAPI=r(),g.insertStyleElement=h(),s()(_.A,g);const v=_.A&&_.A.locals?_.A.locals:void 0},1797:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MODULE_NAME=t.MODULE_VERSION=void 0;const n=i(8330);t.MODULE_VERSION=n.version,t.MODULE_NAME=n.name},2247:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 30 30%27%3e%3cpath stroke=%27rgba%2833, 37, 41, 0.75%29%27 stroke-linecap=%27round%27 stroke-miterlimit=%2710%27 stroke-width=%272%27 d=%27M4 7h22M4 15h22M4 23h22%27/%3e%3c/svg%3e"},3385:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%27-4 -4 8 8%27%3e%3ccircle r=%272%27 fill=%27%23fff%27/%3e%3c/svg%3e"},4274:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 20 20%27%3e%3cpath fill=%27none%27 stroke=%27%23fff%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27 stroke-width=%273%27 d=%27M6 10h8%27/%3e%3c/svg%3e"},4364:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function r(e){try{l(n.next(e))}catch(e){a(e)}}function o(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.PlayerView=t.PlayerModel=void 0;const a=s(i(5364)),r=i(3983),o=i(1797),l=s(i(9155));i(6378),i(1463);class c extends r.DOMWidgetModel{defaults(){return Object.assign(Object.assign({},super.defaults()),{_model_name:c.model_name,_model_module:c.model_module,_model_module_version:c.model_module_version,_view_name:c.view_name,_view_module:c.view_module,_view_module_version:c.view_module_version})}}t.PlayerModel=c,c.serializers=Object.assign({},r.DOMWidgetModel.serializers),c.model_name="PlayerModel",c.model_module=o.MODULE_NAME,c.model_module_version=o.MODULE_VERSION,c.view_name="PlayerView",c.view_module=o.MODULE_NAME,c.view_module_version=o.MODULE_VERSION;class d extends r.DOMWidgetView{render(){super.render(),this.displayed.then((()=>n(this,void 0,void 0,(function*(){const e={isStreaming:this.model.get("is_streaming"),language:this.model.get("language")};this._player=l.default.create((0,a.default)({},this.model.get("config"),e)),this.el.appendChild(this._player.el),this.model.on("change:audio",(()=>{this._player.sampleRate=this.model.get("rate"),this._player.load(this.model.get("audio"))})),this.model.on("change:is_done",(()=>{this._player.setDone()}))}))))}}t.PlayerView=d},4718:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%27-4 -4 8 8%27%3e%3ccircle r=%273%27 fill=%27%23fff%27/%3e%3c/svg%3e"},4930:(e,t,i)=>{i.d(t,{A:()=>o});var n=i(1601),s=i.n(n),a=i(6314),r=i.n(a)()(s());r.push([e.id,".waveform {\n background-color: black;\n cursor: pointer;\n position: relative;\n width: 100%;\n}\n\n.duration, .time {\n background: rgba(0, 0, 0, 0.75);\n color: #DDDD;\n font-size: 11px;\n position: absolute;\n bottom: 0;\n z-index: 11;\n}\n\n.duration {\n right: 0;\n}\n\n.time {\n left: 0;\n}\n",""]);const o=r},5372:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 12 12%27 width=%2712%27 height=%2712%27 fill=%27none%27 stroke=%27%23dc3545%27%3e%3ccircle cx=%276%27 cy=%276%27 r=%274.5%27/%3e%3cpath stroke-linejoin=%27round%27 d=%27M5.8 3.6h.4L6 6.5z%27/%3e%3ccircle cx=%276%27 cy=%278.2%27 r=%27.6%27 fill=%27%23dc3545%27 stroke=%27none%27/%3e%3c/svg%3e"},5419:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 20 20%27%3e%3cpath fill=%27none%27 stroke=%27%23fff%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27 stroke-width=%273%27 d=%27m6 10 3 3 6-6%27/%3e%3c/svg%3e"},5531:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3e%3cpath fill=%27none%27 stroke=%27%23343a40%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27 stroke-width=%272%27 d=%27m2 5 6 6 6-6%27/%3e%3c/svg%3e"},5782:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%27-4 -4 8 8%27%3e%3ccircle r=%273%27 fill=%27%2386b7fe%27/%3e%3c/svg%3e"},5932:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 fill=%27%23fff%27%3e%3cpath d=%27M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z%27/%3e%3c/svg%3e"},6366:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 30 30%27%3e%3cpath stroke=%27rgba%28255, 255, 255, 0.55%29%27 stroke-linecap=%27round%27 stroke-miterlimit=%2710%27 stroke-width=%272%27 d=%27M4 7h22M4 15h22M4 23h22%27/%3e%3c/svg%3e"},6690:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 fill=%27%236ea8fe%27%3e%3cpath fill-rule=%27evenodd%27 d=%27M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z%27/%3e%3c/svg%3e"},7115:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3e%3cpath fill=%27none%27 stroke=%27%23dee2e6%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27 stroke-width=%272%27 d=%27m2 5 6 6 6-6%27/%3e%3c/svg%3e"},7154:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%27-4 -4 8 8%27%3e%3ccircle r=%273%27 fill=%27rgba%280, 0, 0, 0.25%29%27/%3e%3c/svg%3e"},7210:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 fill=%27none%27 stroke=%27%23052c65%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3e%3cpath d=%27M2 5L8 11L14 5%27/%3e%3c/svg%3e"},7249:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 fill=%27%23000%27%3e%3cpath d=%27M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z%27/%3e%3c/svg%3e"},7326:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 fill=%27none%27 stroke=%27%23212529%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3e%3cpath d=%27M2 5L8 11L14 5%27/%3e%3c/svg%3e"},7997:(e,t)=>{function i(e){const t=e.numFrames,i=e.numChannels||2,n=e.sampleRate||44100,s=e.isFloat?4:2,a=e.isFloat?3:1,r=i*s,o=n*r,l=t*r,c=new ArrayBuffer(44),d=new DataView(c);let u=0;function h(e){for(let t=0;t<e.length;t++)d.setUint8(u+t,e.charCodeAt(t));u+=e.length}function m(e){d.setUint32(u,e,!0),u+=4}function p(e){d.setUint16(u,e,!0),u+=2}return h("RIFF"),m(l+36),h("WAVE"),h("fmt "),m(16),p(a),p(i),m(n),m(o),p(r),p(8*s),h("data"),m(l),new Uint8Array(c)}function n(e,t){if(!e)return new Uint8Array;let n,s;e instanceof ArrayBuffer?(n=i({isFloat:!1,numChannels:t.numChannels,sampleRate:t.sampleRate,numFrames:e.byteLength/Int16Array.BYTES_PER_ELEMENT}),s=new Uint8Array(e)):(n=i({isFloat:!1,numChannels:e.numberOfChannels,sampleRate:e.sampleRate,numFrames:e.length}),s=new Uint8Array(function(e){const{numberOfChannels:t,length:i}=e,n=new Int16Array(i*t);for(let s=0;s<t;s++){const a=e.getChannelData(s),r=a instanceof Float32Array;for(let e=0;e<i;e++)n[e*t+s]=r?32767*a[e]:a[e]}return n}(e).buffer));const a=new Uint8Array(n.length+s.length);return a.set(n,0),a.set(s,n.length),a}Object.defineProperty(t,"__esModule",{value:!0}),t.createObjectURL=t.formatTime=t.createElement=void 0,t.createElement=(e,t,i="")=>{const n=document.createElement(e);return n.className=t,n.innerHTML=i,n},t.formatTime=e=>`${Math.floor(e/60)}:${("0"+Math.round(e)%60).slice(-2)}`,t.createObjectURL=(e,t={numChannels:1,sampleRate:44100})=>{let i;return i=e instanceof AudioBuffer?n(e,{numChannels:e.numberOfChannels,sampleRate:e.sampleRate}):n(e,t),URL.createObjectURL(new Blob([i],{type:"audio/wav"}))}},8020:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function r(e){try{l(n.next(e))}catch(e){a(e)}}function o(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=s(i(423)),r=s(i(8429)),o=s(i(9155)),l=i(7997);class c{constructor(e,t){this.el=(0,l.createElement)("div","lm-Widget"),this._container=(0,l.createElement)("div","waveform"),this._currentTime=(0,l.createElement)("div","time","0:00"),this._container.append(this._currentTime),this._config=e,this._player=o.default.create(t)}get sampleRate(){return this._wavesurfer.options.sampleRate}get timeSlice(){var e;return null===(e=this._config.recordOptions)||void 0===e?void 0:e.mediaRecorderTimeslice}set sampleRate(e){this._wavesurfer.options.sampleRate=e,this._player.sampleRate=e}createWaveSurfer(){this._wavesurfer=a.default.create(Object.assign(Object.assign({},this._config.options),{container:this._container}))}createRateSelect(){this._rateSelect=(0,l.createElement)("select","form-select-sm d-inline-block me-3 my-3 w-25"),[8e3,16e3,22050,24e3,44100,48e3].forEach((e=>{const t=document.createElement("option");t.value=e.toString(),t.text=`${e} Hz`,16e3===e&&(t.selected=!0),this._rateSelect.appendChild(t)}))}createMicSelect(){this._micSelect=(0,l.createElement)("select","form-select-sm d-inline-block me-3 my-3 w-50"),navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((e=>{r.default.getAvailableAudioDevices().then((e=>{e.forEach((e=>{const t=document.createElement("option");t.value=e.deviceId,t.text=e.label||e.deviceId,this._micSelect.appendChild(t)}))}))})).catch((e=>{const t="zh"===this._config.language?"访问麦克风失败":"Error accessing the microphone: ";throw new Error(t+e.message)}))}createPauseButton(){this._pauseButton=(0,l.createElement)("button","btn btn-outline-danger me-3 my-3",'<i class="fa fa-pause"></i>'),this._pauseButton.disabled=!0,this._pauseButton.onclick=()=>{this._recorder.isRecording()?(this._recorder.pauseRecording(),this._pauseButton.innerHTML='<i class="fa fa-play"></i>',this._container.style.display="none",this._player.el.style.display="block"):(this._recorder.resumeRecording(),this._pauseButton.innerHTML='<i class="fa fa-pause"></i>',this._container.style.display="block",this._player.el.style.display="none")}}createRecordButton(){this._recordButton=(0,l.createElement)("button","btn btn-danger me-3 my-3",'<i class="fa fa-microphone"></i>'),this._recordButton.onclick=()=>{this._recorder.isRecording()||this._recorder.isPaused()?(this._recorder.stopRecording(),this._container.style.display="none",this._player.el.style.display="block"):(this._wavesurfer.options.normalize=!1,this.sampleRate=parseInt(this._rateSelect.value),this._recorder.startRecording({deviceId:this._micSelect.value}).then((()=>{this._pauseButton.disabled=!1,this._rateSelect.disabled=!0,this._micSelect.disabled=!0,this._pauseButton.innerHTML='<i class="fa fa-pause"></i>',this._recordButton.innerHTML='<i class="fa fa-stop"></i>',this._container.style.display="block",this._player.el.style.display="none"})))}}onRecordStart(e){this._recorder.on("record-start",(()=>{e()}))}onRecordChunk(e){this._recorder.on("record-data-available",(t=>{e(t)}))}onRecordEnd(e){this._recorder.on("record-end",(t=>n(this,void 0,void 0,(function*(){this._player.load(URL.createObjectURL(t)),this._recordButton.disabled=!0,this._pauseButton.disabled=!0,yield e(t),this._recordButton.disabled=!1,this._pauseButton.disabled=!0,this._rateSelect.disabled=!1,this._micSelect.disabled=!1,this._pauseButton.innerHTML='<i class="fa fa-play"></i>',this._recordButton.innerHTML='<i class="fa fa-microphone"></i>'}))))}createRecorder(){this._wavesurfer.toggleInteraction(!1),this._recorder=this._wavesurfer.registerPlugin(r.default.create(this._config.recordOptions)),this.createRateSelect(),this.createMicSelect(),this.createPauseButton(),this.createRecordButton(),this._container.style.display="none",this._player.el.style.display="none",this.el.append(this._recordButton,this._pauseButton,this._rateSelect,this._micSelect,this._container,this._player.el),this._recorder.on("record-pause",(e=>{this._player.load(URL.createObjectURL(e))})),this._recorder.on("record-progress",(e=>{this._currentTime.textContent=(0,l.formatTime)(e/1e3)}))}static create(e,t){const i=new c(e,t);return i.createWaveSurfer(),i.createRecorder(),i}}t.default=c},8078:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function r(e){try{l(n.next(e))}catch(e){a(e)}}function o(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.PCMPlayer=void 0;const s=i(7997);class a{constructor(e){this._isDone=!1,this._isPlaying=!0,this._samples=new Int16Array(0),this._allSamples=new Int16Array(0),this._options=Object.assign({channels:1,sampleRate:16e3,flushTime:100,language:"en"},e),this.playButton=(0,s.createElement)("button","btn btn-danger me-3 my-3",'<i class="fa fa-pause"></i>'),this.playButton.onclick=()=>{this._isPlaying=!this._isPlaying,this._isPlaying?this.play():this.pause(),this.playButton.innerHTML=`<i class="fa fa-${this._isPlaying?"pause":"play"}"></i>`},this._interval=window.setInterval(this.flush.bind(this),this._options.flushTime),this._audioCtx=new(window.AudioContext||window.webkitAudioContext),this._gainNode=this._audioCtx.createGain(),this._gainNode.gain.value=1,this._gainNode.connect(this._audioCtx.destination),this._startTime=this._audioCtx.currentTime}set sampleRate(e){this._options.sampleRate=e}setDone(){this._isDone=!0}feed(e){const t=atob(e),i=new ArrayBuffer(t.length),n=new Uint8Array(i);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);const s=new Int16Array(i);this._samples=new Int16Array([...this._samples,...s]),this._allSamples=new Int16Array([...this._allSamples,...s])}get url(){return(0,s.createObjectURL)(this._allSamples.buffer,{numChannels:this._options.channels,sampleRate:this._options.sampleRate})}flush(){if(!this._samples.length)return;const e=this._isDone,t=this._audioCtx.createBufferSource(),i=this._samples.length/this._options.channels,n=this._audioCtx.createBuffer(this._options.channels,i,this._options.sampleRate);for(let e=0;e<this._options.channels;e++){const t=n.getChannelData(e);let s=e;for(let e=0;e<i;e++)t[e]=this._samples[s]/32768,s+=this._options.channels}this._startTime=Math.max(this._startTime,this._audioCtx.currentTime),t.buffer=n,t.connect(this._gainNode),t.start(this._startTime),t.onended=()=>{this.playButton.disabled=!!e},this._startTime+=n.duration,this._samples=new Int16Array(0)}play(){return n(this,void 0,void 0,(function*(){yield this._audioCtx.resume()}))}pause(){return n(this,void 0,void 0,(function*(){yield this._audioCtx.suspend()}))}volume(e){this._gainNode.gain.value=e}destroy(){this._interval&&clearInterval(this._interval),this._samples=new Int16Array(0),this._audioCtx.close()}}t.PCMPlayer=a,t.default=a},8330:e=>{e.exports=JSON.parse('{"name":"ipyaudio","version":"0.1.11","description":"A Custom Jupyter Widget Library","keywords":["jupyter","jupyterlab","jupyterlab-extension","widgets"],"files":["lib/**/*.js","dist/*.js","css/*.css"],"homepage":"https://github.com/pengzhendong/ipyaudio","bugs":{"url":"https://github.com/pengzhendong/ipyaudio/issues"},"license":"BSD-3-Clause","author":{"name":"Zhendong Peng","email":"pzd17@tsinghua.org.cn"},"main":"lib/index.js","types":"./lib/index.d.ts","repository":{"type":"git","url":"git+https://github.com/pengzhendong/ipyaudio.git"},"scripts":{"build":"jlpm run build:lib && jlpm run build:nbextension && jlpm run build:labextension:dev","build:prod":"jlpm run build:lib && jlpm run build:nbextension && jlpm run build:labextension","build:labextension":"jupyter labextension build .","build:labextension:dev":"jupyter labextension build --development True .","build:lib":"tsc","build:nbextension":"webpack","clean":"jlpm run clean:lib && jlpm run clean:nbextension && jlpm run clean:labextension","clean:lib":"rimraf lib","clean:labextension":"rimraf ipyaudio/labextension","clean:nbextension":"rimraf ipyaudio/nbextension/static/index.js","lint":"eslint . --ext .ts,.tsx --fix","lint:check":"eslint . --ext .ts,.tsx","prepack":"jlpm run build:lib","test":"jest","watch":"npm-run-all -p \\"watch:*\\"","watch:lib":"tsc -w","watch:nbextension":"webpack --watch --mode=development","watch:labextension":"jupyter labextension watch ."},"dependencies":{"@jupyter-widgets/base":"^1.1.10 || ^2 || ^3 || ^4 || ^5 || ^6","bootstrap":"^5.3.3","jupyter-dataserializers":"^3.0.1","lodash.merge":"^4.6.2"},"devDependencies":{"@babel/core":"^7.23.7","@babel/preset-env":"^7.23.8","@jupyter-widgets/base-manager":"^1.0.7","@jupyterlab/builder":"^4.0.11","@lumino/application":"^2.3.0","@lumino/widgets":"^2.3.1","@types/jest":"^29.5.11","@types/webpack-env":"^1.18.4","@typescript-eslint/eslint-plugin":"^6.19.1","@typescript-eslint/parser":"^6.19.1","acorn":"^8.11.3","css-loader":"^6.9.1","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3","fs-extra":"^11.2.0","identity-obj-proxy":"^3.0.0","jest":"^29.7.0","mkdirp":"^3.0.1","npm-run-all":"^4.1.5","prettier":"^3.2.4","rimraf":"^5.0.5","source-map-loader":"^5.0.0","style-loader":"^3.3.4","ts-jest":"^29.1.2","ts-loader":"^9.5.1","typescript":"~5.3.3","wavesurfer.js":"^7.9.1","webpack":"^5.90.0","webpack-cli":"^5.1.4"},"devDependenciesComments":{"@jupyterlab/builder":"pinned to the latest JupyterLab 3.x release","@lumino/application":"pinned to the latest Lumino 1.x release","@lumino/widgets":"pinned to the latest Lumino 1.x release"},"jupyterlab":{"extension":"lib/plugin","outputDir":"ipyaudio/labextension/","sharedPackages":{"@jupyter-widgets/base":{"bundled":false,"singleton":true}}},"packageManager":"yarn@4.8.1"}')},8487:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 8 8%27%3e%3cpath fill=%27%23198754%27 d=%27M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z%27/%3e%3c/svg%3e"},8734:e=>{e.exports="data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%27-4 -4 8 8%27%3e%3ccircle r=%273%27 fill=%27rgba%28255, 255, 255, 0.25%29%27/%3e%3c/svg%3e"},9155:function(e,t,i){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(423)),a=n(i(980)),r=n(i(8659)),o=n(i(8541)),l=n(i(1427)),c=n(i(3875)),d=n(i(8078)),u=i(7997);class h{constructor(e){this.el=(0,u.createElement)("div","lm-Widget"),this._container=(0,u.createElement)("div","waveform"),this._duration=(0,u.createElement)("div","duration","0:00"),this._currentTime=(0,u.createElement)("div","time","0:00"),this._container.append(this._duration,this._currentTime),this.el.append(this._container),this._config=e}get url(){return this._config.isStreaming?this._pcmPlayer.url:(0,u.createObjectURL)(this._wavesurfer.getDecodedData())}set sampleRate(e){this._config.isStreaming&&(this._pcmPlayer.sampleRate=e),this._wavesurfer.options.sampleRate=e}load(e){this._config.isStreaming?(this._pcmPlayer.feed(e),this._wavesurfer.load(this.url)):this._wavesurfer.load(e)}setDone(){this._pcmPlayer.setDone()}createPCMPlayer(){this._config.isStreaming&&(this._pcmPlayer=new d.default({channels:1,sampleRate:this._config.options.sampleRate}),this.el.append(this._pcmPlayer.playButton))}createDownloadButton(){this._downloadButton=(0,u.createElement)("button","btn btn-success my-3");const e="zh"===this._config.language?"下载":"Download";this._downloadButton.innerHTML=`${e} <i class="fa fa-download"></i>`,this.el.append(this._downloadButton),this._downloadButton.onclick=()=>{const e=document.createElement("a");e.href=this.url,e.download="audio.wav",e.click()}}static createPlugins(e){var t;const i={hover:()=>{var t;return a.default.create(null===(t=e.pluginOptions)||void 0===t?void 0:t.hover)},minimap:()=>{var t,i;return r.default.create(Object.assign(Object.assign({},null===(t=e.pluginOptions)||void 0===t?void 0:t.minimap),{plugins:[a.default.create(Object.assign(Object.assign({},null===(i=e.pluginOptions)||void 0===i?void 0:i.hover),{lineWidth:1}))]}))},spectrogram:()=>{var t;return o.default.create(null===(t=e.pluginOptions)||void 0===t?void 0:t.spectrogram)},timeline:()=>{var t;return l.default.create(null===(t=e.pluginOptions)||void 0===t?void 0:t.timeline)},zoom:()=>{var t;return c.default.create(null===(t=e.pluginOptions)||void 0===t?void 0:t.zoom)}};return Array.from(null!==(t=e.plugins)&&void 0!==t?t:[]).map((e=>{var t;return null===(t=i[e])||void 0===t?void 0:t.call(i)})).filter(Boolean)}createWaveSurfer(){this._wavesurfer=s.default.create(Object.assign(Object.assign({},this._config.options),{container:this._container,plugins:h.createPlugins(this._config)})),this._wavesurfer.on("interaction",(()=>this._wavesurfer.playPause())),this._wavesurfer.on("decode",(e=>this._duration.textContent=(0,u.formatTime)(e))),this._wavesurfer.on("timeupdate",(e=>this._currentTime.textContent=(0,u.formatTime)(e)))}static create(e){const t=new h(e);return t.createWaveSurfer(),t.createPCMPlayer(),t.createDownloadButton(),t}}t.default=h}}]);
|