Skip to content

Commit 8aeeca4

Browse files
authored
Merge pull request #1256 from yqzhishen/add-dsdict-check
Add checks for phoneme definitions in dsdict.yaml
2 parents 1036deb + c267218 commit 8aeeca4

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

OpenUtau.Core/DiffSinger/DiffSingerBasePhonemizer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,19 @@ protected bool IsSyllableVowelExtensionNote(Note note) {
201201
/// distribute phonemes to each note inside the group
202202
/// </summary>
203203
List<phonemesPerNote> ProcessWord(Note[] notes, string[] symbols){
204+
//Check if all phonemes are defined in dsdict.yaml (for their types)
205+
foreach (var symbol in symbols) {
206+
if (!g2p.IsValidSymbol(symbol)) {
207+
throw new InvalidDataException(
208+
$"Type definition of symbol \"{symbol}\" not found. Consider adding it to dsdict.yaml (or dsdict-<lang>.yaml) of the phonemizer.");
209+
}
210+
}
204211
var wordPhonemes = new List<phonemesPerNote>{
205212
new phonemesPerNote(-1, notes[0].tone)
206213
};
207214
var dsPhonemes = symbols
208215
.Select((symbol, index) => new dsPhoneme(symbol, GetSpeakerAtIndex(notes[0], index)))
209-
.ToArray();
216+
.ToArray();
210217
var isVowel = dsPhonemes.Select(s => g2p.IsVowel(s.Symbol)).ToArray();
211218
var isGlide = dsPhonemes.Select(s => g2p.IsGlide(s.Symbol)).ToArray();
212219
var nonExtensionNotes = notes.Where(n=>!IsSyllableVowelExtensionNote(n)).ToArray();

OpenUtau.Core/DiffSinger/DiffSingerPitch.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ public RenderPitchResult Process(RenderPhrase phrase){
106106
var endMs = phrase.notes[^1].endMs + tailMs;
107107
int headFrames = (int)Math.Round(headMs / frameMs);
108108
int tailFrames = (int)Math.Round(tailMs / frameMs);
109+
if (dsConfig.predict_dur || dsConfig.use_note_rest) {
110+
//Check if all phonemes are defined in dsdict.yaml (for their types)
111+
foreach (var phone in phrase.phones) {
112+
if (!g2p.IsValidSymbol(phone.phoneme)) {
113+
throw new InvalidDataException(
114+
$"Type definition of symbol \"{phone.phoneme}\" not found. Consider adding it to dsdict.yaml of the pitch predictor.");
115+
}
116+
}
117+
}
109118
//Linguistic Encoder
110119
var linguisticInputs = new List<NamedOnnxValue>();
111120
var tokens = phrase.phones

OpenUtau.Core/DiffSinger/DiffSingerVariance.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ int PhonemeTokenize(string phoneme){
103103
public VarianceResult Process(RenderPhrase phrase){
104104
int headFrames = (int)Math.Round(headMs / frameMs);
105105
int tailFrames = (int)Math.Round(tailMs / frameMs);
106+
if (dsConfig.predict_dur) {
107+
//Check if all phonemes are defined in dsdict.yaml (for their types)
108+
foreach (var phone in phrase.phones) {
109+
if (!g2p.IsValidSymbol(phone.phoneme)) {
110+
throw new InvalidDataException(
111+
$"Type definition of symbol \"{phone.phoneme}\" not found. Consider adding it to dsdict.yaml of the variance predictor.");
112+
}
113+
}
114+
}
106115
//Linguistic Encoder
107116
var linguisticInputs = new List<NamedOnnxValue>();
108117
var tokens = phrase.phones.Select(p => p.phoneme)

0 commit comments

Comments
 (0)