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. OSGI企业应用开发(五)使用Blueprint整合Spring框架(二)

    上篇文章中,我们开发了一个自定义的Bundle,接着从网络中下载到Spring和Blueprint的Bundle,然后复制到DynamicRuntime项目下. 需要注意的是,这些Bundle并不能在 ...

  2. sql server 大批数据插入时,时间过长的问题

    private const string con = "server=192.168.30.36;database=test;user=sa;pwd=123456"; static ...

  3. MBTIles实现

    MBTIles实现 3.1 Compliant(符合) python: raster2mb (write) python: mbutil (read/write) python: landez (wr ...

  4. OpenCV多版本管理

    OpenCV在Ubuntu下经常会安装多个版本,比如默认版本,自己安装的,ros安装的等等.有时候需要给程序指定某个OpenCV版本,网上有一些方法,但还是会遇到很多问题. 这里提供一种选择,即指定O ...

  5. python 以单例模式封装logging相关api实现日志打印类

    python 以单例模式封装logging相关api实现日志打印类   by:授客QQ:1033553122 测试环境: Python版本:Python 2.7   实现功能: 支持自由配置,如下lo ...

  6. 标准标签、<jsp:include>、<jsp:forward>

    使用方法 标准标签在jsp页面直接编写即可,因为标准标签是JSP规范提供的,所有容器都支持. 被替代性 标准标签的许多功能都可以被JSTL与EL表达式语言所替代. 作用 标准标签可协助编写JSP时减少 ...

  7. [SSRS / RV] (.rdlc报表)冻结表头,固定行列标题

    转自:https://blog.csdn.net/dietime1943/article/details/72846171?utm_source=blogxgwz9 Reporting Service ...

  8. MAYA逼真手枪制作视频教程 中文字幕

    下载地址 更多中文字幕教程请关注微镜映画网,有各类CG教程提供

  9. ssh免秘钥配置

    1.要求:两台相同的系统,这里设置server1控制server2的服务器 2.先在两台服务器上都安装好ssh 输入命令下载: yum install -y openssh-clients opens ...

  10. Innodb页面存储结构-2

    上一篇<Innodb页面存储结构-1>介绍了Innodb页面存储的总体结构,本文会介绍页面的详细内容,主要包括页头.页尾和记录的详细格式. 学习数据结构时都说程序等于数据结构+算法,而在i ...