Improve: test code
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@ __pycache__/
|
|||||||
venv/
|
venv/
|
||||||
.venv/
|
.venv/
|
||||||
dist/
|
dist/
|
||||||
|
.coverage
|
||||||
.ipynb_checkpoints/
|
.ipynb_checkpoints/
|
||||||
|
|
||||||
/*.yml
|
/*.yml
|
||||||
|
|||||||
@@ -1,39 +1,55 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from scipy.io import wavfile
|
from scipy.io import wavfile
|
||||||
|
|
||||||
from style_bert_vits2.constants import BASE_DIR
|
from style_bert_vits2.constants import BASE_DIR, Languages
|
||||||
from style_bert_vits2.tts_model import TTSModelHolder
|
from style_bert_vits2.tts_model import TTSModelHolder
|
||||||
|
|
||||||
|
|
||||||
def synthesize(device: str = 'cpu'):
|
def synthesize(device: str = 'cpu'):
|
||||||
|
|
||||||
# モデル一覧を取得
|
# 音声合成モデルが配置されていれば、音声合成を実行
|
||||||
model_holder = TTSModelHolder(BASE_DIR / 'model_assets', device)
|
model_holder = TTSModelHolder(BASE_DIR / 'model_assets', device)
|
||||||
|
|
||||||
# モデルが存在する場合、音声合成を実行
|
|
||||||
if len(model_holder.models_info) > 0:
|
if len(model_holder.models_info) > 0:
|
||||||
|
|
||||||
# jvnv-F1-jp モデルを探す
|
# jvnv-F2-jp モデルを探す
|
||||||
for model_info in model_holder.models_info:
|
for model_info in model_holder.models_info:
|
||||||
if model_info['name'] == 'jvnv-F1-jp':
|
if model_info['name'] == 'jvnv-F2-jp':
|
||||||
|
# すべてのスタイルに対して音声合成を実行
|
||||||
|
for style in model_info['styles']:
|
||||||
|
|
||||||
# 音声合成を実行
|
# 音声合成を実行
|
||||||
model = model_holder.get_model(model_info['name'], model_info['files'][0])
|
model = model_holder.get_model(model_info['name'], model_info['files'][0])
|
||||||
model.load()
|
model.load()
|
||||||
sample_rate, audio_data = model.infer("あらゆる現実を、すべて自分のほうへねじ曲げたのだ。")
|
sample_rate, audio_data = model.infer(
|
||||||
|
"あらゆる現実を、すべて自分のほうへねじ曲げたのだ。",
|
||||||
|
# 言語 (JP, EN, ZH / JP-Extra モデルの場合は JP のみ)
|
||||||
|
language = Languages.JP,
|
||||||
|
# 話者 ID (音声合成モデルに複数の話者が含まれる場合のみ必須、単一話者のみの場合は 0)
|
||||||
|
speaker_id = 0,
|
||||||
|
# 感情表現の強さ (0.0 〜 1.0)
|
||||||
|
sdp_ratio = 0.4,
|
||||||
|
# スタイル (Neutral, Happy など)
|
||||||
|
style = style,
|
||||||
|
# スタイルの強さ (0.0 〜 100.0)
|
||||||
|
style_weight = 6.0,
|
||||||
|
)
|
||||||
|
|
||||||
# 音声データを保存
|
# 音声データを保存
|
||||||
with open(BASE_DIR / 'tests/test.wav', mode='wb') as f:
|
(BASE_DIR / 'tests/wavs').mkdir(exist_ok=True, parents=True)
|
||||||
|
wav_file_path = BASE_DIR / f'tests/wavs/{style}.wav'
|
||||||
|
with open(wav_file_path, 'wb') as f:
|
||||||
wavfile.write(f, sample_rate, audio_data)
|
wavfile.write(f, sample_rate, audio_data)
|
||||||
|
|
||||||
|
# 音声データが保存されたことを確認
|
||||||
|
assert wav_file_path.exists()
|
||||||
|
# wav_file_path.unlink()
|
||||||
else:
|
else:
|
||||||
pytest.skip("音声合成モデルが見つかりませんでした。")
|
pytest.skip("音声合成モデルが見つかりませんでした。")
|
||||||
|
|
||||||
|
|
||||||
def test_synthesize_cpu():
|
def test_synthesize_cpu():
|
||||||
synthesize(device='cpu')
|
synthesize(device='cpu')
|
||||||
assert (BASE_DIR / 'tests/test.wav').exists()
|
|
||||||
|
|
||||||
|
|
||||||
def test_synthesize_cuda():
|
def test_synthesize_cuda():
|
||||||
synthesize(device='cuda')
|
synthesize(device='cuda')
|
||||||
assert (BASE_DIR / 'tests/test.wav').exists()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user