zoukankan      html  css  js  c++  java
  • uwp 之语音朗读

    xml code

    ---------------------------------

    <Page

        x:Class="MyApp.MainPage"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:local="using:MyApp"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d"

        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <StackPanel>

            <TextBox Name="txtInput" Header="请输入文本:"/>

            <Button Content="开始朗读" Click="OnClick" Margin="0,15,0,0"/>

            <MediaElement Name="me" AutoPlay="True" Volume="1.0"/>

        </StackPanel>

    </Page>

    C# code

    ----------------------

      public sealed partial class MainPage : Page

        {

            public MainPage()

            {

                this.InitializeComponent();

                this.NavigationCacheMode = NavigationCacheMode.Required;

            }

            private async void OnClick(object sender, RoutedEventArgs e)

            {

                if (txtInput.Text.Length == 0) return;

                Button b = sender as Button;

                b.IsEnabled = false;

                SpeechSynthesizer synthesizer = new SpeechSynthesizer();

                SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(txtInput.Text);

                // 播放生成的语音

                me.SetSource(stream, stream.ContentType);

                b.IsEnabled = true;

            }

        }

  • 相关阅读:
    Oracle导数据到SQL server的方法总结
    linux vmware 安装步骤
    linux user
    linux 下载jdk
    Jaxb2实现JavaBean与xml互转的方法详解
    idea 远程代码调试
    Java一次读取文本文件所有内容
    mysql 8 server windows 安装经验分享
    java和mysql的length()区别及char_length()
    Java web 强制301跳转
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14224475.html
Copyright © 2011-2022 走看看