• 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;

            }

        }

  • 相关阅读:
    mfc crc校验工具
    MFC 配置附加目录
    多线程中如何使用gdb精确定位死锁问题
    符号冲突
    动态库之间单例模式出现多个实例(Linux)
    c++普通函数在头文件定义报重复定义的错误。而class定义不会
    static初始化顺序及延伸
    tcmalloc使用中出现崩溃问题记录
    shell脚本—判断***是否安装
    【1080TI驱动+CUDA10.1+cudnn】安装记录
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14224475.html
Copyright © 2020-2023  润新知