我正在尝试通过 Template10 UWP 应用程序的设置页面中的 ToggleSwitch 将 voice.gender 设置为男性或女性。
我声明 TG:
<ToggleSwitch x:Name="VoiceSelection" Header="Select Voice"
IsOn="{Binding VoiceChoice, Mode=TwoWay}"
OffContent="Male Voice" OnContent="Female Voice" />
那应该没问题。
然后我设置一个布尔值,稍后将用于选择男性或女性
public event PropertyChangedEventHandler PropertyChanged;
public static bool _voiceChoice = true;
public bool VoiceChoice
{
get
{
return _voiceChoice;
}
set
{
_voiceChoice = value;
OnPropertyChanged("VoiceChoice");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
有关信息,这是稍后分配语音的代码。这也很好。
...
if (_voiceChoice == true)
{
VoiceInformation voiceInfo =
(
from voice in SpeechSynthesizer.AllVoices
where voice.Gender == VoiceGender.Female
select voice
).FirstOrDefault() ?? SpeechSynthesizer.DefaultVoice;
synthesizer.Voice = voiceInfo;
stream = await synthesizer.SynthesizeTextToStreamAsync(text);
}
else
...
我遇到的问题是我可以通过手动设置布尔值 _voiceChoice 来选择声音,但我无法通过 ToggleSwitch 进行设置。
我也意识到这个解决方案不是很干净,我愿意接受任何建议。任何帮助是极大的赞赏。提前致谢。