0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【個人メモ】Irodori-TTSをJupyterから使う

0
Last updated at Posted at 2026-06-12

Irodori-TTSはただ文を音読するだけの従来のTTSと比べ、表情豊かに朗読してくれることが特徴である。

しかし、想定通りに朗読してくれるかどうかは様々生成してみないと分からず、試行錯誤の効率化が活用のための鍵となる。ここではIrodori-TTSをJupyterノートブックから使用するためのメモを残す。

環境準備

本家にはGradioアプリのホストなど様々な機能が入っている上に、比較的古いPythonバージョン(3.10)が指定されている。

Gradioなどを使わずに音声生成をするのなら、構成をある程度削減できる。また、より新しいPythonバージョンでも動く。具体的には、Pythonバージョン3.13のもと、次のような構成でも動作する。

pyproject.tomlのdependencies部分
dependencies = [
    "dacvae",
    "llvmlite>=0.40.0",
    "numba>=0.57.0",
    "pyyaml>=6.0",
    "safetensors>=0.7.0",
    "soundfile>=0.12.0",
    "silentcipher @ git+https://github.com/SesameAILabs/silentcipher.git@d46d7d0893a583d8968ab3a6626e2289faec9152",
    "torch>=2.10.0",
    "torchaudio>=2.10.0",
    "torchcodec>=0.10.0",
    "transformers<5",
    "tqdm>=4.67.3",
    "wandb>=0.17.0",
]

以下より記載することは、本家リポジトリのソースコードを読むことで明らかになったものである。

Jupyterノートブックで素早く試行錯誤する

本家リポジトリにはGradioアプリとコマンドラインツールが提供されているが、Jupyterノートブックを用いれば、より効率的に試行錯誤することができる。

Import
import torch
from irodori_tts.inference_runtime import (
    InferenceRuntime,
    RuntimeKey,
    SamplingRequest,
    save_wav,
)
from IPython.display import Audio
from pathlib import Path
import re
Constants
DTYPE = torch.float32
DTYPE_NAME = "fp32"
DEVICE_NAME = "cuda"
DEVICE = torch.device(DEVICE_NAME)
Launch Runtime
runtime = InferenceRuntime.from_key(
    RuntimeKey(
        checkpoint=r"path-to/Aratako__Irodori-TTS-500M-v3.safetensors",
        model_device=DEVICE_NAME,
        codec_repo=r"path-to/Aratako__Semantic-DACVAE-Japanese-32dim.pth",
        model_precision=DTYPE_NAME,
        codec_device=DEVICE_NAME,
        codec_precision=DTYPE_NAME,
        codec_deterministic_decode=False,
        codec_deterministic_encode=False,
        compile_model=False,
        compile_dynamic=False,
    )
)
Generate
sr = SamplingRequest(
    # プロンプト
    text="😊こんにちは",
    
    # 参照音声
    ref_wav="path-to-reference.wav", # 参照音声。
    # ref_latent="path-to-latent.pt", # 参照音声の潜在変数。参照音声よりも数秒早く動作する。
    ref_embed=None,
    # no_ref=True, # 参照音声を指定しなかった時に指定。
    ref_normalize_db=-16.0,
    ref_ensure_max=True,
    
    # バッチ
    num_candidates=1,
    decode_mode="batch",
    
    # 尺
    # seconds=5, # 希望秒数
    max_seconds=60.0, # 最大秒数
    
    # 生成過程
    num_steps=30, # ステップ数
    cfg_scale_text=3.0, # 読み上げテキストの強さ
    seed=0, # シード
)
result = runtime.synthesize(sr)
Audio(data=result.audio, rate=result.sample_rate) # 最後にこう書くことで生成された音のプレーヤーが現れる

指定する必要のあるファイルは次からダウンロードできる:

参照音声の潜在変数を作る

SamplingRequest.ref_latentに指定するファイルを作る。

MakeLatent
from irodori_tts.inference_runtime import _load_audio as load_audio
wav, sr = load_audio("path-to-reference.wav")
ref_latent = runtime.codec.encode_waveform(
    wav.unsqueeze(0), sample_rate=int(sr), normalize_db=-16.0, ensure_max=True
)
torch.save(ref_latent, "path-to-latent.pt")

私が見る限り、これと等価な処理が本家リポジトリ内でも動いていると思うのですが、本家リポジトリと私のコードとで生成物を聞き比べると、少し違いがありました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?