A dataset handler for fine-tuning MOSS TTS models, including text encoding and audio code normalization. Use this to prepare training data for custom text-to-speech models.
# Source: https://github.com/OpenMOSS/MOSS-TTS-Nano | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
from __future__ import annotations
from typing import Any, Dict, Iterable, List, Optional
import torch
from torch.utils.data import Dataset
USER_ROLE_PREFIX = "user\n"
USER_TEMPLATE_REFERENCE_PREFIX = "<user_inst>\n- Reference(s):\n"
USER_TEMPLATE_SUFFIX = "\n</user_inst>"
ASSISTANT_TURN_PREFIX = "\n"
ASSISTANT_ROLE_PREFIX = "assistant\n"
OPTIONAL_MESSAGE_FIELDS = (
("instruction", "Instruction"),
("tokens", "Tokens"),
("quality", "Quality"),
("sound_event", "Sound Event"),
("ambient_sound", "Ambient Sound"),
("language", "Language"),
)
def encode_text(
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key