From 2b673e7c6c6d5e54d26f561b32a25f2190367c0f Mon Sep 17 00:00:00 2001 From: oxygen-dioxide <54425948+oxygen-dioxide@users.noreply.github.com> Date: Wed, 7 Feb 2024 09:30:22 +0800 Subject: [PATCH] DiffSinger phonemizers: Return error if lyric isn't found in the dictionary --- .../DiffSinger/DiffSingerBasePhonemizer.cs | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/OpenUtau.Core/DiffSinger/DiffSingerBasePhonemizer.cs b/OpenUtau.Core/DiffSinger/DiffSingerBasePhonemizer.cs index 0cbe10f62..61af0c478 100644 --- a/OpenUtau.Core/DiffSinger/DiffSingerBasePhonemizer.cs +++ b/OpenUtau.Core/DiffSinger/DiffSingerBasePhonemizer.cs @@ -88,7 +88,7 @@ string[] GetSymbols(Note note) { //1. phonetic hint //2. query from g2p dictionary //3. treat lyric as phonetic hint, including single phoneme - //4. default pause + //4. empty if (!string.IsNullOrEmpty(note.phoneticHint)) { // Split space-separated symbols into an array. return note.phoneticHint.Split() @@ -108,7 +108,7 @@ string[] GetSymbols(Note note) { if (lyricSplited.Length > 0) { return lyricSplited; } - return new string[] { defaultPause }; + return new string[] { }; } string GetSpeakerAtIndex(Note note, int index){ @@ -122,21 +122,20 @@ string GetSpeakerAtIndex(Note note, int index){ return speaker.Suffix; } - dsPhoneme[] GetDsPhonemes(Note note){ - return GetSymbols(note) - .Select((symbol, index) => new dsPhoneme(symbol, GetSpeakerAtIndex(note, index))) - .ToArray(); - } - protected bool IsSyllableVowelExtensionNote(Note note) { return note.lyric.StartsWith("+~") || note.lyric.StartsWith("+*"); } - List ProcessWord(Note[] notes){ + /// + /// distribute phonemes to each note inside the group + /// + List ProcessWord(Note[] notes, string[] symbols){ var wordPhonemes = new List{ new phonemesPerNote(-1, notes[0].tone) }; - var dsPhonemes = GetDsPhonemes(notes[0]); + var dsPhonemes = symbols + .Select((symbol, index) => new dsPhoneme(symbol, GetSpeakerAtIndex(notes[0], index))) + .ToArray(); var isVowel = dsPhonemes.Select(s => g2p.IsVowel(s.Symbol)).ToArray(); var isGlide = dsPhonemes.Select(s => g2p.IsGlide(s.Symbol)).ToArray(); var nonExtensionNotes = notes.Where(n=>!IsSyllableVowelExtensionNote(n)).ToArray(); @@ -217,8 +216,17 @@ protected override void ProcessPart(Note[][] phrase) { new phonemesPerNote(-1,phrase[0][0].tone, new List{new dsPhoneme("SP", GetSpeakerAtIndex(phrase[0][0], 0))}) }; var notePhIndex = new List { 1 }; - foreach (var word in phrase) { - var wordPhonemes = ProcessWord(word); + var wordFound = new bool[phrase.Length]; + foreach (int wordIndex in Enumerable.Range(0, phrase.Length)) { + Note[] word = phrase[wordIndex]; + var symbols = GetSymbols(word[0]); + if (symbols == null || symbols.Length == 0) { + symbols = new string[] { defaultPause }; + wordFound[wordIndex] = false; + } else { + wordFound[wordIndex] = true; + } + var wordPhonemes = ProcessWord(word, symbols); phrasePhonemes[^1].Phonemes.AddRange(wordPhonemes[0].Phonemes); phrasePhonemes.AddRange(wordPhonemes.Skip(1)); notePhIndex.Add(notePhIndex[^1]+wordPhonemes.SelectMany(n=>n.Phonemes).Count()); @@ -310,20 +318,24 @@ protected override void ProcessPart(Note[][] phrase) { //Convert the position sequence to tick and fill into the result list int index = 1; - foreach (int groupIndex in Enumerable.Range(0, phrase.Length)) { - Note[] group = phrase[groupIndex]; + foreach (int wordIndex in Enumerable.Range(0, phrase.Length)) { + Note[] word = phrase[wordIndex]; var noteResult = new List>(); - if (group[0].lyric.StartsWith("+")) { + if (!wordFound[wordIndex]){ + //partResult[word[0].position] = noteResult; + continue; + } + if (word[0].lyric.StartsWith("+")) { continue; } - double notePos = timeAxis.TickPosToMsPos(group[0].position);//start position of the note, ms - for (int phIndex = notePhIndex[groupIndex]; phIndex < notePhIndex[groupIndex + 1]; ++phIndex) { + double notePos = timeAxis.TickPosToMsPos(word[0].position);//start position of the note, ms + for (int phIndex = notePhIndex[wordIndex]; phIndex < notePhIndex[wordIndex + 1]; ++phIndex) { if (!String.IsNullOrEmpty(phs[phIndex].Symbol)) { noteResult.Add(Tuple.Create(phs[phIndex].Symbol, timeAxis.TicksBetweenMsPos( notePos, positions[phIndex - 1]))); } } - partResult[group[0].position] = noteResult; + partResult[word[0].position] = noteResult; } } }