1. <Window x:Class="Synthesizer.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:Synthesizer"
  7. mc:Ignorable="d"
  8. d:DesignHeight="450" d:DesignWidth="800">
  9. <Window.Title>Synthesizer</Window.Title>
  10. <Window.Resources>
  11. <local:DoubleToStringConverter x:Key="converter" />
  12. </Window.Resources>
  13. <Grid>
  14. <Grid.RowDefinitions>
  15. <RowDefinition Height="*" />
  16. <RowDefinition Height="Auto" />
  17. <RowDefinition Height="Auto" />
  18. <RowDefinition Height="Auto" />
  19. </Grid.RowDefinitions>
  20. <Grid.ColumnDefinitions>
  21. <ColumnDefinition Width="*" />
  22. <ColumnDefinition Width="Auto" />
  23. </Grid.ColumnDefinitions>
  24. <TextBox Name="PreviewTextBox" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5 5 5 5" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"/>
  25. <ComboBox Name="VoiceComboBox" Grid.Row="1" Grid.Column="0" Width="320" Height="30" Margin="5 5 5 5" Grid.ColumnSpan="2"/>
  26. <Slider Name="SpeedSlider" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Width="320" Margin="5 5 5 5" Minimum="0.5" Maximum="1.0" Value="1.0"/>
  27. <Label Name="SpeedLabel" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="5 5 5 5" HorizontalAlignment="Center" Content="{Binding ElementName=SpeedSlider, Path=Value, Converter={StaticResource converter}}"/>
  28. <Button Name="SaveButton" Grid.Row="3" Grid.Column="1" Width="80" Height="45" Margin="5 5 5 5" Content="Save" Click="SaveButtonClick" />
  29. </Grid>
  30. </Window>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Microsoft.Win32;
  16. using Windows.Storage;
  17. using Windows.Storage.Streams;
  18. using Windows.Media.SpeechSynthesis;
  19. using System.IO;
  20.  
  21. namespace Synthesizer
  22. {
  23. /// <summary>
  24. /// MainWindow.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class MainWindow : Window
  27. {
  28. public MainWindow()
  29. {
  30. InitializeComponent();
  31. foreach (var voice in SpeechSynthesizer.AllVoices.OrderBy(voice => voice.Language))
  32. {
  33. VoiceComboBox.Items.Add(new ComboBoxItem() { Tag=voice,Content=string.Format("{0} ({1})",voice.DisplayName, voice.Language)});
  34. }
  35. if (VoiceComboBox.Items.Count > )
  36. {
  37. VoiceComboBox.SelectedIndex = ;
  38. }
  39. }
  40.  
  41. [STAThread]
  42. public static void Main(string[] args)
  43. {
  44. new MainWindow().ShowDialog();
  45. }
  46.  
  47. private async void SaveButtonClick(object sender, RoutedEventArgs e)
  48. {
  49. var dialog = new SaveFileDialog()
  50. {
  51. Filter = "WAV File|*.wav"
  52. };
  53. if (dialog.ShowDialog() != true)
  54. {
  55. return;
  56. }
  57. var synthesizer = new SpeechSynthesizer()
  58. {
  59. Voice = (VoiceComboBox.SelectedItem as ComboBoxItem).Tag as VoiceInformation
  60. };
  61. synthesizer.Options.SpeakingRate = SpeedSlider.Value;
  62. var stream = await synthesizer.SynthesizeTextToStreamAsync(PreviewTextBox.Text);
  63. using (var file = new FileStream(dialog.FileName, FileMode.Create))
  64. {
  65. stream.AsStream().CopyTo(file);
  66. }
  67. }
  68. }
  69. }
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Data;
  8.  
  9. namespace Synthesizer
  10. {
  11. [ValueConversion(typeof(double), typeof(string))]
  12. class DoubleToStringConverter : IValueConverter
  13. {
  14. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  15. {
  16. return (value as double?)?.ToString("F2");
  17. }
  18.  
  19. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  20. {
  21. return double.Parse(value as string);
  22. }
  23. }
  24. }

