Skip to content

Commit 05d6ba5

Browse files
committed
example for jupyternotebook
asyncio.run() can not be called in jupyter-notebook, jupyter-lab
1 parent 4d22817 commit 05d6ba5

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@ dmypy.json
129129
.pyre/
130130

131131
voice.wav
132-
audio.zip
132+
audio.zip
133+
134+
# vscode
135+
.vscode/*

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ Example
4242
f.write(await audio_query.synthesis(speaker=4))
4343
4444
45-
if __name__ == "__main__":
46-
asyncio.run(main())
45+
if __name__ == "__main__":
46+
## already in asyncio (in a Jupyter notebook, for example)
47+
# await main()
48+
## otherwise
49+
asyncio.run(main())

examples/basic.ipynb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from voicevox import Client\n",
10+
"import asyncio\n",
11+
"\n",
12+
"\n",
13+
"async def main():\n",
14+
" async with Client() as client:\n",
15+
" audio_query = await client.create_audio_query(\"こんにちは!\", speaker=1)\n",
16+
" with open(\"voice.wav\", \"wb\") as f:\n",
17+
" f.write(await audio_query.synthesis(speaker=1))\n",
18+
"\n",
19+
"\n",
20+
"if __name__ == \"__main__\":\n",
21+
" await main()\n"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": []
30+
}
31+
],
32+
"metadata": {
33+
"kernelspec": {
34+
"display_name": "base",
35+
"language": "python",
36+
"name": "python3"
37+
},
38+
"language_info": {
39+
"codemirror_mode": {
40+
"name": "ipython",
41+
"version": 3
42+
},
43+
"file_extension": ".py",
44+
"mimetype": "text/x-python",
45+
"name": "python",
46+
"nbconvert_exporter": "python",
47+
"pygments_lexer": "ipython3",
48+
"version": "3.9.13"
49+
},
50+
"orig_nbformat": 4
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 2
54+
}

0 commit comments

Comments
 (0)