| 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 | |
| 88 | std::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 | |
| 96 | void append_tokens( |
| 97 | VibeVoicePromptEncoding & encoding, |
no test coverage detected