MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / parse_script

Function parse_script

src/models/vibevoice/tokenizer_text.cpp:57–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55 const std::string raw_line = end == std::string::npos
56 ? script.substr(start)
57 : script.substr(start, end - start);
58 const std::string line = trim_ascii(raw_line);
59 if (!line.empty()) {
60 std::smatch match;
61 if (std::regex_match(line, match, line_regex)) {
62 VibeVoicePromptLine parsed;
63 parsed.speaker_id = std::stoi(match[1].str());
64 parsed.text = " " + trim_ascii(match[2].str());
65 lines.push_back(std::move(parsed));
66 }
67 }
68 if (end == std::string::npos) {
69 break;
70 }
71 start = end + 1;
72 }
73 if (lines.empty()) {
74 throw std::runtime_error("VibeVoice prompt has no valid Speaker N: lines");
75 }
76 int min_speaker = lines.front().speaker_id;
77 for (const auto & line : lines) {
78 min_speaker = std::min(min_speaker, line.speaker_id);
79 }
80 if (min_speaker > 0) {
81 for (auto & line : lines) {
82 line.speaker_id -= 1;
83 }
84 }
85 return lines;
86}
87
88std::vector<int> collect_speaker_ids(const std::vector<VibeVoicePromptLine> & lines) {
89 std::set<int> ids;
90 for (const auto & line : lines) {
91 ids.insert(line.speaker_id);
92 }
93 return {ids.begin(), ids.end()};
94}
95
96void append_tokens(
97 VibeVoicePromptEncoding & encoding,

Callers 1

encode_promptMethod · 0.85

Calls 6

minFunction · 0.85
strMethod · 0.80
trim_asciiFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected