-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: e2e TTS テストの追加 * fix: lint * fix: Linux-Windows 数値誤差ワークアラウンドの追加 * fix: lint * fix: `snapshot_json` -> `snapshot` * fix: lint
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# serializer version: 1 | ||
# name: test_テキストと話者IDから音声を合成できる | ||
'MD5:9cb1070db2510240ff63a16fd42907c9' | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
TTSのテスト | ||
""" | ||
|
||
import io | ||
from test.utility import hash_long_string, round_floats | ||
|
||
import soundfile as sf | ||
from fastapi.testclient import TestClient | ||
from syrupy.assertion import SnapshotAssertion | ||
|
||
|
||
def test_テキストと話者IDから音声を合成できる( | ||
client: TestClient, snapshot: SnapshotAssertion | ||
) -> None: | ||
# テキストと話者 ID から AudioQuery を生成する | ||
audio_query_res = client.post( | ||
"/audio_query", params={"text": "テストです", "speaker": 0} | ||
) | ||
audio_query = audio_query_res.json() | ||
|
||
# AudioQuery から音声波形を生成する | ||
synthesis_res = client.post("/synthesis", params={"speaker": 0}, json=audio_query) | ||
|
||
# wav ファイルを含む FileResponse から音声波形を抽出する | ||
wav_bytes = io.BytesIO(synthesis_res.read()) | ||
wave = sf.read(wav_bytes)[0].tolist() | ||
|
||
# NOTE: Linux-Windows 数値精度問題に対するワークアラウンド | ||
wave = round_floats(wave, 2) | ||
|
||
# リクエストが成功している | ||
assert synthesis_res.status_code == 200 | ||
# レスポンスが音声ファイルである | ||
assert synthesis_res.headers["content-type"] == "audio/wav" | ||
# 音声波形が commit 間で不変である | ||
wave_str = " ".join(map(lambda point: str(point), wave)) | ||
assert snapshot == hash_long_string(wave_str) |