Skip to content

Commit

Permalink
Fixed bug in sample playing
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Sep 27, 2024
1 parent 4c79856 commit aafd7fd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Mirivoice/Mirivoice.Core/Format/Voicer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions Mirivoice/ViewModels/VoicersStyleBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
Expand Down
3 changes: 3 additions & 0 deletions Mirivoice/ViewModels/VoicersVoicerButtonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IO;
using Avalonia.Media.Imaging;
using Mirivoice.Engines;
using Serilog;

namespace Mirivoice.ViewModels
{
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 10 additions & 4 deletions Mirivoice/Views/VoicersStyleBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
using Avalonia.Interactivity;
using Avalonia.Threading;
using System;
using Serilog;
using System.IO;
using System.Linq;
namespace Mirivoice;


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;
Expand All @@ -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;
}

Expand All @@ -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);
}
}

0 comments on commit aafd7fd

Please sign in to comment.