Speech Synthesis的更多相关文章

  1. System.Speech.Synthesis 添加暂停、继续功能

    为了方便调用暂停.继续的方法.要将speech的功能写成一个类.直接附上代码: using System; using System.Collections.Generic; using System ...

  2. HTML5语音合成Speech Synthesis API简介

    by zhangxinxu from http://www.zhangxinxu.com/wordpress/?p=5865本文可全文转载,但需得到原作者书面许可,同时保留原作者和出处,摘要引流则随意 ...

  3. C#中的System.Speech命名空间初探

    本程序是口算两位数乘法,随机生成两个两位数,用语音读出来.然后开启语音识别,接受用户输入,知道答案正确关闭语音识别.用户说答案时,可以说“再说一遍”重复题目. 关键是GrammarBuilder和Ch ...

  4. Speech两种使用方法

    COM组件使用speech: public class Speach { private static Speach _Instance = null ; private SpeechLib.SpVo ...

  5. csharp: Speech

    Speech SDK 5.1https://www.microsoft.com/en-us/download/details.aspx?id=10121 detects mobile devices ...

  6. 微软职位内部推荐-Senior Speech TTS

    微软近期Open的职位: Job Description: Responsibilities Do you want to change the way the world interacts wit ...

  7. asp.net引用System.Speech实现语音提示

    using System; using System.Speech.Synthesis; namespace testvoice { class Program { static void Main( ...

  8. C# 使用System.Speech 进行语音播报和识别

    C# 使用System.Speech 进行语音播报和识别 using System.Speech.Synthesis; using System.Speech.Recognition; //语音识别 ...

  9. 必应语音API(Bing text to speech API)

    前言 Link : Microsoft Speech API overview 通过这个链接,大致了解Bing speech API的语音识别和语音合成两部分, 这次是需要用到TTS,所以就直接看TT ...

随机推荐

  1. Python 中Lambda 表达式 实例解析

    Lambda 表达式 lambda表达式是一种简洁格式的函数.该表达式不是正常的函数结构,而是属于表达式的类型.而且它可以调用其它函数. 1.基本格式: lambda 参数,参数...:函数功能代码 ...

  2. service层代码相互调用, 导致spring循环依赖,设计上的优化

    管理员创建用户需要发送激活邮件, 而发送激活邮件的时候需要判断发件人是不是合法的用户, 因此设计到一个循环依赖的问题 //UserService @Service class UserService{ ...

  3. 新版的Bing Developer Assistant 已发布,去掉了Beta

    网址:https://visualstudiogallery.msdn.microsoft.com/a1166718-a2d9-4a48-a5fd-504ff4ad1b65 新加特性: New Vis ...

  4. TCP与UDP传输协议

    目录结构: contents structure [-] 1 TCP协议和UDP协议的比较 1.1 TCP协议 TCP的全称是Transmission Control Protocol (传输控制协议 ...

  5. Java第12章笔记

    如何定义 Java 中的方法 所谓方法,就是用来解决一类问题的代码的有序组合,是一个功能模块. 一般情况下,定义一个方法的语法是: 其中: //方法名为骆驼命名法 1. 访问修饰符:方法允许被访问的权 ...

  6. Java关键字解释及作用

    JAVA 关键字及其作用解释 1. 访问控制 1) private 私有的 private 关键字是访问控制修饰符,可以应用于类.方法或字段(在类中声明的变量). 只能在声明 private(内部)类 ...

  7. 开发简单的JavaWeb项目

    一.配置相关环境 下载配置JDK,eclipse,Tomcat服务器,Mysql数据库,Navicat for MySQL(数据库可视化工具) 如果你已经做好各个环境的配置,eclipse与Tomca ...

  8. dj 分页器组件

    django内置的分页器组件,能够帮我们实现对查询的数据进行自动分页,并返回分页对象 from django.core.paginator import Paginator, EmptyPage Pa ...

  9. 获取当前操作的IFrame对象的方法

    分两种情况:第一种:获取JS函数在父页面上,如下 function getIframeByElement(element){ var iframe; $("iframe").eac ...

  10. chmod用法

    以下是chmod的详细用法:chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设 ...