Speech Synthesis
<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的更多相关文章
- System.Speech.Synthesis 添加暂停、继续功能
为了方便调用暂停.继续的方法.要将speech的功能写成一个类.直接附上代码: using System; using System.Collections.Generic; using System ...
- HTML5语音合成Speech Synthesis API简介
by zhangxinxu from http://www.zhangxinxu.com/wordpress/?p=5865本文可全文转载,但需得到原作者书面许可,同时保留原作者和出处,摘要引流则随意 ...
- C#中的System.Speech命名空间初探
本程序是口算两位数乘法,随机生成两个两位数,用语音读出来.然后开启语音识别,接受用户输入,知道答案正确关闭语音识别.用户说答案时,可以说“再说一遍”重复题目. 关键是GrammarBuilder和Ch ...
- Speech两种使用方法
COM组件使用speech: public class Speach { private static Speach _Instance = null ; private SpeechLib.SpVo ...
- csharp: Speech
Speech SDK 5.1https://www.microsoft.com/en-us/download/details.aspx?id=10121 detects mobile devices ...
- 微软职位内部推荐-Senior Speech TTS
微软近期Open的职位: Job Description: Responsibilities Do you want to change the way the world interacts wit ...
- asp.net引用System.Speech实现语音提示
using System; using System.Speech.Synthesis; namespace testvoice { class Program { static void Main( ...
- C# 使用System.Speech 进行语音播报和识别
C# 使用System.Speech 进行语音播报和识别 using System.Speech.Synthesis; using System.Speech.Recognition; //语音识别 ...
- 必应语音API(Bing text to speech API)
前言 Link : Microsoft Speech API overview 通过这个链接,大致了解Bing speech API的语音识别和语音合成两部分, 这次是需要用到TTS,所以就直接看TT ...
随机推荐
- Java 读取HDFS文件系统
最近有个需求,计算用户画像. 系统大概有800W的用户量,算每个用户的一些数据. 数据量比较大,算用hive还是毫无压力的,但是写的oracle,在给出数据给前端,就比较难受了. 然后换了种解决方法: ...
- 2018.11.02 洛谷P2661 信息传递(拓扑排序+搜索)
传送门 按照题意模拟就行了. 先拓扑排序去掉不在环上面的点. 剩下的都是简单环了. 于是都dfsdfsdfs一遍求出最短的环就行. 代码: #include<bits/stdc++.h> ...
- php多表查询数据合并,避免foreach循环嵌套
$memberList = $member->getMemberList(); $members = []; if (is_array($memberList)) { foreach ($mem ...
- tp5内置验证规则
验证规则 描述 require 必须验证 alpha 是否为字母 alphaNum 是否为字母和数字 alphaDash 是否为字母.数字,下划线_及破折号- number 是否为数字 integer ...
- java常用设计模式十二:命令模式
一.概述 定义:命令(Command)模式又叫作动作(Action)模式或事务(Transaction)模式,是一种对象的行为模式.将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化:对 ...
- c语言struct和c++struct的区别
1.定义 c语言中struct是用户自定义数据类型(UDT),是一些变量的集合体:c++中struct是抽象数据类型(ADT),能给用户提供接口,能定义成员函数,能继承,能实现多态 2.成员权限设置 ...
- INtellJ IDEA 2017 创建Annotation注解类
1.建立一个文件夹 java ------->new ---->Package--->输入名字 2.New ---->java class --->如图修改红圈位置的下拉 ...
- IntellJ IDEA2017 springboot2.0.2中读取配置
IDEA 路径 src\main\resources\application.properties 配置文件名称为 application.properties 默认的位置在classpath根目录下 ...
- ArcGIS API 和GIServer
ArcGIS API 和GIServer 先后以ArcGIS Server(9.3)和GIServer(2.2)为服务端,以ArcGIS API for Flex(1.2).ArcGIS API f ...
- C#版ObjectId
近来在准备弄一个开源的HIS,但一周过去了几乎没有进度.就卡在ID如何生成.HIS的数据库压力大,如何多数据库支持,减轻压力一直想去实现.拿不准纯数字ID段还是GUID一类的文本ID.最终在mongo ...