Skip to content

Comments

Implement FastSpeech2 #1744

Open
Yugo0000999921 wants to merge 20 commits intomasterfrom
feature/add-fastspeech2
Open

Implement FastSpeech2 #1744
Yugo0000999921 wants to merge 20 commits intomasterfrom
feature/add-fastspeech2

Conversation

@Yugo0000999921
Copy link

@Yugo0000999921 Yugo0000999921 commented Nov 27, 2025

@Yugo0000999921
Copy link
Author

textなど必要なファイルのコミットを行いました。
推論は単一話者のみ成功しています。

@Yugo0000999921
Copy link
Author

複数話者に対しても推論が成功しました。

@kyakuno
Copy link
Collaborator

kyakuno commented Dec 25, 2025

モデルをアップロードしました。
https://storage.googleapis.com/ailia-models/fastspeech2/aishell3.onnx.prototxt

@kyakuno
Copy link
Collaborator

kyakuno commented Dec 25, 2025

コード的には単機能でシンプルにした方が良いと考えていまして、#1764 をマージ後に、Batch SynthesisのREADME.mdからの削除と該当コードの削除をお願いできればと思います。

fastspeech2をailia SDKで動作するように修正
Copy link
Author

@Yugo0000999921 Yugo0000999921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve changes

@kyakuno
Copy link
Collaborator

kyakuno commented Dec 29, 2025

@Yugo0000999921 下記のコマンドで音声合成した場合、音声の末尾にノイズが入りました。
output.wav

$ python3 fastspeech2.py \
  --text "Hello, I am speaking from a multi-speaker model." \
  --preprocess_config config/LibriTTS/preprocess.yaml \
  --onnx_fs2 libritts.onnx \
  --speaker_id 0

Torchの場合はactual_mel_lenで処理していますが、ONNXをFixed Shapeでエクスポートしてしまっているために、パディングでノイズが発生していると考えています。

    # HiFi-GANのONNXモデルは固定長(3000フレーム)を期待しているため、パディングが必要
    # ただし、元のリポジトリの処理に近づけるため、シンプルなパディングを使用
    HIFI_FIXED_LENGTH = 3000
    hop_length = preprocess_config["preprocessing"]["stft"]["hop_length"]
    actual_mel_len = mel_input.shape[2]

    if actual_mel_len < HIFI_FIXED_LENGTH:
        # 元のリポジトリに近い処理:最後のフレームを繰り返してパディング
        pad_length = HIFI_FIXED_LENGTH - actual_mel_len
        last_frame = mel_input[:, :, -1:]
        padding = np.repeat(last_frame, pad_length, axis=2)
        mel_input = np.concatenate([mel_input, padding], axis=2)
        logger.info(f"Padded mel_input from {actual_mel_len} to {HIFI_FIXED_LENGTH} frames")
    elif actual_mel_len > HIFI_FIXED_LENGTH:
        # 3000フレームを超える場合は切り詰め
        mel_input = mel_input[:, :, :HIFI_FIXED_LENGTH]
        actual_mel_len = HIFI_FIXED_LENGTH
        logger.info(f"Truncated mel_input from {actual_mel_len} to {HIFI_FIXED_LENGTH} frames")

そこで、ONNXをDynamic Shapeでエクスポートして、このノイズを抑制することは可能でしょうか?

また、ONNXで推論した場合の音声ファイルと、Torchで推論した場合の音声ファイルを聞いてみて、概ね一致しているかを確認いただければと思います。

@kyakuno kyakuno changed the title feat(fastspeech2): Add FastSpeech2 + HiFi-GAN TTS sample Implement FastSpeech2 Dec 29, 2025
Yugo0000999921 and others added 7 commits February 23, 2026 17:03
- Remove fixed-length padding, use actual sequence length
- Use ailia.Net(None, onnx_path) without prototxt
- Use onnx.load() to get input/output names
- Add preprocess_text with auto language detection
- Remove HiFi-GAN fixed-length padding
- Add mel spectrogram plot saving

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants