From 68b7d3fd1433134d5131ad0a948264bb2c22bfb4 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 14 Apr 2024 17:25:41 +0200 Subject: [PATCH] Work on tts --- src/libse/TextToSpeech/PiperModels.cs | 2 +- src/ui/Forms/Tts/TextToSpeech.cs | 73 ++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/libse/TextToSpeech/PiperModels.cs b/src/libse/TextToSpeech/PiperModels.cs index bb8b5786a..7e4841601 100644 --- a/src/libse/TextToSpeech/PiperModels.cs +++ b/src/libse/TextToSpeech/PiperModels.cs @@ -99,7 +99,7 @@ namespace Nikse.SubtitleEdit.Core.TextToSpeech new PiperModels("huayan", "Chinese", "medium", "https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/zh/zh_CN/huayan/medium/zh_CN-huayan-medium.onnx", "https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/zh/zh_CN/huayan/medium/zh_CN-huayan-medium.onnx.json"), }; - return models; + return models.OrderBy(p=>p.ToString()).ToList(); } } } diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index c6b24a734..3e8212eb2 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -773,23 +773,70 @@ namespace Nikse.SubtitleEdit.Forms.Tts FillActorListView(); contextMenuStripActors.Items.Clear(); - for (var index = 0; index < nikseComboBoxVoice.Items.Count; index++) + + if (engine.Id == TextToSpeechEngine.IdPiper) { - var item = nikseComboBoxVoice.Items[index]; - - var tsi = new ToolStripMenuItem(); - tsi.Tag = new ActorAndVoice { Voice = item.ToString(), VoiceIndex = index }; - tsi.Text = item.ToString(); - tsi.Click += (x, args) => + var voices = PiperModels.GetVoices(); + foreach (var voiceLanguage in voices + .GroupBy(p => p.Language) + .OrderBy(p => p.Key)) { - var a = (ActorAndVoice)(x as ToolStripItem).Tag; - SetActor(a); - }; - contextMenuStripActors.Items.Add(tsi); + if (voiceLanguage.Count() == 1) + { + var voice = voiceLanguage.First(); + var tsi = new ToolStripMenuItem(); + tsi.Tag = new ActorAndVoice { Voice = voice.Voice, VoiceIndex = voices.IndexOf(voice) }; + tsi.Text = voice.ToString(); + tsi.Click += (x, args) => + { + var a = (ActorAndVoice)(x as ToolStripItem).Tag; + SetActor(a); + }; + contextMenuStripActors.Items.Add(tsi); + } + else + { + var parent = new ToolStripMenuItem(); + parent.Text = voiceLanguage.Key; + contextMenuStripActors.Items.Add(parent); - labelActors.Visible = true; - listViewActors.Visible = true; + foreach (var voice in voiceLanguage.OrderBy(p => p.Voice).ToList()) + { + var tsi = new ToolStripMenuItem(); + tsi.Tag = new ActorAndVoice { Voice = voice.Voice, VoiceIndex = voices.IndexOf(voice) }; + tsi.Text = voice.Voice + " (" + voice.Quality + ")"; + tsi.Click += (x, args) => + { + var a = (ActorAndVoice)(x as ToolStripItem).Tag; + SetActor(a); + }; + parent.DropDownItems.Add(tsi); + } + + DarkTheme.SetDarkTheme(parent); + } + } } + else + { + for (var index = 0; index < nikseComboBoxVoice.Items.Count; index++) + { + var item = nikseComboBoxVoice.Items[index]; + + var tsi = new ToolStripMenuItem(); + tsi.Tag = new ActorAndVoice { Voice = item.ToString(), VoiceIndex = index }; + tsi.Text = item.ToString(); + tsi.Click += (x, args) => + { + var a = (ActorAndVoice)(x as ToolStripItem).Tag; + SetActor(a); + }; + contextMenuStripActors.Items.Add(tsi); + } + } + + labelActors.Visible = true; + listViewActors.Visible = true; } } }