From f92e529217203a7666c23c6b20bcdfc44c163ce9 Mon Sep 17 00:00:00 2001 From: Maiko Date: Thu, 28 Sep 2023 00:11:35 +0900 Subject: [PATCH 1/8] Fix voicebank error check --- .../Classic/VoicebankErrorChecker.cs | 42 +++++++++++++++++++ OpenUtau.Core/Classic/VoicebankLoader.cs | 7 +++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs index 244ec1c98..6f69e418f 100644 --- a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs +++ b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; +using NAudio.Wave; namespace OpenUtau.Classic { public class VoicebankError { @@ -91,6 +93,13 @@ public void Check() { CheckOto(oto, fileDuration); } } + if (FindDuplication(out List duplicates)) { + string message = ""; + duplicates.ForEach(oto => message += "\n" + oto.FileTrace.file + " : " + oto.Alias); + Errors.Add(new VoicebankError() { + message = $"There are duplicate aliases.{message}" + }); + } } bool TryGetFileDuration(string filePath, Oto oto, out double fileDuration) { @@ -108,6 +117,29 @@ bool TryGetFileDuration(string filePath, Oto oto, out double fileDuration) { try { using (var wav = Core.Format.Wave.OpenFile(filePath)) { fileDuration = wav.TotalTime.TotalMilliseconds; + var waveFormat = wav.ToSampleProvider().WaveFormat; + if (waveFormat.SampleRate != 44100) { + Errors.Add(new VoicebankError() { + trace = oto.FileTrace, + soundFile = filePath, + message = $"Sample rate of the sound file is not 44100Hz." + }); + } + if (waveFormat.Channels != 1) { + Errors.Add(new VoicebankError() { + trace = oto.FileTrace, + soundFile = filePath, + message = $"Sound file is not mono channel." + }); + } + /* If sound is not 16bit, it cannot be opened. + if (waveFormat.BitsPerSample != 16) { + Errors.Add(new VoicebankError() { + trace = oto.FileTrace, + soundFile = filePath, + message = $"Bit rate of the sound file is not 16bit." + }); + }*/ } } catch (Exception e) { Errors.Add(new VoicebankError() { @@ -197,5 +229,15 @@ bool CheckOto(Oto oto, double fileDuration) { } return valid; } + + bool FindDuplication(out List duplicates) { + duplicates = voicebank.OtoSets + .SelectMany(set => set.Otos) + .GroupBy(oto => oto.Alias) + .Where(alias => alias.Count() > 1) + .SelectMany(group => group).ToList(); + + return duplicates.Count > 0; + } } } diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index 773759c54..e5c6f7178 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -317,7 +317,7 @@ public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encodi otoSet.Otos.Add(oto); } if (!string.IsNullOrEmpty(oto.Error)) { - Log.Error($"Failed to parse\n{trace}: {oto.Error}"); + Log.Error($"Failed to parse\n{oto.Error}"); } } catch (Exception e) { Log.Error(e, $"Failed to parse\n{trace}"); @@ -386,6 +386,11 @@ static Oto ParseOto(string line, FileTrace trace) { oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}."; return oto; } + string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); + if (!File.Exists(path)) { + oto.Error = $"{trace}\nSound file missing. {path}"; + return oto; + } oto.IsValid = true; return oto; } From 20c1caf010a2090b6b0c583846ba29dead88ed78 Mon Sep 17 00:00:00 2001 From: Maiko Date: Thu, 28 Sep 2023 23:55:01 +0900 Subject: [PATCH 2/8] wav existence check is now passed through when debug build. --- OpenUtau.Core/Classic/VoicebankLoader.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index e5c6f7178..9a7b87198 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -386,11 +386,13 @@ static Oto ParseOto(string line, FileTrace trace) { oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}."; return oto; } +#if DEBUG == false string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); if (!File.Exists(path)) { oto.Error = $"{trace}\nSound file missing. {path}"; return oto; } +#endif oto.IsValid = true; return oto; } From 23c1b8310255c855f7c976d89e31f7e0ec740eeb Mon Sep 17 00:00:00 2001 From: Maiko Date: Fri, 29 Sep 2023 00:36:08 +0900 Subject: [PATCH 3/8] fix tests --- OpenUtau.Core/Classic/ClassicSinger.cs | 10 ++++-- OpenUtau.Core/Classic/VoiceBank.cs | 5 ++- .../Classic/VoicebankErrorChecker.cs | 2 +- OpenUtau.Core/Classic/VoicebankLoader.cs | 32 +++++++++---------- OpenUtau.Test/Classic/VoicebankLoaderTest.cs | 2 +- OpenUtau.Test/Plugins/PhonemizerTestBase.cs | 4 +-- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/OpenUtau.Core/Classic/ClassicSinger.cs b/OpenUtau.Core/Classic/ClassicSinger.cs index 3394cc077..4189faf5e 100644 --- a/OpenUtau.Core/Classic/ClassicSinger.cs +++ b/OpenUtau.Core/Classic/ClassicSinger.cs @@ -47,18 +47,24 @@ public ClassicSinger(Voicebank voicebank) { } public override void EnsureLoaded() { + EnsureLoaded(false); + } + public void EnsureLoaded(bool isTest) { if (Loaded) { return; } - Reload(); + Reload(isTest); } public override void Reload() { + Reload(false); + } + private void Reload(bool isTest) { if (!Found) { return; } try { - voicebank.Reload(); + voicebank.Reload(isTest); Load(); loaded = true; if (otoWatcher == null) { diff --git a/OpenUtau.Core/Classic/VoiceBank.cs b/OpenUtau.Core/Classic/VoiceBank.cs index c39b78081..87bda640b 100644 --- a/OpenUtau.Core/Classic/VoiceBank.cs +++ b/OpenUtau.Core/Classic/VoiceBank.cs @@ -25,6 +25,9 @@ public class Voicebank { public string Id; public void Reload() { + Reload(false); + } + public void Reload(bool isTest) { Name = null; Image = null; Portrait = null; @@ -40,7 +43,7 @@ public void Reload() { OtoSets.Clear(); Subbanks.Clear(); Id = null; - VoicebankLoader.LoadVoicebank(this); + VoicebankLoader.LoadVoicebank(this, isTest); } public override string ToString() { diff --git a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs index 6f69e418f..572688023 100644 --- a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs +++ b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs @@ -60,7 +60,7 @@ public void Check() { }); } try { - VoicebankLoader.LoadVoicebank(voicebank); + VoicebankLoader.LoadVoicebank(voicebank, false); } catch (Exception e) { Errors.Add(new VoicebankError() { message = "Failed to load voicebank", diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index 9a7b87198..b83b6ac88 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -57,15 +57,15 @@ public IEnumerable SearchAll() { return result; } - public static void LoadVoicebank(Voicebank voicebank) { + public static void LoadVoicebank(Voicebank voicebank, bool isTest) { LoadInfo(voicebank, voicebank.File, voicebank.BasePath); - LoadOtoSets(voicebank, Path.GetDirectoryName(voicebank.File)); + LoadOtoSets(voicebank, Path.GetDirectoryName(voicebank.File), isTest); } - public static void LoadOtoSets(Voicebank voicebank, string dirPath) { + public static void LoadOtoSets(Voicebank voicebank, string dirPath, bool isTest) { var otoFile = Path.Combine(dirPath, kOtoIni); if (File.Exists(otoFile)) { - var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding); + var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding, isTest); var voicebankDir = Path.GetDirectoryName(voicebank.File); otoSet.Name = Path.GetRelativePath(voicebankDir, dirPath); if (otoSet.Name == ".") { @@ -75,7 +75,7 @@ public static void LoadOtoSets(Voicebank voicebank, string dirPath) { } var dirs = Directory.GetDirectories(dirPath); foreach (var dir in dirs) { - LoadOtoSets(voicebank, dir); + LoadOtoSets(voicebank, dir, isTest); } } @@ -288,10 +288,10 @@ public static Dictionary, SortedSet> ParsePrefixMap(S } } - public static OtoSet ParseOtoSet(string filePath, Encoding encoding) { + public static OtoSet ParseOtoSet(string filePath, Encoding encoding, bool isTest) { try { using (var stream = File.OpenRead(filePath)) { - var otoSet = ParseOtoSet(stream, filePath, encoding); + var otoSet = ParseOtoSet(stream, filePath, encoding, isTest); AddAliasForMissingFiles(otoSet); return otoSet; } @@ -301,7 +301,7 @@ public static OtoSet ParseOtoSet(string filePath, Encoding encoding) { return null; } - public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding) { + public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding, bool isTest) { OtoSet otoSet; using (var reader = new StreamReader(stream, encoding)) { var trace = new FileTrace { file = filePath, lineNumber = 0 }; @@ -312,7 +312,7 @@ public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encodi var line = reader.ReadLine().Trim(); trace.line = line; try { - Oto oto = ParseOto(line, trace); + Oto oto = ParseOto(line, trace, isTest); if (oto != null) { otoSet.Otos.Add(oto); } @@ -346,7 +346,7 @@ static void AddAliasForMissingFiles(OtoSet otoSet) { } } - static Oto ParseOto(string line, FileTrace trace) { + static Oto ParseOto(string line, FileTrace trace, bool isTest) { const string format = "=,,,,,"; var oto = new Oto { FileTrace = new FileTrace(trace), @@ -386,13 +386,13 @@ static Oto ParseOto(string line, FileTrace trace) { oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}."; return oto; } -#if DEBUG == false - string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); - if (!File.Exists(path)) { - oto.Error = $"{trace}\nSound file missing. {path}"; - return oto; + if (!isTest) { + string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); + if (!File.Exists(path)) { + oto.Error = $"{trace}\nSound file missing. {path}"; + return oto; + } } -#endif oto.IsValid = true; return oto; } diff --git a/OpenUtau.Test/Classic/VoicebankLoaderTest.cs b/OpenUtau.Test/Classic/VoicebankLoaderTest.cs index f3f2917cd..9e8d17f9c 100644 --- a/OpenUtau.Test/Classic/VoicebankLoaderTest.cs +++ b/OpenUtau.Test/Classic/VoicebankLoaderTest.cs @@ -39,7 +39,7 @@ public void OtoSetRoundTrip() { ".Replace("\r\n", "\n"); using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(text))) { - var otoSet = VoicebankLoader.ParseOtoSet(stream, "oto.ini", Encoding.ASCII); + var otoSet = VoicebankLoader.ParseOtoSet(stream, "oto.ini", Encoding.ASCII, true); using (MemoryStream stream2 = new MemoryStream()) { VoicebankLoader.WriteOtoSet(otoSet, stream2, Encoding.ASCII); string actual = Encoding.ASCII.GetString(stream2.ToArray()); diff --git a/OpenUtau.Test/Plugins/PhonemizerTestBase.cs b/OpenUtau.Test/Plugins/PhonemizerTestBase.cs index e2902b913..55ae23f4b 100644 --- a/OpenUtau.Test/Plugins/PhonemizerTestBase.cs +++ b/OpenUtau.Test/Plugins/PhonemizerTestBase.cs @@ -26,9 +26,9 @@ public void RunPhonemizeTest(string singerName, string[] lyrics, string[] alts, var file = Path.Join(basePath, singerName, "character.txt"); var voicebank = new Voicebank() { File = file, BasePath = dir }; - VoicebankLoader.LoadVoicebank(voicebank); + VoicebankLoader.LoadVoicebank(voicebank, true); var singer = new ClassicSinger(voicebank); - singer.EnsureLoaded(); + singer.EnsureLoaded(true); var timeAxis = new Core.TimeAxis(); timeAxis.BuildSegments(new Core.Ustx.UProject()); From 3cec526ec1d7a64cc660e816c1ca86dd19c9e552 Mon Sep 17 00:00:00 2001 From: Maiko Date: Fri, 29 Sep 2023 00:49:59 +0900 Subject: [PATCH 4/8] Revert "fix tests" This reverts commit 23c1b8310255c855f7c976d89e31f7e0ec740eeb. --- OpenUtau.Core/Classic/ClassicSinger.cs | 10 ++---- OpenUtau.Core/Classic/VoiceBank.cs | 5 +-- .../Classic/VoicebankErrorChecker.cs | 2 +- OpenUtau.Core/Classic/VoicebankLoader.cs | 32 +++++++++---------- OpenUtau.Test/Classic/VoicebankLoaderTest.cs | 2 +- OpenUtau.Test/Plugins/PhonemizerTestBase.cs | 4 +-- 6 files changed, 23 insertions(+), 32 deletions(-) diff --git a/OpenUtau.Core/Classic/ClassicSinger.cs b/OpenUtau.Core/Classic/ClassicSinger.cs index 4189faf5e..3394cc077 100644 --- a/OpenUtau.Core/Classic/ClassicSinger.cs +++ b/OpenUtau.Core/Classic/ClassicSinger.cs @@ -47,24 +47,18 @@ public ClassicSinger(Voicebank voicebank) { } public override void EnsureLoaded() { - EnsureLoaded(false); - } - public void EnsureLoaded(bool isTest) { if (Loaded) { return; } - Reload(isTest); + Reload(); } public override void Reload() { - Reload(false); - } - private void Reload(bool isTest) { if (!Found) { return; } try { - voicebank.Reload(isTest); + voicebank.Reload(); Load(); loaded = true; if (otoWatcher == null) { diff --git a/OpenUtau.Core/Classic/VoiceBank.cs b/OpenUtau.Core/Classic/VoiceBank.cs index 87bda640b..c39b78081 100644 --- a/OpenUtau.Core/Classic/VoiceBank.cs +++ b/OpenUtau.Core/Classic/VoiceBank.cs @@ -25,9 +25,6 @@ public class Voicebank { public string Id; public void Reload() { - Reload(false); - } - public void Reload(bool isTest) { Name = null; Image = null; Portrait = null; @@ -43,7 +40,7 @@ public void Reload(bool isTest) { OtoSets.Clear(); Subbanks.Clear(); Id = null; - VoicebankLoader.LoadVoicebank(this, isTest); + VoicebankLoader.LoadVoicebank(this); } public override string ToString() { diff --git a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs index 572688023..6f69e418f 100644 --- a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs +++ b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs @@ -60,7 +60,7 @@ public void Check() { }); } try { - VoicebankLoader.LoadVoicebank(voicebank, false); + VoicebankLoader.LoadVoicebank(voicebank); } catch (Exception e) { Errors.Add(new VoicebankError() { message = "Failed to load voicebank", diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index b83b6ac88..9a7b87198 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -57,15 +57,15 @@ public IEnumerable SearchAll() { return result; } - public static void LoadVoicebank(Voicebank voicebank, bool isTest) { + public static void LoadVoicebank(Voicebank voicebank) { LoadInfo(voicebank, voicebank.File, voicebank.BasePath); - LoadOtoSets(voicebank, Path.GetDirectoryName(voicebank.File), isTest); + LoadOtoSets(voicebank, Path.GetDirectoryName(voicebank.File)); } - public static void LoadOtoSets(Voicebank voicebank, string dirPath, bool isTest) { + public static void LoadOtoSets(Voicebank voicebank, string dirPath) { var otoFile = Path.Combine(dirPath, kOtoIni); if (File.Exists(otoFile)) { - var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding, isTest); + var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding); var voicebankDir = Path.GetDirectoryName(voicebank.File); otoSet.Name = Path.GetRelativePath(voicebankDir, dirPath); if (otoSet.Name == ".") { @@ -75,7 +75,7 @@ public static void LoadOtoSets(Voicebank voicebank, string dirPath, bool isTest) } var dirs = Directory.GetDirectories(dirPath); foreach (var dir in dirs) { - LoadOtoSets(voicebank, dir, isTest); + LoadOtoSets(voicebank, dir); } } @@ -288,10 +288,10 @@ public static Dictionary, SortedSet> ParsePrefixMap(S } } - public static OtoSet ParseOtoSet(string filePath, Encoding encoding, bool isTest) { + public static OtoSet ParseOtoSet(string filePath, Encoding encoding) { try { using (var stream = File.OpenRead(filePath)) { - var otoSet = ParseOtoSet(stream, filePath, encoding, isTest); + var otoSet = ParseOtoSet(stream, filePath, encoding); AddAliasForMissingFiles(otoSet); return otoSet; } @@ -301,7 +301,7 @@ public static OtoSet ParseOtoSet(string filePath, Encoding encoding, bool isTest return null; } - public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding, bool isTest) { + public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding) { OtoSet otoSet; using (var reader = new StreamReader(stream, encoding)) { var trace = new FileTrace { file = filePath, lineNumber = 0 }; @@ -312,7 +312,7 @@ public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encodi var line = reader.ReadLine().Trim(); trace.line = line; try { - Oto oto = ParseOto(line, trace, isTest); + Oto oto = ParseOto(line, trace); if (oto != null) { otoSet.Otos.Add(oto); } @@ -346,7 +346,7 @@ static void AddAliasForMissingFiles(OtoSet otoSet) { } } - static Oto ParseOto(string line, FileTrace trace, bool isTest) { + static Oto ParseOto(string line, FileTrace trace) { const string format = "=,,,,,"; var oto = new Oto { FileTrace = new FileTrace(trace), @@ -386,13 +386,13 @@ static Oto ParseOto(string line, FileTrace trace, bool isTest) { oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}."; return oto; } - if (!isTest) { - string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); - if (!File.Exists(path)) { - oto.Error = $"{trace}\nSound file missing. {path}"; - return oto; - } +#if DEBUG == false + string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); + if (!File.Exists(path)) { + oto.Error = $"{trace}\nSound file missing. {path}"; + return oto; } +#endif oto.IsValid = true; return oto; } diff --git a/OpenUtau.Test/Classic/VoicebankLoaderTest.cs b/OpenUtau.Test/Classic/VoicebankLoaderTest.cs index 9e8d17f9c..f3f2917cd 100644 --- a/OpenUtau.Test/Classic/VoicebankLoaderTest.cs +++ b/OpenUtau.Test/Classic/VoicebankLoaderTest.cs @@ -39,7 +39,7 @@ public void OtoSetRoundTrip() { ".Replace("\r\n", "\n"); using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(text))) { - var otoSet = VoicebankLoader.ParseOtoSet(stream, "oto.ini", Encoding.ASCII, true); + var otoSet = VoicebankLoader.ParseOtoSet(stream, "oto.ini", Encoding.ASCII); using (MemoryStream stream2 = new MemoryStream()) { VoicebankLoader.WriteOtoSet(otoSet, stream2, Encoding.ASCII); string actual = Encoding.ASCII.GetString(stream2.ToArray()); diff --git a/OpenUtau.Test/Plugins/PhonemizerTestBase.cs b/OpenUtau.Test/Plugins/PhonemizerTestBase.cs index 55ae23f4b..e2902b913 100644 --- a/OpenUtau.Test/Plugins/PhonemizerTestBase.cs +++ b/OpenUtau.Test/Plugins/PhonemizerTestBase.cs @@ -26,9 +26,9 @@ public void RunPhonemizeTest(string singerName, string[] lyrics, string[] alts, var file = Path.Join(basePath, singerName, "character.txt"); var voicebank = new Voicebank() { File = file, BasePath = dir }; - VoicebankLoader.LoadVoicebank(voicebank, true); + VoicebankLoader.LoadVoicebank(voicebank); var singer = new ClassicSinger(voicebank); - singer.EnsureLoaded(true); + singer.EnsureLoaded(); var timeAxis = new Core.TimeAxis(); timeAxis.BuildSegments(new Core.Ustx.UProject()); From ecfe5763814d855443c0393e1a1714bbc3dd3ed3 Mon Sep 17 00:00:00 2001 From: Maiko Date: Fri, 29 Sep 2023 00:50:05 +0900 Subject: [PATCH 5/8] Revert "wav existence check is now passed through when debug build." This reverts commit 20c1caf010a2090b6b0c583846ba29dead88ed78. --- OpenUtau.Core/Classic/VoicebankLoader.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index 9a7b87198..e5c6f7178 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -386,13 +386,11 @@ static Oto ParseOto(string line, FileTrace trace) { oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}."; return oto; } -#if DEBUG == false string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); if (!File.Exists(path)) { oto.Error = $"{trace}\nSound file missing. {path}"; return oto; } -#endif oto.IsValid = true; return oto; } From 56c5f5bf032206db0360efcc6860a905d778ca93 Mon Sep 17 00:00:00 2001 From: Maiko Date: Fri, 29 Sep 2023 00:55:10 +0900 Subject: [PATCH 6/8] fix tests more smarter --- OpenUtau.Core/Classic/VoicebankLoader.cs | 12 ++++++++---- OpenUtau.Test/Classic/VoicebankLoaderTest.cs | 1 + OpenUtau.Test/Plugins/PhonemizerTestBase.cs | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index e5c6f7178..082a25676 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -33,6 +33,8 @@ public class VoicebankLoader { readonly string basePath; + public static bool IsTest = false; + public VoicebankLoader(string basePath) { this.basePath = basePath; } @@ -386,10 +388,12 @@ static Oto ParseOto(string line, FileTrace trace) { oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}."; return oto; } - string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); - if (!File.Exists(path)) { - oto.Error = $"{trace}\nSound file missing. {path}"; - return oto; + if (!IsTest) { + string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); + if (!File.Exists(path)) { + oto.Error = $"{trace}\nSound file missing. {path}"; + return oto; + } } oto.IsValid = true; return oto; diff --git a/OpenUtau.Test/Classic/VoicebankLoaderTest.cs b/OpenUtau.Test/Classic/VoicebankLoaderTest.cs index f3f2917cd..a4db6548c 100644 --- a/OpenUtau.Test/Classic/VoicebankLoaderTest.cs +++ b/OpenUtau.Test/Classic/VoicebankLoaderTest.cs @@ -39,6 +39,7 @@ public void OtoSetRoundTrip() { ".Replace("\r\n", "\n"); using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(text))) { + VoicebankLoader.IsTest = true; var otoSet = VoicebankLoader.ParseOtoSet(stream, "oto.ini", Encoding.ASCII); using (MemoryStream stream2 = new MemoryStream()) { VoicebankLoader.WriteOtoSet(otoSet, stream2, Encoding.ASCII); diff --git a/OpenUtau.Test/Plugins/PhonemizerTestBase.cs b/OpenUtau.Test/Plugins/PhonemizerTestBase.cs index e2902b913..dae06360d 100644 --- a/OpenUtau.Test/Plugins/PhonemizerTestBase.cs +++ b/OpenUtau.Test/Plugins/PhonemizerTestBase.cs @@ -25,6 +25,7 @@ public void RunPhonemizeTest(string singerName, string[] lyrics, string[] alts, var basePath = Path.Join(dir, "Files"); var file = Path.Join(basePath, singerName, "character.txt"); + VoicebankLoader.IsTest = true; var voicebank = new Voicebank() { File = file, BasePath = dir }; VoicebankLoader.LoadVoicebank(voicebank); var singer = new ClassicSinger(voicebank); From fe6fb3dfa04d5a5c961b980cab71ee69a2f065b7 Mon Sep 17 00:00:00 2001 From: Maiko Date: Sat, 14 Oct 2023 14:17:56 +0900 Subject: [PATCH 7/8] Fix wav checker --- OpenUtau.Core/Classic/VoicebankLoader.cs | 27 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index 082a25676..0ad892bb0 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -294,6 +294,9 @@ public static OtoSet ParseOtoSet(string filePath, Encoding encoding) { try { using (var stream = File.OpenRead(filePath)) { var otoSet = ParseOtoSet(stream, filePath, encoding); + if (!IsTest) { + CheckWavExist(otoSet); + } AddAliasForMissingFiles(otoSet); return otoSet; } @@ -341,6 +344,7 @@ static void AddAliasForMissingFiles(OtoSet otoSet) { var oto = new Oto { Alias = Path.GetFileNameWithoutExtension(file), Wav = file, + FileTrace = new FileTrace { file = wav, lineNumber = 0 } }; oto.Phonetic = oto.Alias; otoSet.Otos.Add(oto); @@ -348,6 +352,22 @@ static void AddAliasForMissingFiles(OtoSet otoSet) { } } + static void CheckWavExist(OtoSet otoSet) { + var wavGroups = otoSet.Otos.GroupBy(oto => oto.Wav); + foreach(var group in wavGroups) { + string path = Path.Combine(Path.GetDirectoryName(otoSet.File), group.Key); + if (!File.Exists(path)) { + Log.Error($"Sound file missing. {path}"); + foreach (Oto oto in group) { + if(string.IsNullOrEmpty(oto.Error)) { + oto.Error = $"Sound file missing. {path}"; + } + oto.IsValid = false; + } + } + } + } + static Oto ParseOto(string line, FileTrace trace) { const string format = "=,,,,,"; var oto = new Oto { @@ -388,13 +408,6 @@ static Oto ParseOto(string line, FileTrace trace) { oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}."; return oto; } - if (!IsTest) { - string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav); - if (!File.Exists(path)) { - oto.Error = $"{trace}\nSound file missing. {path}"; - return oto; - } - } oto.IsValid = true; return oto; } From 13287f512d9c0167b6f0a5382ed0597fc73adc71 Mon Sep 17 00:00:00 2001 From: Maiko Date: Sat, 18 Nov 2023 21:37:54 +0900 Subject: [PATCH 8/8] Isolate minor errors in error reports as "information" --- OpenUtau.Core/Classic/VoicebankErrorChecker.cs | 5 +++-- OpenUtau/ViewModels/SingersViewModel.cs | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs index 6f69e418f..9b003057b 100644 --- a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs +++ b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs @@ -32,6 +32,7 @@ public override string ToString() { public class VoicebankErrorChecker { public List Errors = new List(); + public List Infos = new List(); readonly string path; readonly Voicebank voicebank; @@ -55,7 +56,7 @@ public void Check() { } string charYaml = Path.Combine(path, VoicebankLoader.kCharYaml); if (!File.Exists(charYaml)) { - Errors.Add(new VoicebankError() { + Infos.Add(new VoicebankError() { message = "character.yaml not found", }); } @@ -126,7 +127,7 @@ bool TryGetFileDuration(string filePath, Oto oto, out double fileDuration) { }); } if (waveFormat.Channels != 1) { - Errors.Add(new VoicebankError() { + Infos.Add(new VoicebankError() { trace = oto.FileTrace, soundFile = filePath, message = $"Sound file is not mono channel." diff --git a/OpenUtau/ViewModels/SingersViewModel.cs b/OpenUtau/ViewModels/SingersViewModel.cs index 6911ec141..529bdcb5f 100644 --- a/OpenUtau/ViewModels/SingersViewModel.cs +++ b/OpenUtau/ViewModels/SingersViewModel.cs @@ -179,10 +179,18 @@ public void ErrorReport() { string outFile = Path.Combine(Singer.Location, "errors.txt"); using (var stream = File.Open(outFile, FileMode.Create)) { using (var writer = new StreamWriter(stream)) { + writer.WriteLine($"------ Informations ------"); + writer.WriteLine(); + for (var i = 0; i < checker.Infos.Count; i++) { + writer.WriteLine($"--- Info {i + 1} ---"); + writer.WriteLine(checker.Infos[i].ToString()); + } + writer.WriteLine(); + writer.WriteLine($"------ Errors ------"); writer.WriteLine($"Total errors: {checker.Errors.Count}"); writer.WriteLine(); for (var i = 0; i < checker.Errors.Count; i++) { - writer.WriteLine($"------ Error {i + 1} ------"); + writer.WriteLine($"--- Error {i + 1} ---"); writer.WriteLine(checker.Errors[i].ToString()); } }