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;

            }

        }

  • 相关阅读:
    【转】GitHub 中国区前 100 名到底是什么样的人?
    不同服务器数据库之间的数据操作
    行列互换
    千万级数据查询
    用命令对sql进行备份
    通过SQL Server 2008数据库复制实现数据库同步备份
    各种字符串合并处理示例.
    字符串分解
    四大排序函数
    cross apply 和 outer apply
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14224475.html
Copyright © 2011-2022 走看看