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;

            }

        }

  • 相关阅读:
    ssize_t与size_t的前世今生
    jQuery 中的事件参数传递机制
    链表的container_of 疑惑
    c 语言使用疑惑小记
    IQueryFilter的WhereClause详解
    给自己鼓励...
    什么是闭包,我的理解
    WCF 第五章 行为 为服务终结点行为实现一个消息检测器
    WCF 第五章 行为 事务之事务服务行为
    WCF 第四章 绑定 wsHttpBinding
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14224475.html
Copyright © 2011-2022 走看看