MCPcopy Create free account
hub / github.com/debpalash/VoiceStudio / parseTaggedScript

Function parseTaggedScript

frontend/src/utils/parseScript.js:93–119  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

91 * joined). Any prose before the first tag is attributed to the Narrator.
92 */
93export function parseTaggedScript(text) {
94 const out = [];
95 const src = String(text || '')
96 .replace(/\r\n/g, '\n')
97 .trim();
98 if (!src) return out;
99
100 let cur = { speaker: 'Narrator', parts: [] };
101 const flush = () => {
102 const t = cur.parts.join('\n').trim();
103 if (t) out.push({ speaker: cur.speaker, text: t });
104 cur = { speaker: cur.speaker, parts: [] };
105 };
106
107 for (const line of src.split('\n')) {
108 const m = line.match(_SPEAKER_TAG);
109 if (m && _isSpeakerTag(m[1])) {
110 flush();
111 cur.speaker = normalizeSpeaker(m[1]);
112 if (m[2] && m[2].trim()) cur.parts.push(m[2].trim());
113 } else if (line.trim()) {
114 cur.parts.push(line.trim());
115 }
116 }
117 flush();
118 return out;
119}
120
121export function parseScript(text) {
122 const out = [];

Callers 2

parseScriptFunction · 0.85

Calls 5

_isSpeakerTagFunction · 0.85
normalizeSpeakerFunction · 0.85
pushMethod · 0.80
flushFunction · 0.70
replaceMethod · 0.45

Tested by

no test coverage detected