| """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) | |
Xet Storage Details
- Size:
- 1.31 kB
- Xet hash:
- b6d0bfb20c087e789ed90dc0a83b7b036da784c805c2f09516a49b1c78e8b0c6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.