Xamarin.forms Xamarin表单:如何突出显示文本并暂停/播放文本到语音的音频?

Xamarin.forms Xamarin表单:如何突出显示文本并暂停/播放文本到语音的音频?,xamarin.forms,text-to-speech,xamarin.essentials,Xamarin.forms,Text To Speech,Xamarin.essentials,我正在使用xamarin essentials软件包实现文本到语音的功能。演讲时,我需要突出显示相应的文本。另外,我需要一个暂停/播放演讲的选项。请看视频 屏幕截图: 如何实现突出显示文本功能并暂停/播放音频作为视频? 突出显示文本功能 您可以拆分标签的文本。并使用Span设置高光 在xaml中 暗藏 public分部类主页面:ContentPage { 字符串[]strList; 公共主页() { 初始化组件(); string content=“每个平台都支持不同的区域设置,\n以不同

我正在使用
xamarin essentials
软件包实现文本到语音的功能。演讲时,我需要突出显示相应的文本。另外,我需要一个暂停/播放演讲的选项。请看视频

屏幕截图:

如何实现突出显示文本功能并暂停/播放音频作为视频?

突出显示文本功能

您可以拆分标签的文本。并使用Span设置高光

在xaml中

暗藏
public分部类主页面:ContentPage
{
字符串[]strList;
公共主页()
{
初始化组件();
string content=“每个平台都支持不同的区域设置,\n以不同的语言和口音回传文本。\n平台具有不同的代码和指定区域设置的方式,\n这就是Xamarin提供跨平台区域设置类以及使用GetLocalesAsync查询这些类的原因。\n”;
label.Text=内容;
字符串str=“.”;
char character=char.Parse(str);
字符串str2=“,”;
character2=char.Parse(str2);
strList=content.Split(新字符[]{character,character2});
}
已单击专用异步无效按钮(对象发送方,事件参数e)
{
for(int i=0;i对于(int j=0;j@LucasZhang-MSFT我的数据是HTML,所以当我启动TTS时,它会在UI上显示HTML数据,TTS会获取这些数据。@LucasZhang MSFT目前我使用的是文本类型HTML的普通标签,所以在最初显示数据时不会出现此类问题。但是在进行TTS时会出现上述问题。HTML数据问题有任何解决方案吗?我没有我想我们可以用TTS为Html数据实现它。如果我尝试使用Xam.Plugin.htmlabel,这是解决方案吗?你可以试试。
<StackLayout x:Name="firstPage" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">

  <Label  x:Name="label"  WidthRequest="250" HeightRequest="300" />


  <Button Text="start" Clicked="Button_Clicked" />

</StackLayout>
public partial class MainPage : ContentPage
{

    string[] strList;

    public MainPage()
    {
        InitializeComponent();

        string content = "Each platform supports different locales,\n to speak back text in different languages and accents.\n Platforms have different codes and ways of specifying the locale, \n  which is why Xamarin provides a cross-platform Locale class and a way to query them with GetLocalesAsync.\n ";

        label.Text = content;

        string str = ".";
        char character = char.Parse(str);

        string str2 = ",";
        char character2 = char.Parse(str2);

        strList = content.Split(new char[] { character,character2 });



    }

    private async void Button_Clicked(object sender, EventArgs e)
    {
        for (int i=0;i< strList.Length;i++)
        {
            string content = strList[i];

            var formattedString = new FormattedString();

            for (int j=0;j<strList.Length;j++)
            {
                
                if(i==j)
                {
                    formattedString.Spans.Add(new Span { Text = strList[j], ForegroundColor = Color.Black, BackgroundColor = Color.Gray });
                }

                else
                {
                    formattedString.Spans.Add(new Span { Text = strList[j], ForegroundColor = Color.Black, });
                }
                

            }

            label.FormattedText = formattedString;

            //Using a bool varibale we can pause the TTS fucntion, when press back button set the value of StopTTS to true.
            //When loading this set the value back to false.
            if (!Utility.StopTTS)
            {
                await TextToSpeech.SpeakAsync(content);
            }

        }
    }
    
    protected override bool OnBackButtonPressed()
    {
        Utility.StopTTS = true;
        return base.OnBackButtonPressed();
    }


}