From acf2e352b4ae347cede6fbbeed3dba85bd4eda42 Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:09:40 +0900 Subject: [PATCH] =?UTF-8?q?#25=20=E4=BA=8C=E9=87=8D=E3=83=AB=E3=83=BC?= =?UTF-8?q?=E3=83=97=E3=82=92=E9=81=BF=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/ClaudeAnalyzerService.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/KoeBook.Core/Services/ClaudeAnalyzerService.cs b/KoeBook.Core/Services/ClaudeAnalyzerService.cs index 3595c02..040b519 100644 --- a/KoeBook.Core/Services/ClaudeAnalyzerService.cs +++ b/KoeBook.Core/Services/ClaudeAnalyzerService.cs @@ -165,21 +165,22 @@ private static (Character[], Dictionary) ExtractCharacterList(st }).ToArray(); var characterId2Name = characters.Select(x => (x.Id, x.Name)).ToDictionary(); - var voiceIdLines = lines.SkipWhile(l => !l.StartsWith("[REVISE VOICE ID]")) - .Where((x, i) => x.StartsWith(i.ToString())); //[REVISE VOICE ID]の分ズレる - - if (voiceIdLines.Count() != scriptLines.Count) + var voiceIdLinesCount = lines.SkipWhile(l => !l.StartsWith("[REVISE VOICE ID]")) + .Where((x, i) => x.StartsWith(i.ToString())) //[REVISE VOICE ID]の分ズレる + .Zip(scriptLines) + .Select(zippedLine => + { + var voiceIdLine = zippedLine.First.AsSpan(); + voiceIdLine = voiceIdLine[(voiceIdLine.IndexOf(' ') + 2)..];//cまで無視 + voiceIdLine = voiceIdLine[..voiceIdLine.IndexOf(' ')];// 二人以上話す時には先頭のものを使う + if (characterId2Name.TryGetValue(voiceIdLine.ToString(), out var characterName)) + { + zippedLine.Second.Character = characterName; + } + return 0; + }).Count(); + if (voiceIdLinesCount != scriptLines.Count) throw new EbookException(ExceptionType.ClaudeTalkerAndStyleSettingFailed); - foreach (var (voiceIdLine, scriptLine) in voiceIdLines.Zip(scriptLines)) - { - var line = voiceIdLine.AsSpan(); - line = line[(line.IndexOf(' ') + 2)..];//cまで無視 - line = line[..line.IndexOf(' ')];// 二人以上話す時には先頭のものを使う - if (characterId2Name.TryGetValue(line.ToString(), out var characterName)) - { - scriptLine.Character = characterName; - } - } return (characters, characterId2Name); }