c# speech 文本转语言
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 文本转语言的更多相关文章
- tn文本分析语言(二) 基本语法
tn是desert和tan共同开发的一种用于匹配,转写和抽取文本的语言.解释器使用Python实现,代码不超过1000行. 本文主要介绍tn的基本语法.高级内容可以参考其他篇章.使用这样的语法,是为了 ...
- tn文本分析语言(四) 实现自然语言计算器
tn是desert和tan共同开发的一种用于匹配,转写和抽取文本的语言.解释器使用Python实现,代码不超过1000行. github地址:https://github.com/ferventdes ...
- 重磅开源:TN文本分析语言
tn是desert(沙漠之鹰)和tan共同开发的一种用于匹配,转写和抽取文本的语言(DSL).并为其开发和优化了专用的编译器.基于递归下降方法和正则表达式,能解析自然文本并转换为树和字典,识别时间,地 ...
- [Markdown]纯文本标记语言MarkdowPad2--MD语法知识
##1.标题 代码 注:# 后面保持空格 # h1 ## h2 ### h3 #### h4 ##### h5 ###### h6 ####### h7 // 错误代码 ######## h8 // ...
- Browser Security-超文本标记语言(HTML)
Browser Security-超文本标记语言(HTML) 瞌睡龙 · 2013/06/19 18:55 重要的4个规则: 1 &符号不应该出现在HTML的大部分节点中. 2 尖括号< ...
- [译]HAL-超文本应用语言
[译]HAL-超文本应用语言 精益超媒体类型 总结 HAL 是一种简单的格式,它提供了一种一致且简便的方法在 API 的资源之间进行超链接. 采用 HAL 将使您的 API 易于探索,并且其文档很容易 ...
- tn文本分析语言(三):高级语法
标签(空格分隔): 未分类 高级操作 1.脚本表达式 用双引号包含的脚本被称为脚本表达式,目前支持嵌入Python. 脚本表达式只能在顺序表达式中使用.代码可以在三个位置存在: |位置|功能|例子| ...
- CoffeeScript及相关文本标记语言
粗步看了下CoffeeScript(简称cs),发现cs这玩意还是有些问题,当然最大的问题之一是缺乏称手的工具.要是能放VS里编译调试当然好.但是转来转去的,真不如直接多敲几个JS字符串. 问题之二就 ...
- 轻量级文本标记语言-Markdown
Markdown简介 接触过github的都知道,在发布项目的时候可以建立一个说明文件README.md,这个md文件就是Markdown文本编辑语言的文件. Markdown 是一种轻量级标记语言, ...
随机推荐
- webpack打包vue项目之后生成的dist文件该怎么启动运行
亲测,webpack打包vue项目之后生成的dist文件可以部署到 express 服务器上运行. 我的vue项目结构如下: 1. 进入该vue项目目录,打开git bash,执行:npm run b ...
- springcloud 入门 3 (服务之间的调用)
服务调用: 指的是注册到服务端上的客户端之间数据的相互调用问题:服务与服务的通讯是基于http restful的 服务直接调用主要有两种实现:ribbon 和 feign ribbon是实现负载均衡 ...
- AOP编程报错Xlint:invalidAbsoluteTypeName
@Component@Aspectpublic class DingdingAspect { private Logger logger = LoggerFactory.getLogger(this. ...
- Problem4-Project Euler
Largest palindrome product A palindromic number reads the same both ways. The largest palindrome m ...
- Prometheus Node_exporter 详解
Basic CPU / Mem / Disk Info https://www.cnblogs.com/qianyuliang/p/10479515.html Basic CPU / Mem / Di ...
- C#安全加密类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.S ...
- SQL Server 如何设置数据库的默认初始大小和自动增长大小
我们在SQL Server中新建数据库的时候,可以选择数据库文件及日志文件的初始大小.自动增长大小和最大大小,如下图所示: 可以通过设置更改数据库初始大小.自动增长大小和最大大小: 但是其实在SQL ...
- 使用MyEclipse建立working set
1.用eclipse或者MyEclipse开发久了后,会有很多的项目,就算关闭了还会有很多,这是需要建立一个working set,相当在工作区中建立项目文件夹分类放自己做过的一些项目. 如下图: ...
- web导出excel文件的几种方法
总的来说,两种方法:服务器端生成和浏览器端生成. 服务器端生成就是:根据用户请求,获取相应的数据,使用poi/jxl, jacob/jawin+excel,或是用数据拼html的table或是cvs纯 ...
- Win7命令终端基础配色指南
微软对控制台字体的元数据有严格的限制,https://support.microsoft.com/zh-cn/help/247815/necessary-criteria-for-fonts-to-b ...