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 ...
随机推荐
- 使用crf++
在example文件夹下存在4个使用crf的实例 1.在命令行执行 进入路径:./example/seg 执行:sh exec.sh 2. 在python中执行 进入路径:./python 执行:(1 ...
- [C#.NET]最简单的实现文本框的水印效果
C#项目开发中在设计登录界面时,经常会遇到TextBox的水印提示要求.这里简单描述一下项目在实现水印提示的过程设置.如下图图1所示. 图1 窗体布局 一.窗体布局(如图1所示) 1. 在窗体中放 ...
- spring 学习 一 spring 介绍
Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为 J2EE 应用程序开发提供集成的框架. Spring ...
- java学习第六周
这是暑假学习的第六周,在这周我练习了老师给的例题,还是有一些地方看不懂,这周我对那些不懂的地方用看视频来进行解答,以及进行第二次复习. 下周我会对Java进行更加详细的复习,做好笔记,在LeetCod ...
- Tkinter添加图片
Tkinter添加图片的方式,与Java相似都是利用label标签来完成的: 一.默认的是gif的格式,注意将png后缀名修改为gif还是无法使用,文件格式依然错误. photo = PhotoIma ...
- Mac 更换桌面背景崩溃(闪退)
更新完系统后就会出现这种情况,,其实就是用户偏好文件出了问题. 1. 在终端输入 cd /Users/YourUserName/Library/Preferences //进入文件夹 rm com.a ...
- 2018.12.12 codeforces 935D. Fafa and Ancient Alphabet(概率dp)
传送门 概率dp水题. 题意简述:给你数字表的大小和两个数列,数列中为0的数表示不确定,不为0的表示确定的,求第一个数列字典序比第二个数列大的概率. fif_ifi表示第i ni~ ni n位第一个 ...
- vue 开发系列(七) 路由配置
概要 用 Vue.js + vue-router 创建单页应用,是非常简单的.使用 Vue.js ,我们已经可以通过组合组件来组成应用程序,当你要把 vue-router 添加进来,我们需要做的是,将 ...
- new命令简化的内部流程
构造函数返回对象的一些问题: function fn(name,age){ this.name = name; this.age = age; //return 23; 忽略数字,直接返回原有对象 / ...
- 安卓修改开机logo和开机动画的方法
第一种和第二种方法亲测可用,安卓版本是4.2和安卓5.1均可.第二种方法待验证 以下三种方法 Android 开机其实总共会出现3个画面: 1.第一个就是 linux 系统启动,出现Linux小企鹅画 ...