Skip to content

Commit

Permalink
python (FFI) example を削除 (VOICEVOX#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
PickledChair authored Feb 23, 2023
1 parent d3d0686 commit 3483887
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 563 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ sudo apt install libgomp1

現在このリポジトリでは次のサンプルが提供されています。実行方法についてはそれぞれのディレクトリ内にある README を参照してください

- [Python](./example/python)
- [Python(pip)](./example/pyo3)
- [Python(pip)](./example/python)
- [C++(UNIX CMake)](./example/cpp/unix)
- [C++(Windows Visual Studio)](./example/cpp/windows)

Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core_python_api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ venv を作ったらその venv 上で Maturin をインストールします。

## サンプル実行

`maturin develop` で editable な状態でインストールした後、[example/pyo3](../../example/pyo3) にてサンプルを実行できます。
`maturin develop` で editable な状態でインストールした後、[example/python](../../example/python) にてサンプルを実行できます。
8 changes: 0 additions & 8 deletions example/pyo3/.gitignore

This file was deleted.

49 changes: 0 additions & 49 deletions example/pyo3/README.md

This file was deleted.

78 changes: 0 additions & 78 deletions example/pyo3/run.py

This file was deleted.

141 changes: 1 addition & 140 deletions example/python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,147 +1,8 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# OpenJTalk-dictionary's dir
open_jtalk_dic_utf_8-*

# shared library
*.so
*.so.*
*.dylib
*.dll
voicevox_core/
60 changes: 43 additions & 17 deletions example/python/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
# Python のサンプルコード
# Python サンプルコード (PyO3 によるバインディング経由)

python から voicevox_core ライブラリを使用するためのサンプルコードです。
voicevox_core ライブラリ の Python バインディングを使った音声合成のサンプルコードです。
`pip install`で導入することができます。

## サンプル実行方法
## 準備

まず、この README があるディレクトリで、[Downloader を使用して voicevox_core をダウンロードします](../../docs/downloads/download.md#default)
次に下記コマンドを実行して python のサンプルを実行します。
TODO

```bash
# サンプルコード実行のための依存モジュールのインストール
pip install -r requirements.txt
python run.py \
--text "これは本当に実行できているんですか" \
--speaker_id 1
- Python インタプリタ ≧3.8 + venv
- voicevox_core_python_api の whl (`pip install`)
- onnxruntime の DLL (/README.md と同様)
- open_jtalk_dic_utf_8-1.11 (/README.md と同様)

# 引数の紹介
# --text 読み上げるテキスト
# --speaker_id 話者ID
# --use_gpu GPUを使う
# --f0_speaker_id 音高の話者ID(デフォルト値はspeaker_id)
# --f0_correct 音高の補正値(デフォルト値は0。+-0.3くらいで結果が大きく変わります)
## 実行

Open JTalk 辞書ディレクトリ、読み上げさせたい文章、出力 wav ファイルのパスの 3 つを指定して run.py を実行します。

```console
python ./run.py -h
usage: run.py [-h] [--mode MODE] open_jtalk_dict_dir text out

positional arguments:
open_jtalk_dict_dir Open JTalkの辞書ディレクトリ
text 読み上げさせたい文章
out 出力wavファイルのパス

optional arguments:
-h, --help show this help message and exit
--mode MODE モード ("AUTO", "CPU", "GPU")
```

```console
# python ./run.py <Open JTalk辞書ディレクトリ> <読み上げさせたい文章> <出力wavファイルのパス>
python ./run.py ./open_jtalk_dic_utf_8-1.11 これはテストです ./audio.wav
[DEBUG] run.py: voicevox_core.METAS=[Meta(name='四国めたん', styles=[Style(name='あまあま', id=0)], speaker_uuid='7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff', version='0.0.1'), Meta(name='ずんだもん', styles=[Style(name='あまあま', id=1)], speaker_uuid='388f246b-8c41-4ac1-8e2d-5d79f3ff56d9', version='0.0.1')]
[DEBUG] run.py: voicevox_core.SUPPORTED_DEVICES=SupportedDevices(cpu=True, cuda=True, dml=False)
[INFO] run.py: Initializing (acceleration_mode=<AccelerationMode.AUTO: 'AUTO'>, open_jtalk_dict_dir=PosixPath('open_jtalk_dic_utf_8-1.11'))
[DEBUG] run.py: core.is_gpu_mode=True
[INFO] run.py: Loading model 0
[DEBUG] run.py: core.is_model_loaded(0)=True
[INFO] run.py: Creating an AudioQuery from 'これはテストです'
[INFO] run.py: Synthesizing with {"accent_phrases": [{"moras": [{"text": "コ", "consonant": "k", "consonant_length": 0.063058704, "vowel": "o", "vowel_length": 0.08937682, "pitch": 5.5699596}, {"text": "レ", "consonant": "r", "consonant_length": 0.047547057, "vowel": "e", "vowel_length": 0.07596417, "pitch": 5.6643105}, {"text": "ワ", "consonant": "w", "consonant_length": 0.053706698, "vowel": "a", "vowel_length": 0.10348523, "pitch": 5.7773285}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "テ", "consonant": "t", "consonant_length": 0.06311223, "vowel": "e", "vowel_length": 0.07596652, "pitch": 5.881741}, {"text": "ス", "consonant": "s", "consonant_length": 0.038565055, "vowel": "U", "vowel_length": 0.050694168, "pitch": 0.0}, {"text": "ト", "consonant": "t", "consonant_length": 0.06685759, "vowel": "o", "vowel_length": 0.0753997, "pitch": 5.737323}, {"text": "デ", "consonant": "d", "consonant_length": 0.058399618, "vowel": "e", "vowel_length": 0.09201351, "pitch": 5.4747167}, {"text": "ス", "consonant": "s", "consonant_length": 0.08852549, "vowel": "U", "vowel_length": 0.1281984, "pitch": 0.0}], "accent": 1, "pause_mora": null, "is_interrogative": false}], "speed_scale": 1.0, "pitch_scale": 0.0, "intonation_scale": 1.0, "volume_scale": 1.0, "pre_phoneme_length": 0.1, "post_phoneme_length": 0.1, "output_sampling_rate": 24000, "output_stereo": false, "kana": "コレワ'/テ'_ストデ_ス"}
[INFO] run.py: Wrote `audio.wav`
[DEBUG] lib.rs: Destructing a VoicevoxCore
```

正常に実行されれば音声合成の結果である wav ファイルが生成されます。
この例の場合、`"これはテストです"`という読み上げの wav ファイルが audio.wav という名前で生成されます。
Loading

0 comments on commit 3483887

Please sign in to comment.