Untitled

 avatar
unknown
plain_text
a year ago
1.9 kB
6
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 = "sys";
        if (list.length === 0) { // Check if it's the first character
          list.push({ text: "[", tag: "sys" });
        } else {
          list.push({ text: tmpStr, tag: "narration" });
          tmpStr = "[";
        }
      } else if (char === ']') {
        endTag = "narration";
        tmpStr = tmpStr.slice(0, -1);
        list.push({ text: tmpStr, tag: "sys" });
        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