Skip to content

Commit b103a29

Browse files
nanae772Hiroshiba
andauthored
test: cancellable_synthesis, connect_waves API のスナップショットテスト (#1538)
Co-authored-by: Hiroshiba <[email protected]>
1 parent 92dc13a commit b103a29

File tree

7 files changed

+105
-5
lines changed

7 files changed

+105
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# serializer version: 1
2+
# name: test_post_cancellable_synthesis_200
3+
'MD5:f7d42ce5787856549abc3d2d7561c06f'
4+
# ---
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# serializer version: 1
2+
# name: test_post_connect_waves_200
3+
'MD5:09eeac5fac75ce47f5002c48fef3044d'
4+
# ---
82 KB
Binary file not shown.
81 KB
Binary file not shown.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
/cancellable_synthesis API のテスト
3+
"""
4+
5+
from test.e2e.single_api.utils import gen_mora
6+
from test.utility import hash_wave_floats_from_wav_bytes
7+
8+
import pytest
9+
from fastapi.testclient import TestClient
10+
from syrupy.assertion import SnapshotAssertion
11+
12+
from voicevox_engine.app.application import generate_app
13+
from voicevox_engine.cancellable_engine import CancellableEngine
14+
15+
16+
@pytest.fixture()
17+
def cancellable_client(app_params: dict) -> TestClient:
18+
app_params["cancellable_engine"] = CancellableEngine(
19+
init_processes=1,
20+
use_gpu=False,
21+
enable_mock=True,
22+
)
23+
cancellable_app = generate_app(**app_params)
24+
return TestClient(cancellable_app)
25+
26+
27+
def test_post_cancellable_synthesis_200(
28+
cancellable_client: TestClient, snapshot: SnapshotAssertion
29+
) -> None:
30+
query = {
31+
"accent_phrases": [
32+
{
33+
"moras": [
34+
gen_mora("テ", "t", 2.3, "e", 0.8, 3.3),
35+
gen_mora("ス", "s", 2.1, "U", 0.3, 0.0),
36+
gen_mora("ト", "t", 2.3, "o", 1.8, 4.1),
37+
],
38+
"accent": 1,
39+
"pause_mora": None,
40+
"is_interrogative": False,
41+
}
42+
],
43+
"speedScale": 1.0,
44+
"pitchScale": 1.0,
45+
"intonationScale": 1.0,
46+
"volumeScale": 1.0,
47+
"prePhonemeLength": 0.1,
48+
"postPhonemeLength": 0.1,
49+
"pauseLength": None,
50+
"pauseLengthScale": 1.0,
51+
"outputSamplingRate": 24000,
52+
"outputStereo": False,
53+
"kana": "テ'_スト",
54+
}
55+
response = cancellable_client.post(
56+
"/cancellable_synthesis", params={"speaker": 0}, json=query
57+
)
58+
assert response.status_code == 200
59+
60+
# 音声波形が一致する
61+
assert response.headers["content-type"] == "audio/wav"
62+
assert snapshot == hash_wave_floats_from_wav_bytes(response.read())
63+
64+
65+
# TODO: キャンセルするテストを追加する
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
/connect_waves API のテスト
3+
"""
4+
5+
import base64
6+
from pathlib import Path
7+
from test.utility import hash_wave_floats_from_wav_bytes
8+
9+
from fastapi.testclient import TestClient
10+
from syrupy.assertion import SnapshotAssertion
11+
12+
13+
def test_post_connect_waves_200(
14+
client: TestClient, snapshot: SnapshotAssertion
15+
) -> None:
16+
test_audio_dir = Path(__file__).parent / "test_audio"
17+
wavs = [
18+
base64.b64encode((test_audio_dir / "sample1.wav").read_bytes()).decode(),
19+
base64.b64encode((test_audio_dir / "sample2.wav").read_bytes()).decode(),
20+
]
21+
22+
response = client.post("/connect_waves", json=wavs)
23+
assert response.status_code == 200
24+
25+
# 音声波形が一致する
26+
assert response.headers["content-type"] == "audio/wav"
27+
assert snapshot == hash_wave_floats_from_wav_bytes(response.read())

voicevox_engine/cancellable_engine.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def __init__(
5252
self,
5353
init_processes: int,
5454
use_gpu: bool,
55-
voicelib_dirs: list[Path] | None,
56-
voicevox_dir: Path | None,
57-
runtime_dirs: list[Path] | None,
58-
cpu_num_threads: int | None,
59-
enable_mock: bool,
55+
voicelib_dirs: list[Path] | None = None,
56+
voicevox_dir: Path | None = None,
57+
runtime_dirs: list[Path] | None = None,
58+
cpu_num_threads: int | None = None,
59+
enable_mock: bool = True,
6060
) -> None:
6161
"""
6262
変数の初期化を行う

0 commit comments

Comments
 (0)