Download dude_tts/layout.py from penguinfish1688/duplexdataengine: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/penguinfish1688/duplexdataengine/resolve/main/dude_tts/layout.py
- Command line
-
hf download hf://penguinfish1688/duplexdataengine/dude_tts/layout.py
-
curl -L -o layout.py https://huggingface.co/penguinfish1688/duplexdataengine/resolve/main/dude_tts/layout.py
1.31 kB
| """Native conditioning for duplex inference.""" | |
| import torch | |
| def native_prefix(record, config): | |
| """Reproduce the pinned official CustomVoice non-streaming prompt using IDs. | |
| A position can have projected text, codec conditioning, or their sum. | |
| -1 means no embedding contribution; it is not a vocabulary token. | |
| """ | |
| c = config.talker_config | |
| text_ids, codec_ids = [], [] | |
| def add(t=-1, a=-1): | |
| text_ids.append(int(t)) | |
| codec_ids.append([int(a)] + [-1] * (c.num_code_groups - 1)) | |
| for token in record["instruct_ids"]: | |
| add(t=token) | |
| ids = record["text_ids"] | |
| for token in ids[:3]: | |
| add(t=token) | |
| lang = record["language"].lower() | |
| if lang == "auto": | |
| control = [c.codec_nothink_id, c.codec_think_bos_id, c.codec_think_eos_id] | |
| else: | |
| control = [c.codec_think_id, c.codec_think_bos_id, c.codec_language_id[lang], c.codec_think_eos_id] | |
| control += [c.spk_id[record["speaker"].lower()]] | |
| for token in control: | |
| add(config.tts_pad_token_id, token) | |
| add(config.tts_bos_token_id, c.codec_pad_id) | |
| for token in ids[3:-5]: | |
| add(token, c.codec_pad_id) | |
| add(config.tts_eos_token_id, c.codec_pad_id) | |
| add(config.tts_pad_token_id, c.codec_bos_id) | |
| return torch.tensor(text_ids), torch.tensor(codec_ids) | |