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 是一种轻量级标记语言, ...
随机推荐
- 免费的局域网协作办公方式—onlyoffice文档协作
局域网内想享受协作办公的乐趣,请移步到这里按照步骤部署.https://blog.csdn.net/hotqin888/article/details/79337881 它是免费开源的,经过作者的一些 ...
- JUnit手动设计测试方法以及与Randoop的自动生成测试的比较
手动设计测试 在已有的web project本地目录lib文件夹里导入两个jar文件(版本可不一样):junit-4.12.jar和hamcrest.jar 打开eclipse,导入项目,右击项目选择 ...
- Python tuple
元组其实跟列表差不多,也是存一组数,只不是它一旦创建,便不能再修改,所以又叫只读列表 语法 names = (a,b,c) 它只有2个方法,一个是count,一个是index. 当然也有可变元祖: 可 ...
- 为什么Sql Server的查询有时候第一次执行很慢,第二次,第三次执行就变快了
老外提问: Hi, I have an sql query which takes 8 seconds in the first run. The next run there after takes ...
- 报错:java.net.bindexception: address already in use: jvm_bind:8080
原因:8080端口被占用 这说明80端口(该端口是Tomcat的监听端口)已经被其他程序占用,先用命令提示符 " netstat -ano " 命令显示端口状态,再在结果中找到端口 ...
- linux常见问题解决
1.登录环境故障的原理及解决办法? -bash-4.1$ -bash-4.1$ cp /etc/skel/.bash* .
- [Errno 256] No more mirrors to try 解决方法
安装tree时遇到问题yum [Errno 256] No more mirrors to try 解决方法: 1.yum clean all 2.yum makecache 3.yum update ...
- .NET Core 获取配置文件appsettings.json 方法
using Abp.Extensions; using Microsoft.Extensions.Configuration; using System; using System.Collectio ...
- 解决Win10无法安装.Net Framework 3.5,错误代码0x800F081F
重新安装了一遍Win10,但是不知怎的无法安装.net framework 3.5,即便是下载离线安装包也没法用. 网上有人说需要使用win10的ISO文件,个人感觉太麻烦,在这里分享一个很方便的操作 ...
- jquery实现根据所选时间生成页面元素
最近做项目,碰见这样的一个需求 根据所选的时间动态生成值班安排,日期格式需要带星期,如: 代码如下: 1.首先放两个文本框,时间插件用的是My97DataPicker,再放一个table,简单设置一下 ...