using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Shapes;
using System.Speech;
using System.Speech.Synthesis;
using System.Threading; namespace VoiceTest
{
public partial class MainWind: Window
{
public MainWind()
{
InitializeComponent(); }
private SpeechSynthesizer synth = null;
/// <summary>
/// 返回一个SpeechSynthesizer对象
/// </summary>
/// <returns></returns>
private SpeechSynthesizer GetSpeechSynthesizerInstance()
{
if (synth == null)
{
synth = new SpeechSynthesizer();
}
return synth;
}
/// <summary>
/// 播放
/// </summary>
public void Play(string text)
{
Thread thread = new Thread(new ParameterizedThreadStart(SaveAudio));
thread.Start(text);
}
/// <summary>
/// 保存语音文件
/// </summary>
/// <param name="text"></param>
public void SaveAudio(object text)
{
speak(text);
string outputFolderPath = "D:\\voice";
if(! System.IO.Directory.Exists(outputFolderPath)){
System.IO.Directory.CreateDirectory(outputFolderPath);
}
synth = GetSpeechSynthesizerInstance();
string spText = text.ToString();
synth.Rate = -2;
synth.Volume = 100;
string filename = DateTime.Now.ToString("yyyyMMddHHmmss");
string strVoiceFile =System.IO.Path.Combine(outputFolderPath, filename + ".wav");
synth.SetOutputToWaveFile(strVoiceFile);
synth.Speak(spText);
synth.SetOutputToNull();
//调用语音转文字
//Thread threadVoice = new Thread(VoiceToText);
//threadVoice.Start(str);
}

public void speak(string speechSounds)
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice spVoice = new SpVoice();
spVoice.Rate = spVoice.Rate - 5;
if (spVoice.Volume < 100)
{
spVoice.Volume = spVoice.Volume + 10;
}

if (spVoice.Volume > 9)
{
spVoice.Volume = spVoice.Volume - 10;
}
spVoice.Speak(speechSounds, SpFlags);

}

        private void button1_Click(object sender, RoutedEventArgs e)
{
//Play("hello swimming, today we will learn how to swimming")
Play("你好!今天我们将学习如何提高游泳技巧!不用太费力气哦,haha!");
} }
}

  

参考:https://www.cnblogs.com/-maomao/p/6861447.html

c# speech 文本转语言的更多相关文章

  1. tn文本分析语言(二) 基本语法

    tn是desert和tan共同开发的一种用于匹配,转写和抽取文本的语言.解释器使用Python实现,代码不超过1000行. 本文主要介绍tn的基本语法.高级内容可以参考其他篇章.使用这样的语法,是为了 ...

  2. tn文本分析语言(四) 实现自然语言计算器

    tn是desert和tan共同开发的一种用于匹配,转写和抽取文本的语言.解释器使用Python实现,代码不超过1000行. github地址:https://github.com/ferventdes ...

  3. 重磅开源:TN文本分析语言

    tn是desert(沙漠之鹰)和tan共同开发的一种用于匹配,转写和抽取文本的语言(DSL).并为其开发和优化了专用的编译器.基于递归下降方法和正则表达式,能解析自然文本并转换为树和字典,识别时间,地 ...

  4. [Markdown]纯文本标记语言MarkdowPad2--MD语法知识

    ##1.标题 代码 注:# 后面保持空格 # h1 ## h2 ### h3 #### h4 ##### h5 ###### h6 ####### h7 // 错误代码 ######## h8 // ...

  5. Browser Security-超文本标记语言(HTML)

    Browser Security-超文本标记语言(HTML) 瞌睡龙 · 2013/06/19 18:55 重要的4个规则: 1 &符号不应该出现在HTML的大部分节点中. 2 尖括号< ...

  6. [译]HAL-超文本应用语言

    [译]HAL-超文本应用语言 精益超媒体类型 总结 HAL 是一种简单的格式,它提供了一种一致且简便的方法在 API 的资源之间进行超链接. 采用 HAL 将使您的 API 易于探索,并且其文档很容易 ...

  7. tn文本分析语言(三):高级语法

    标签(空格分隔): 未分类 高级操作 1.脚本表达式 用双引号包含的脚本被称为脚本表达式,目前支持嵌入Python. 脚本表达式只能在顺序表达式中使用.代码可以在三个位置存在: |位置|功能|例子| ...

  8. CoffeeScript及相关文本标记语言

    粗步看了下CoffeeScript(简称cs),发现cs这玩意还是有些问题,当然最大的问题之一是缺乏称手的工具.要是能放VS里编译调试当然好.但是转来转去的,真不如直接多敲几个JS字符串. 问题之二就 ...

  9. 轻量级文本标记语言-Markdown

    Markdown简介 接触过github的都知道,在发布项目的时候可以建立一个说明文件README.md,这个md文件就是Markdown文本编辑语言的文件. Markdown 是一种轻量级标记语言, ...

随机推荐

  1. Nginx的常用功能

    1.规范nginx的配置文件 在企业中我们的虚拟主机可能会很多,配置文件的内容也会有很多,这时候我们就可以规范一下我们的配置文件,把每个虚拟主机按照网站的域名或者是功能取名,放到统一的文件夹中,当然我 ...

  2. 【Python】定时调度

    from datetime import datetime from apscheduler.schedulers.blocking import BlockingScheduler def tick ...

  3. android编写测试类

    由于网上很多教程,我就不多说.在这里我就说说我遇到的问题. 在android studio编写单元测试类中,在androidTest包下编写了两个类,分别如下 import junit.framewo ...

  4. Json 操作

    Json简介: JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式.它基于 ECMAScript (欧洲计算机协会制定的js规范)的一个子集 ...

  5. Visual Studio 2010详细安装过程

    Visual Studio 2010在目前看来,应该是使用得比较多的一款微软的软件开发工具集合了,因为它具有以下优点:(1)启动速度快:在相同环境下,相比于Visual Studio 2015来说,2 ...

  6. RecyclerView嵌套TextView时显示文字不全的解决方法之一

    先描述一下这个小bug:简单的TextView嵌套RecyclerView作为itemView时,可能会在文本中出现布局覆盖的现象,itemView的布局其实很简单,就是一个RelativeLayou ...

  7. Windows 7 任务栏图标消失(变透明,仍然占有地方,但是点击无反应)的解决方法

    解决方案:清理资源管理器缓存(重启资源管理器) 1.打开程序管理器(ctrl+shift+esc) 2.在进程那里找到"explorer.exe",然后按结束进程 3.然后在文件( ...

  8. 使用C#获取Windows Phone手机的各种数据(转)

    转自:http://www.sum16.com/desinger/use-c-sharp-get-windows-phone-information.html 使用C#获取Windows Phone手 ...

  9. IE 8 下sharepoint 2013 难看的字体的解决方案

    将 corev15.css 中的有关"Segoe UI","Segoe",Tahoma,移除即可. 一共二处 C:\Program Files\Common F ...

  10. January 01st, 2018 Week 01st Monday

    Life's like a movie, write your own. Keep believing, keep pretending. 人生如同电影,书写自己的结局.持续相信,继续演出. Some ...