Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整理: e2e TTS テスト #1064

Merged
merged 7 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/e2e/__snapshots__/test_tts.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_テキストと話者IDから音声を合成できる
'MD5:9cb1070db2510240ff63a16fd42907c9'
# ---
38 changes: 38 additions & 0 deletions test/e2e/test_tts.py
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)
Loading