Skip to content

Commit

Permalink
Fixed logic error in phonemizing
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Sep 27, 2024
1 parent 3472c25 commit b94c44a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 53 deletions.
6 changes: 5 additions & 1 deletion Mirivoice/Mirivoice.Core/Editor/MTextBoxEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public string CurrentScript

if ( value != null)
{
if (value == _currentScript)
{
Log.Debug("CurrentScript was same as lastScript");
return;
}
lastScript = _currentScript;

//Log.Debug("CurrentScript: {value}", value);
Expand Down Expand Up @@ -98,7 +103,6 @@ public string CurrentScript
this.RaiseAndSetIfChanged(ref _currentScript, value);

OnPropertyChanged(nameof(CurrentScript));

}


Expand Down
1 change: 1 addition & 0 deletions Mirivoice/Mirivoice.Core/Format/MResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ public MResult(MResultPrototype mResultPrototype): base(mResultPrototype.Phoneme
}
public override void OnVoicerChanged(Voicer value) { }
public override void OnVoicerCultureChanged(CultureInfo culture) { }

}
}
1 change: 1 addition & 0 deletions Mirivoice/Mirivoice.Core/Managers/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AudioManager
private LineBoxView _;
private readonly MainViewModel v;
private bool MainViewModelPlaying;
public bool IsPlaying => _waveOut.PlaybackState == PlaybackState.Playing;
public AudioManager(MainViewModel v)
{
this.v = v;
Expand Down
2 changes: 2 additions & 0 deletions Mirivoice/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public void ClearCache()
public void PlayAudio(string path)
{
MainManager.Instance.AudioM.PlayAudio(path);

}

public void StopAudio()
Expand Down Expand Up @@ -847,5 +848,6 @@ public async void OnVoicerInstallButtonClick()
public override void OnVoicerChanged(Voicer value) { }

public override void OnVoicerCultureChanged(CultureInfo culture) { }

}
}
1 change: 1 addition & 0 deletions Mirivoice/ViewModels/VoicerSelectingViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public VoicerSelectingViewModelBase(int voicerIndex, bool useVoicerSelector = fa
}
public abstract void OnVoicerChanged(Voicer value);
public abstract void OnVoicerCultureChanged(CultureInfo culture);

public VoicerSelectingViewModelBase(string initText, bool saveUndoAtInit, bool useVoicerSelector = false)
{
if (useVoicerSelector)
Expand Down
2 changes: 2 additions & 0 deletions Mirivoice/Views/LineBoxView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public bool ShouldPhonemize
}
}

public string lastPhonemizedText = string.Empty;
private async Task PhonemizeLine(bool ApplyToCurrentEdit = true)
{
if (viewModel is null)
Expand Down Expand Up @@ -140,6 +141,7 @@ private async Task PhonemizeLine(bool ApplyToCurrentEdit = true)
else
{
await Task.Run(() => viewModel.phonemizer.PhonemizeAsync(textChanged, this, ApplyToCurrentEdit));
lastPhonemizedText = textChanged;
}


Expand Down
60 changes: 12 additions & 48 deletions Mirivoice/Views/SingleLineEditorView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,20 @@ public SingleLineEditorView(LineBoxView l, bool FirstUpdate = true)

private async void LineTextChanged(object sender, TextChangedEventArgs e)
{

var textBox = sender as TextBox;
if (textBox != null)
l.DeActivatePhonemizer = false;
if (FirstUpdate)
{
try
{

string textChanged = textBox.Text;
if (l is null)
{
//Log.Debug("LineBoxView is null");
return;
}
if (l.viewModel.LineText == textBox.Text)
{
//Log.Debug($"No need to phonemize ---- SingleLineTBox '{textBox.Text}' // linePreview '{l.viewModel.LineText}' "); ;
l.DeActivatePhonemizer = true; // no need to phonemize
}
else
{
//Log.Debug($"SingleLineTBox '{textBox.Text}' // linePreview '{l.viewModel.LineText}' "); ;
l.viewModel.LineText = textChanged;
l.DeActivatePhonemizer = false;
if (FirstUpdate)
{
FirstUpdate = false;
Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
return;
}
if (l.ShouldPhonemize && !l.DeActivatePhonemizer)
{
await Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(textChanged, l));
}



}






}
finally
{

}

FirstUpdate = false;
Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
return;
}
if (l.ShouldPhonemize && !l.DeActivatePhonemizer)
{
await Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
}
l.viewModel.LineText = viewModel.mTextBoxEditor.CurrentScript;

}

private void LineLostFocus(object sender, RoutedEventArgs e)
Expand Down
6 changes: 2 additions & 4 deletions Mirivoice/Views/VoicersStyleBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Serilog;
using System.IO;
using System.Linq;
using Mirivoice.Mirivoice.Core;
namespace Mirivoice;


Expand Down Expand Up @@ -47,21 +48,18 @@ private void InitializeComponent()

public async void OnSamplePlayButtonClick(object sender, RoutedEventArgs e)
{
if (isPlaying)
if (MainManager.Instance.AudioM.IsPlaying)
{
v.StopAudio();
isPlaying = false;
return;
}
if (File.Exists(cachePath))
{
isPlaying = true;
v.PlayAudio(cachePath);
return;
}
if (voicer != null)
{
isPlaying = true;
string ipa = await phonemizer.ConvertToIPA(phrase, DispatcherPriority.ApplicationIdle);
voicer.Inference(ipa, cachePath, null, sid);
v.PlayAudio(cachePath);
Expand Down

0 comments on commit b94c44a

Please sign in to comment.