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 是一种轻量级标记语言, ...
随机推荐
- IIS 下调用证书出现异常解决方案 (C#)
程序发布前,跑在vs上是没问题的,当发布后,程序就报错了.通过系统日志找到了错误所在:证书调用时出现了异常.原因是:在IIS上调用证书是需要配置的,具体配置如下: 一. 确保证书已安装 1. 点击 [ ...
- linux下安装jenkins实现自动化部署
安装 开始 1.安装之前,必须先安装JDK 可以参考 http://www.cnblogs.com/ericli-ericli/p/7070874.html 2.使用相关命令: wget -q -O ...
- Ajax如何设置cookie
普通的Ajax请求很遗憾不能返回服务器端设置的cookie 如何实现不刷新页面返回服务器设置的Cookie呢? 可以使用<script>或者<image>的src属性发起一个请 ...
- 几个python函数
迭代器 fun函数 过滤作用 s=['a', 'b', 'c'] def fun1(s): if s!='a': return s ret filter(fun1, str) print(ret) ...
- SVN switch 用法总结
一直知道SVN有个switch命令,但是对它的介绍教程却很少,大多是生硬的svn帮助文档里的文字,从而一直不怎么会用.今天看了这篇文章,突觉豁然开朗,整理下来以备查阅. 使用SVN,自然是需要与别人合 ...
- OneASP 安全公开课,深圳站, Come Here, Feel Safe!
在这个世界上,一共有两种公司:一种被「黑」过,另一种,不知道自己被「黑」过. 在安全攻击频发的今天: 如何构建完善的安全防护壁垒? 如何借助威胁情报改善安全态势? 如何检测新形式下的漏洞? 答案,就在 ...
- python 中* 和**的作用
先举个 ** 使用的例子: data = {"a": 1, "b": 2} def foo(**kwargs): print kwargs foo(a=1, b ...
- 负载均衡(Load Balancing)学习笔记(一)
概述 在分布式系统中,负载均衡(Load Balancing)是一种将任务分派到多个服务端进程的方法.例如,将一个HTTP请求派发到实际的Web服务器中执行的过程就涉及负载均衡的实现.一个HTTP请求 ...
- 编写脚本-SQL SERVER 用户权限分配
USE [TXM];GOCREATE USER [WIN-JO\Administrator]FOR LOGIN [WIN-JO\Administrator];GOEXEC sp_addrole ...
- soapui 调用wsdl 步骤以及出现的问题
创建soap project 添加wsdl 地址(或者导入wsdl(后缀可以是xml或者wsdl)文件) 添加request 自动生成请求代码 参数放在in0 中 <soapenv:Envelo ...