<Window x:Class="Synthesizer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Synthesizer"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Window.Title>Synthesizer</Window.Title>
<Window.Resources>
<local:DoubleToStringConverter x:Key="converter" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Name="PreviewTextBox" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5 5 5 5" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"/>
<ComboBox Name="VoiceComboBox" Grid.Row="1" Grid.Column="0" Width="320" Height="30" Margin="5 5 5 5" Grid.ColumnSpan="2"/>
<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"/>
<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}}"/>
<Button Name="SaveButton" Grid.Row="3" Grid.Column="1" Width="80" Height="45" Margin="5 5 5 5" Content="Save" Click="SaveButtonClick" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.Media.SpeechSynthesis;
using System.IO; namespace Synthesizer
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
foreach (var voice in SpeechSynthesizer.AllVoices.OrderBy(voice => voice.Language))
{
VoiceComboBox.Items.Add(new ComboBoxItem() { Tag=voice,Content=string.Format("{0} ({1})",voice.DisplayName, voice.Language)});
}
if (VoiceComboBox.Items.Count > )
{
VoiceComboBox.SelectedIndex = ;
}
} [STAThread]
public static void Main(string[] args)
{
new MainWindow().ShowDialog();
} private async void SaveButtonClick(object sender, RoutedEventArgs e)
{
var dialog = new SaveFileDialog()
{
Filter = "WAV File|*.wav"
};
if (dialog.ShowDialog() != true)
{
return;
}
var synthesizer = new SpeechSynthesizer()
{
Voice = (VoiceComboBox.SelectedItem as ComboBoxItem).Tag as VoiceInformation
};
synthesizer.Options.SpeakingRate = SpeedSlider.Value;
var stream = await synthesizer.SynthesizeTextToStreamAsync(PreviewTextBox.Text);
using (var file = new FileStream(dialog.FileName, FileMode.Create))
{
stream.AsStream().CopyTo(file);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data; namespace Synthesizer
{
[ValueConversion(typeof(double), typeof(string))]
class DoubleToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value as double?)?.ToString("F2");
} public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return double.Parse(value as string);
}
}
}

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. 【Linux】DNS基础(一)

    DNS基础 DNS 是计算机域名系统 (Domain Name System 或Domain Name Service) 的缩写,域名服务器是进行域名(domain name)和与之相对应的IP地址 ...

  2. linux_域名映射

    vi /etc/hosts在最后加上ip及映射的域名 192.168.229.111 node001 192.168.229.112 node002 192.168.229.113 node003

  3. Linux+Apache+Mysql+PHP优化技巧

    LAMP 平台由四个组件组成,呈分层结构.每一层都提供了整个软件栈的一个关键部分:Linux.Apache.MySQL.PHP. LAMP这个词的由来最早始于德国杂志“c't Magazine”,Mi ...

  4. 2018.10.31 NOIP模拟 一些情报(倍增)

    传送门 题目并不难(想) 其实就是用倍增维护几个树上信息. 也就这么几个: 子树内最长链及其后继点. 子树内次长链及其后继点. 子树内第三场链(也就是dzyodzyodzyo口中鬼畜的次次长链) 点i ...

  5. 1.2OpenCV如何扫描图像,利用查找表和计时

    查找表 颜色缩减法:如果矩阵元素存储的是单通道像素,使用C或C++的无符号字符类型,那么像素可有256个不同值. 但若是三通道图像,这种存储格式的颜色数就太多了(确切地说,有一千六百多万种).用如此之 ...

  6. HTML5 通过 FileReader 实现文件上传

    概述 在页面中上传时,之前一般都是需要使用form表单进行上传.html5 中提供了FileReader 可以将文件转换成Base64编码字符串,因此就可以直接使用 AJAX实现文件上传. 实现代码 ...

  7. Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)

    https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...

  8. C#系列之{流和序列化}

    不论何种类型的文件都可以表示为一个字节数组.(Byte[]) 一.文件复制 (示例) 首先建立一个类似管道的东西将文件和内存中的程序连接,并将文件按字节发送.为了保存接收到的文件字节,需要创建一个字节 ...

  9. 个人理解的int数组和char数组

    char数组中不论是一维还是二维的,在程序执行时每一块的分离依据都是以提供的起始地址到'\0'为一个处理的字符串.所以关于char[]的函数都是只提供相应起始地址作为形参就可以. char[]互相交换 ...

  10. MATLAB相关快捷键以及常用函数

    MATLAB快捷键大全 F1帮助 F2改名F3搜索 F4地址 F5刷新 F6切换 F10菜单 CTRL+A全选 CTRL+C复制 CTRL+X剪切 CTRL+V粘贴 CTRL+Z撤消 CTRL+O打开 ...