forked from stakira/OpenUtau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultPhonemizer.cs
31 lines (30 loc) · 1.38 KB
/
DefaultPhonemizer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using OpenUtau.Api;
using OpenUtau.Core.Ustx;
using System.Linq;
namespace OpenUtau.Core {
/// <summary>
/// The simplest Phonemizer possible. Simply pass the lyric as phoneme.
/// </summary>
[Phonemizer("Default Phonemizer", "DEFAULT")]
public class DefaultPhonemizer : Phonemizer {
private USinger singer;
public override void SetSinger(USinger singer) => this.singer = singer;
public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevNeighbour, Note? nextNeighbour, Note[] prevNeighbours) {
// Note that even when input has multiple notes, only the leading note is used to produce phoneme.
// This is because the 2nd+ notes will always be extender notes, i.e., with lyric "+" or "+<number>".
// For this simple phonemizer, all these notes maps to a single phoneme.
string alias = notes[0].lyric;
var attr0 = notes[0].phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;
if (singer.TryGetMappedOto(notes[0].lyric, notes[0].tone + attr0.toneShift, attr0.voiceColor, out var oto)) {
alias = oto.Alias;
}
return new Result {
phonemes = new Phoneme[] {
new Phoneme {
phoneme = alias,
}
}
};
}
}
}