Untitled

 avatar
unknown
plain_text
a year ago
1.8 kB
7
Indexable
let SpeechRuleJS = {
  name: "旁白/对话",
  id: "ttsrv.multi_voice",
  author: "TTS Server",
  version: 4,
  tags: { narration: "旁白", dialogue: "对话", system: "sys" },

  handleText(text) {
    const list = [];
    let tmpStr = "";
    let endTag = "narration";

    text = text.replace(/-ssi/g, "shi")
               .replace(/Ok Toyeon/g, "Ohk Toyeon")
               .replace(/Lumian/g, "Lu-mi-ahn");

    text.split("").forEach((char, index) => {
      tmpStr += char;

      if (char === '“') {
        endTag = "dialogue";
        list.push({ text: tmpStr, tag: "narration" });
        tmpStr = "";
      } else if (char === '”') {
        endTag = "narration";
        tmpStr = tmpStr.slice(0, -1);
        list.push({ text: tmpStr, tag: "dialogue" });
        tmpStr = "";
      } else if (char === '[') {
        endTag = "system";
        list.push({ text: tmpStr, tag: endTag });
        tmpStr = "";
      } else if (char === ']') {
        endTag = "narration"; // Assuming you want to go back to narration after system
        tmpStr = tmpStr.slice(0, -1);
        list.push({ text: tmpStr, tag: "system" });
        tmpStr = "";
      } else if (index === text.length - 1) {
        list.push({ text: tmpStr, tag: endTag });
      }
    });

    return list;
  },

  splitText(text) {
    let separatorStr = "。?? ?!!;;"

    let list = []
    let tmpStr = ""
    text.split("").forEach((char, index) => {
      tmpStr += char

      if (separatorStr.includes(char)) {
        list.push(tmpStr)
        tmpStr = ""
      } else if (index === text.length - 1) {
        list.push(tmpStr);
      }
    })

    return list.filter(item => item.replace(/[“”]/g, '').trim().length > 0);
  }
};
Editor is loading...
Leave a Comment