Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EN X-SAMPA Phonemizer] Consonant length optimization + refactor #924

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions OpenUtau.Core/Classic/ClassicRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Task<RenderResult> RenderInternal(RenderPhrase phrase, Progress progress,
VoicebankFiles.Inst.CopyBackMetaFiles(item.inputFile, item.inputTemp);
}
}
progress.Complete(1, $"Track {trackNo + 1}: {item.resampler} \"{item.phone.phoneme}\"");
progress.Complete(1, $"Track {trackNo}: {item.resampler} \"{item.phone.phoneme}\"");
});
var result = Layout(phrase);
var wavtool = new SharpWavtool(true);
Expand All @@ -97,7 +97,7 @@ public Task<RenderResult> RenderExternal(RenderPhrase phrase, Progress progress,
resamplerItems.Add(new ResamplerItem(phrase, phone));
}
var task = Task.Run(() => {
string progressInfo = $"Track {trackNo + 1} : {phrase.wavtool} \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
string progressInfo = $"Track {trackNo} : {phrase.wavtool} \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
progress.Complete(0, progressInfo);
var wavPath = Path.Join(PathManager.Inst.CachePath, $"cat-{phrase.hash:x16}.wav");
var result = Layout(phrase);
Expand Down
3 changes: 0 additions & 3 deletions OpenUtau.Core/Classic/Ust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,9 @@ public static List<UNote> WritePlugin(UProject project, UVoicePart part, UNote f
var note = first;
while (note != last.Next) {
if (note.position < position) {
//Ignore current note if it is overlapped with previous note
note = note.Next;
continue;
}
if (note.position > position) {
//Insert R note if there is space between two notes
writer.WriteLine($"[#{sequence.Count:D4}]");
var spacer = UNote.Create();
spacer.position = position;
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Core/Classic/WorldlineRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Task<RenderResult> Render(RenderPhrase phrase, Progress progress, int tra
var task = Task.Run(() => {
var result = Layout(phrase);
var wavPath = Path.Join(PathManager.Inst.CachePath, $"wdl-{phrase.hash:x16}.wav");
string progressInfo = $"Track {trackNo + 1}: {this} {string.Join(" ", phrase.phones.Select(p => p.phoneme))}";
string progressInfo = $"Track {trackNo}: {this} {string.Join(" ", phrase.phones.Select(p => p.phoneme))}";
progress.Complete(0, progressInfo);
if (File.Exists(wavPath)) {
try {
Expand Down
7 changes: 0 additions & 7 deletions OpenUtau.Core/Commands/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,4 @@ public GotoOtoNotification(USinger singer, UOto oto) {
}
public override string ToString() => "Goto oto.";
}

public class NotePresetChangedNotification : UNotification {
public NotePresetChangedNotification() {

}
public override string ToString() => "Note preset changed.";
}
}
2 changes: 1 addition & 1 deletion OpenUtau.Core/DiffSinger/DiffSingerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Task<RenderResult> Render(RenderPhrase phrase, Progress progress, int tra
? $"ds-{phrase.hash:x16}-depth{depth}-{speedup}x.wav" // if the depth changes, phrase should be re-rendered
: $"ds-{phrase.hash:x16}-{speedup}x.wav"; // preserve this for not invalidating cache from older versions
var wavPath = Path.Join(PathManager.Inst.CachePath, wavName);
string progressInfo = $"Track {trackNo + 1}: {this}{speedup}x \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
string progressInfo = $"{this}{speedup}x \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
if (File.Exists(wavPath)) {
try {
using (var waveStream = Wave.OpenFile(wavPath)) {
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Core/DocManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void SearchAllPlugins() {

public bool ChangesSaved {
get {
return (Project.Saved || (Project.tracks.Count <= 1 && Project.parts.Count == 0)) &&
return (Project.Saved || Project.tracks.Count == 0) &&
(undoQueue.Count > 0 && savedPoint == undoQueue.Last() || undoQueue.Count == 0 && savedPoint == null);
}
}
Expand Down
40 changes: 0 additions & 40 deletions OpenUtau.Core/Editing/NoteBatchEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,46 +142,6 @@ public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, Do
}
}

public class FixOverlap: BatchEdit {
/// <summary>
/// Fix overlapping notes.
/// If multiple notes start at the same time, only the one with the highest tone will be kept
/// If one notes's end is overlapped by another note, the end will be moved to the start of the next note
/// </summary>
public virtual string Name => name;

private string name;

public FixOverlap() {
name = $"pianoroll.menu.notes.fixoverlap";
}

public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, DocManager docManager) {
var notes = selectedNotes.Count > 0 ? selectedNotes : part.notes.ToList();
if(notes.Count == 0){
return;
}
docManager.StartUndoGroup();
var currentNote = notes[0];
foreach(var note in notes.Skip(1)){
if(note.position == currentNote.position){
if(note.tone > currentNote.tone){
docManager.ExecuteCmd(new RemoveNoteCommand(part, currentNote));
currentNote = note;
}else{
docManager.ExecuteCmd(new RemoveNoteCommand(part, note));
}
}else if(note.position < currentNote.End){
docManager.ExecuteCmd(new ResizeNoteCommand(part, currentNote, note.position - currentNote.End));
currentNote = note;
}else{
currentNote = note;
}
}
docManager.EndUndoGroup();
}
}

public class HanziToPinyin : BatchEdit {
public virtual string Name => name;

Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Core/Enunu/EnunuRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Task<RenderResult> Render(RenderPhrase phrase, Progress progress, int tra
if (cancellation.IsCancellationRequested) {
return new RenderResult();
}
string progressInfo = $"Track {trackNo + 1}: {this} \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
string progressInfo = $"Track {trackNo}: {this} \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
progress.Complete(0, progressInfo);
var tmpPath = Path.Join(PathManager.Inst.CachePath, $"enu-{phrase.preEffectHash:x16}");
var ustPath = tmpPath + ".tmp";
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Core/Vogen/VogenRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Task<RenderResult> Render(RenderPhrase phrase, Progress progress, int tra
}
var result = Layout(phrase);
var wavPath = Path.Join(PathManager.Inst.CachePath, $"vog-{phrase.hash:x16}.wav");
string progressInfo = $"Track {trackNo + 1}: {this} \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
string progressInfo = $"Track {trackNo}: {this} \"{string.Join(" ", phrase.phones.Select(p => p.phoneme))}\"";
progress.Complete(0, progressInfo);
if (File.Exists(wavPath)) {
try {
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Plugin.Builtin/ChineseCVVCPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
29 changes: 9 additions & 20 deletions OpenUtau.Plugin.Builtin/EnXSampaPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using OpenUtau.Api;
Expand All @@ -24,8 +23,7 @@ public class EnXSampaPhonemizer : SyllableBasedPhonemizer {
private readonly string[] consonants = "b,tS,d,D,4,f,g,h,dZ,k,l,m,n,N,p,r,s,S,t,T,v,w,W,j,z,Z,t_},・,_".Split(',');
private readonly string[] affricates = "tS,dZ".Split(',');
private readonly string[] shortConsonants = "4".Split(",");
private readonly string[] longConsonants = "tS,f,dZ,k,p,s,S,t,T,t_}".Split(",");
private readonly string[] normalConsonants = "b,d,D,g,h,l,m,n,N,r,v,w,W,j,z,Z,・".Split(',');
private readonly string[] longConsonants = "tS,f,dZ,k,p,s,S,t,T,t_},t}".Split(",");
private readonly Dictionary<string, string> dictionaryReplacements = ("aa=A;ae={;ah=V;ao=O;aw=aU;ax=@;ay=aI;" +
"b=b;ch=tS;d=d;dh=D;" + "dx=4;eh=E;el=@l;em=@m;en=@n;eng=@N;er=3;ey=eI;f=f;g=g;hh=h;ih=I;iy=i;jh=dZ;k=k;l=l;m=m;n=n;ng=N;ow=oU;oy=OI;" +
"p=p;q=・;r=r;s=s;sh=S;t=t;th=T;" + "uh=U;uw=u;v=v;w=w;" + "y=j;z=z;zh=Z").Split(';')
Expand Down Expand Up @@ -641,28 +639,19 @@ protected override string ValidateAlias(string alias) {
}

protected override double GetTransitionBasicLengthMs(string alias = "") {
UOto? oto;
oto = default;
var suffix = oto?.Suffix;

foreach (var c in longConsonants) {
if (alias.Contains(c)) {
if (!alias.StartsWith(c)) {
return base.GetTransitionBasicLengthMs() * 2.0;
}
}
}
foreach (var c in normalConsonants) {
if (!alias.Contains("_D")) {
if (alias.Contains(c)) {
if (!alias.StartsWith(c)) {
return base.GetTransitionBasicLengthMs();
}
}
if (alias.EndsWith(c) && suffix == null) {
return base.GetTransitionBasicLengthMs() * 2.0;
}
}

foreach (var c in shortConsonants) {
if (alias.Contains(c)) {
if (!alias.Contains(" _")) {
return base.GetTransitionBasicLengthMs() * 0.50;
}
if (alias.EndsWith(c) && suffix == null) {
return base.GetTransitionBasicLengthMs() * 0.5;
}
}
return base.GetTransitionBasicLengthMs();
Expand Down
6 changes: 4 additions & 2 deletions OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using OpenUtau.Api;
Expand Down Expand Up @@ -131,9 +131,11 @@ private bool checkOtoUntilHit(string[] input, Note note, out UOto oto) {

// checking VCs
// when VC does not exist, it will not be inserted
// TODO: fix duplicate voice color fallback bug (for now, this is better than nothing)
private bool checkOtoUntilHitVc(string[] input, Note note, out UOto oto) {
oto = default;
var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default;
var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;
var attr1 = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default;

var otos = new List<UOto>();
foreach (string test in input) {
Expand Down
3 changes: 2 additions & 1 deletion OpenUtau.Plugin.Builtin/JapanesePresampPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ private bool checkOtoUntilHit(List<string> input, Note note, out UOto oto) {

// checking VCs
// when VC does not exist, it will not be inserted
// TODO: fix duplicate voice color fallback bug (for now, this is better than nothing)
private bool checkOtoUntilHitVc(List<string> input, Note note, out UOto oto) {
oto = default;
var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default;
var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;

var otos = new List<UOto>();
foreach (string test in input) {
Expand Down
38 changes: 8 additions & 30 deletions OpenUtau.Plugin.Builtin/KoreanVCVPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -121,21 +121,10 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
Note note = notes[0];
string color = string.Empty;
int shift = 0;
int? alt;

string color1 = string.Empty;
int shift1 = 0;
int? alt1;

PhonemeAttributes attr = note.phonemeAttributes.FirstOrDefault(a => a.index == 0);
PhonemeAttributes attr = note.phonemeAttributes.FirstOrDefault(a => a.index == 0);
color = attr.voiceColor;
shift = attr.toneShift;
alt = attr.alternate;

PhonemeAttributes attr1 = note.phonemeAttributes.FirstOrDefault(a => a.index == 1);
color1 = attr1.voiceColor;
shift1 = attr1.toneShift;
alt1 = attr1.alternate;

string[] currIMF;
string currPhoneme;
Expand Down Expand Up @@ -179,9 +168,7 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
}

// Map alias (apply shift + color)
if (singer.TryGetMappedOto(currPhoneme + alt, note.tone + shift, color, out var otoAlt)) {
currPhoneme = otoAlt.Alias;
} else if (singer.TryGetMappedOto(currPhoneme, note.tone + shift, color, out var oto)) {
if (singer.TryGetMappedOto(currPhoneme, note.tone + shift, color, out var oto)) {
currPhoneme = oto.Alias;
}

Expand Down Expand Up @@ -267,9 +254,7 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
if (string.IsNullOrEmpty(currIMF[2]))
{
// Map alias (apply shift + color)
if (singer.TryGetMappedOto(currPhoneme + alt, note.tone + shift, color, out var otoAlt)) {
currPhoneme = otoAlt.Alias;
} else if (singer.TryGetMappedOto(currPhoneme, note.tone + shift, color, out var oto)) {
if (singer.TryGetMappedOto(currPhoneme, note.tone + shift, color, out var oto)) {
currPhoneme = oto.Alias;
}

Expand All @@ -291,13 +276,13 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
if (string.IsNullOrEmpty(currIMF[2])) secondPhoneme += " R";
else
{
if (singer.TryGetMappedOto($"{secondPhoneme} {currIMF[2]}", note.tone + shift1, color1, out _)) secondPhoneme += $" {currIMF[2]}";
if (singer.TryGetMappedOto($"{secondPhoneme} {currIMF[2]}", note.tone + shift, color, out _)) secondPhoneme += $" {currIMF[2]}";
else secondPhoneme += $" {currIMF[2].ToUpper()}";
}
}
else if (!string.IsNullOrEmpty(currIMF[2]))
{
if (singer.TryGetMappedOto($"{secondPhoneme} {currIMF[2]}", note.tone + shift1, color1, out _)) secondPhoneme += $" {currIMF[2]}";
if (singer.TryGetMappedOto($"{secondPhoneme} {currIMF[2]}", note.tone + shift, color, out _)) secondPhoneme += $" {currIMF[2]}";
else secondPhoneme += $" {currIMF[2].ToUpper()}";
}

Expand All @@ -307,16 +292,9 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
int secondPosition = Math.Max(noteLength - (nextNeighbour == null ? 120 : 180), noteLength / 2);

// Map alias (apply shift + color)
if (singer.TryGetMappedOto(currPhoneme + alt, note.tone + shift, color, out var otoAlt)) {
currPhoneme = otoAlt.Alias;
} else if (singer.TryGetMappedOto(currPhoneme, note.tone + shift, color, out var oto)) {
if (singer.TryGetMappedOto(currPhoneme, note.tone + shift, color, out var oto) && singer.TryGetMappedOto(secondPhoneme, note.tone + shift, color, out var oto1)) {
currPhoneme = oto.Alias;
}

if (singer.TryGetMappedOto(secondPhoneme + alt1, note.tone + shift1, color1, out var otoAlt1)) {
secondPhoneme = otoAlt1.Alias;
} else if (singer.TryGetMappedOto(secondPhoneme, note.tone + shift1, color1, out var oto)) {
secondPhoneme = oto.Alias;
secondPhoneme = oto1.Alias;
}

// Return Result
Expand Down
Loading