diff --git a/Mirivoice/Mirivoice.Core/Format/Voicer.cs b/Mirivoice/Mirivoice.Core/Format/Voicer.cs index f938fbb..df4760c 100644 --- a/Mirivoice/Mirivoice.Core/Format/Voicer.cs +++ b/Mirivoice/Mirivoice.Core/Format/Voicer.cs @@ -73,7 +73,13 @@ public void Inference(string ipaText, string cacheFilePath, LineBoxView l) { //Log.Debug("[Infer Started] --- ipaText"); int spkid = CurrentVoicerMeta.SpeakerId; - Engine.Inference(ipaText, cacheFilePath, spkid); + Inference(ipaText, cacheFilePath, l, spkid); + } + + public void Inference(string ipaText, string cacheFilePath, LineBoxView l, int sid) + { + //Log.Debug("[Infer Started] --- ipaText"); + Engine.Inference(ipaText, cacheFilePath, sid); if (l != null) { l.IsCacheIsVaild = true; diff --git a/Mirivoice/ViewModels/VoicersStyleBoxViewModel.cs b/Mirivoice/ViewModels/VoicersStyleBoxViewModel.cs index bd5fd2a..00b9eb2 100644 --- a/Mirivoice/ViewModels/VoicersStyleBoxViewModel.cs +++ b/Mirivoice/ViewModels/VoicersStyleBoxViewModel.cs @@ -51,6 +51,17 @@ public string StyleName OnPropertyChanged(nameof(StyleName)); } } + + private int _spkid; + public int Spkid + { + get => _spkid; + set + { + this.RaiseAndSetIfChanged(ref _spkid, value); + OnPropertyChanged(nameof(Spkid)); + } + } public VoicersStyleBoxViewModel() { } diff --git a/Mirivoice/ViewModels/VoicersVoicerButtonViewModel.cs b/Mirivoice/ViewModels/VoicersVoicerButtonViewModel.cs index d24166b..17d11e4 100644 --- a/Mirivoice/ViewModels/VoicersVoicerButtonViewModel.cs +++ b/Mirivoice/ViewModels/VoicersVoicerButtonViewModel.cs @@ -12,6 +12,7 @@ using System.IO; using Avalonia.Media.Imaging; using Mirivoice.Engines; +using Serilog; namespace Mirivoice.ViewModels { @@ -103,6 +104,8 @@ public void OnButtonClick() VoicerMeta[] voicerMetas = Voicer.VoicerMetaCollection.ToArray(); foreach (var meta in voicerMetas ) { + Log.Debug($"VoicerMeta {i}: {meta.Style}"); + Voicer.CurrentVoicerMeta = meta; voicersStyleBoxes.Add(new VoicersStyleBox(Voicer, i, mv)); ++i; } diff --git a/Mirivoice/Views/VoicersStyleBox.axaml.cs b/Mirivoice/Views/VoicersStyleBox.axaml.cs index 98c0517..2506e36 100644 --- a/Mirivoice/Views/VoicersStyleBox.axaml.cs +++ b/Mirivoice/Views/VoicersStyleBox.axaml.cs @@ -8,6 +8,9 @@ using Avalonia.Interactivity; using Avalonia.Threading; using System; +using Serilog; +using System.IO; +using System.Linq; namespace Mirivoice; @@ -15,7 +18,7 @@ public partial class VoicersStyleBox : UserControl { public VoicersStyleBoxViewModel viewModel; private readonly MainViewModel v; - private Voicer voicer; + private Voicer voicer; // shared private string phrase; private BasePhonemizer phonemizer; private string cachePath; @@ -33,7 +36,6 @@ public VoicersStyleBox(Voicer voicer, int metaIndex, MainViewModel v) phonemizer = LineBoxViewModel.GetPhonemizer(voicer.Info.LangCode); cachePath = Guid.NewGuid().ToString(); this.voicer = voicer; - voicer.CurrentVoicerMeta = voicer.VoicerMetaCollection[metaIndex]; this.v = v; } @@ -51,12 +53,16 @@ public async void OnSamplePlayButtonClick(object sender, RoutedEventArgs e) isPlaying = false; return; } + if (File.Exists(cachePath)) + { + isPlaying = true; + } if (voicer != null) { isPlaying = true; string ipa = await phonemizer.ConvertToIPA(phrase, DispatcherPriority.ApplicationIdle); - voicer.Inference(ipa, cachePath, null); - v.PlayAudio(cachePath); + voicer.Inference(ipa, cachePath, null, sid); } + v.PlayAudio(cachePath); } } \ No newline at end of file