web个性化,web版tts语音合成技术,cs架构语音合成技术,web时时推送技术,异步调用多线程技术
2016-02-17 15:23
731 查看
我本人亲自实现了一个web版本的tts语音合成技术,和cs版本的tts语音合成技术
这个是后台源码
/// <summary>
/// 发送HTTP请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="param">请求的参数</param>
/// <returns>请求结果</returns>
public string request(string url, string param)
{
url = "http://apis.baidu.com/apistore/baidutts/tts";
param = "text=heloyuzhilinctp=1&per=0";
string strURL = url + '?' + param;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "GET";
// 添加header
request.Headers.Add("apikey", "c5682670452c7aeee370ee1b09e24e79");
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate + "\r\n";
}
return strValue;
}
web版本的tts语音合成技术,我采用的方法是直接调用百度的接口,直接返回一个base64格式的编码,直接播放就可以了,
cs版本我就不过多的介绍了,网上都能找得到
public static void systemspeech(object word, int kanumber)
{
try
{
SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
SpeechStreamFileMode spFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream spFileStream = new SpFileStream();
SpAudioFormat SpAudio = new DotNetSpeech.SpAudioFormat();
SpAudio.Type = SpeechAudioFormatType.SAFT48kHz16BitStereo;
var XmlFilePath = Guid.NewGuid().ToString();
spFileStream.Format = SpAudio;
//XmlFilePath = System.Windows.Forms.Application.StartupPath + "/video/" + XmlFilePath + ".wav";System.AppDomain.CurrentDomain.BaseDirectory + "Style\\Images";
// XmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "Style\\voice\\" + Voiceprompt + ".wav";
XmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "Style\\voice\\Voicepromptr.wav";
//XmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + ".\\voice\\Voiceprompt.wav";
spFileStream.Open(XmlFilePath, spFileMode, false);
voice.AudioOutputStream = spFileStream;
voice.Speak(word.ToString(), spFlags);
voice.WaitUntilDone(Timeout.Infinite);
spFileStream.Close();
}
catch
{
}
}
//读取文件
/// <summary>
/// 输出WAV
/// </summary>
/// <param name="path">保存路径</param>
/// <param name="str">要转换的文本内容</param>
/// <returns></returns>
public bool WreiteToWAV(string path, string str, SpeechAudioFormatType SpAudioType)
{
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpVoice voice = new SpVoice();
SpFileStream SpFileStream = new SpFileStream();
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpAudioFormat SpAudio = new DotNetSpeech.SpAudioFormat();
SpAudio.Type = SpAudioType;
SpFileStream.Format = SpAudio;
SpFileStream.Open(path, SpFileMode, false);
voice.AudioOutputStream = SpFileStream;
voice.Speak(str, SpFlags);
// voice.AudioOutputStream.Format.Type = SpeechAudioFormatType.SAFT48kHz16BitStereo;
voice.WaitUntilDone(Timeout.Infinite);
SpFileStream.Close();
return File.Exists(path);
}
public void read_Word(object word)
{
try
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice Voice = new SpVoice();
Voice.Voice = Voice.GetVoices(string.Empty, string.Empty).Item(2);
//ISpeechObjectTokens sb = Voice.GetVoices("", "");
//foreach (ISpeechObjectToken so in sb)
// Voice.Voice = Voice.GetVoices("name=Microsoft Lili", "").Item(0);
Voice.Rate = 4;
Voice.Volume = 80;
Voice.Speak(word.ToString(), SpFlags);
}
catch (System.Exception ec)
{
MessageBox.Show(ec.ToString(), "SpeechApp", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
//syth.SelectVoice("Microsoft Server Speech Text to Speech Voice (zh-CN, HuiHui)");
////syth.SelectVoice("Microsoft Anna");
//string fileFullPath = @"E:\项目备份\LCMS_Comac\Pelesys.LCMS.Web\CBTUnitFiles\Cu02161\MediaFiles\123.wav"; // TODO: Initialize to an appropriate value
//syth.SetOutputToWaveFile(fileFullPath);
//syth.Rate = 0;
//syth.Speak("sdfwod项目备份sdfsdf");
}
}
高并发高性能, frid 时时读取最新数据并推送到html5页面或者pc端页面 web页面推送技术源码
前台页面源码
<script type="text/javascript">
$(function () {
(function longPolling() {
$.ajax({
url: "/WebSocket/indexstring",
data: { "timed": new Date().getTime() },
dataType: "text",
cache: false, //无缓存
timeout: 5000,
error: function (XMLHttpRequest, textStatus, errorThrown) {
$("#state").append("[state: " + textStatus + ", error: " + errorThrown + " ]<br/>");
if (textStatus == "timeout") { // 请求超时
longPolling(); // 递归调用
// 其他错误,如网络错误等
} else {
longPolling();
}
},
success: function (data, textStatus) {
$("#state").append("[state: " + textStatus + ", data: { " + data + "} ]<br/>");
if (textStatus == "success") { // 请求成功
longPolling();
}
}
});
})();
});
</script>
后台源码:
/*************/
//LongPolling Action 1 - 处理客户端发起的请求
public void LongPollingAsync()
{
//计时器,5秒种触发一次Elapsed事件
System.Timers.Timer timer = new System.Timers.Timer(2000);
//告诉ASP.NET接下来将进行一个异步操作
AsyncManager.OutstandingOperations.Increment();
//订阅计时器的Elapsed事件
timer.Elapsed += (sender, e) =>
{
//保存将要传递给LongPollingCompleted的参数
AsyncManager.Parameters["now"] = e.SignalTime;
//告诉ASP.NET异步操作已完成,进行LongPollingCompleted方法的调用
AsyncManager.OutstandingOperations.Decrement();
};
//启动计时器
timer.Start();
}
不是最新代码,最新代码融合了异步调用,回调函数,socket通讯
webttsqq交流群:455605710
这个是后台源码
/// <summary>
/// 发送HTTP请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="param">请求的参数</param>
/// <returns>请求结果</returns>
public string request(string url, string param)
{
url = "http://apis.baidu.com/apistore/baidutts/tts";
param = "text=heloyuzhilinctp=1&per=0";
string strURL = url + '?' + param;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "GET";
// 添加header
request.Headers.Add("apikey", "c5682670452c7aeee370ee1b09e24e79");
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate + "\r\n";
}
return strValue;
}
web版本的tts语音合成技术,我采用的方法是直接调用百度的接口,直接返回一个base64格式的编码,直接播放就可以了,
cs版本我就不过多的介绍了,网上都能找得到
public static void systemspeech(object word, int kanumber)
{
try
{
SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
SpeechStreamFileMode spFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream spFileStream = new SpFileStream();
SpAudioFormat SpAudio = new DotNetSpeech.SpAudioFormat();
SpAudio.Type = SpeechAudioFormatType.SAFT48kHz16BitStereo;
var XmlFilePath = Guid.NewGuid().ToString();
spFileStream.Format = SpAudio;
//XmlFilePath = System.Windows.Forms.Application.StartupPath + "/video/" + XmlFilePath + ".wav";System.AppDomain.CurrentDomain.BaseDirectory + "Style\\Images";
// XmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "Style\\voice\\" + Voiceprompt + ".wav";
XmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "Style\\voice\\Voicepromptr.wav";
//XmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + ".\\voice\\Voiceprompt.wav";
spFileStream.Open(XmlFilePath, spFileMode, false);
voice.AudioOutputStream = spFileStream;
voice.Speak(word.ToString(), spFlags);
voice.WaitUntilDone(Timeout.Infinite);
spFileStream.Close();
}
catch
{
}
}
//读取文件
/// <summary>
/// 输出WAV
/// </summary>
/// <param name="path">保存路径</param>
/// <param name="str">要转换的文本内容</param>
/// <returns></returns>
public bool WreiteToWAV(string path, string str, SpeechAudioFormatType SpAudioType)
{
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpVoice voice = new SpVoice();
SpFileStream SpFileStream = new SpFileStream();
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpAudioFormat SpAudio = new DotNetSpeech.SpAudioFormat();
SpAudio.Type = SpAudioType;
SpFileStream.Format = SpAudio;
SpFileStream.Open(path, SpFileMode, false);
voice.AudioOutputStream = SpFileStream;
voice.Speak(str, SpFlags);
// voice.AudioOutputStream.Format.Type = SpeechAudioFormatType.SAFT48kHz16BitStereo;
voice.WaitUntilDone(Timeout.Infinite);
SpFileStream.Close();
return File.Exists(path);
}
public void read_Word(object word)
{
try
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice Voice = new SpVoice();
Voice.Voice = Voice.GetVoices(string.Empty, string.Empty).Item(2);
//ISpeechObjectTokens sb = Voice.GetVoices("", "");
//foreach (ISpeechObjectToken so in sb)
// Voice.Voice = Voice.GetVoices("name=Microsoft Lili", "").Item(0);
Voice.Rate = 4;
Voice.Volume = 80;
Voice.Speak(word.ToString(), SpFlags);
}
catch (System.Exception ec)
{
MessageBox.Show(ec.ToString(), "SpeechApp", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
//syth.SelectVoice("Microsoft Server Speech Text to Speech Voice (zh-CN, HuiHui)");
////syth.SelectVoice("Microsoft Anna");
//string fileFullPath = @"E:\项目备份\LCMS_Comac\Pelesys.LCMS.Web\CBTUnitFiles\Cu02161\MediaFiles\123.wav"; // TODO: Initialize to an appropriate value
//syth.SetOutputToWaveFile(fileFullPath);
//syth.Rate = 0;
//syth.Speak("sdfwod项目备份sdfsdf");
}
}
高并发高性能, frid 时时读取最新数据并推送到html5页面或者pc端页面 web页面推送技术源码
前台页面源码
<script type="text/javascript">
$(function () {
(function longPolling() {
$.ajax({
url: "/WebSocket/indexstring",
data: { "timed": new Date().getTime() },
dataType: "text",
cache: false, //无缓存
timeout: 5000,
error: function (XMLHttpRequest, textStatus, errorThrown) {
$("#state").append("[state: " + textStatus + ", error: " + errorThrown + " ]<br/>");
if (textStatus == "timeout") { // 请求超时
longPolling(); // 递归调用
// 其他错误,如网络错误等
} else {
longPolling();
}
},
success: function (data, textStatus) {
$("#state").append("[state: " + textStatus + ", data: { " + data + "} ]<br/>");
if (textStatus == "success") { // 请求成功
longPolling();
}
}
});
})();
});
</script>
后台源码:
/*************/
//LongPolling Action 1 - 处理客户端发起的请求
public void LongPollingAsync()
{
//计时器,5秒种触发一次Elapsed事件
System.Timers.Timer timer = new System.Timers.Timer(2000);
//告诉ASP.NET接下来将进行一个异步操作
AsyncManager.OutstandingOperations.Increment();
//订阅计时器的Elapsed事件
timer.Elapsed += (sender, e) =>
{
//保存将要传递给LongPollingCompleted的参数
AsyncManager.Parameters["now"] = e.SignalTime;
//告诉ASP.NET异步操作已完成,进行LongPollingCompleted方法的调用
AsyncManager.OutstandingOperations.Decrement();
};
//启动计时器
timer.Start();
}
不是最新代码,最新代码融合了异步调用,回调函数,socket通讯
webttsqq交流群:455605710
相关文章推荐
- 三层基本架构方向
- 一个架构师谈什么是架构以及怎么成为一个架构师
- 我的架构经验小结(四)-- 实战中演化的三层架构
- 架构之路(二):性能
- 我的架构经验小结(三)-- 深入三层架构
- 我的架构经验小结(二)-- 关于三层架构
- 我的架构经验小结(一)-- 常用的架构模型
- CSS架构
- 如何快速拥有一个小网站
- (转载) 《火星救援》中你应该知道的5个高可用系统故障恢复原则
- 小故事:架构师需要做什么?
- 小米网技术架构变迁实践
- 一些有用的网站。
- 基于Flume的美团日志收集系统(一)架构和设计
- 架构设计:负载均衡层设计方案(1)——负载场景和解决方式
- 在Android应用中使用Clean架构
- 秒杀系统架构分析与实战
- 钓鱼网站钓取大量QQ帐号密码被泄露钓鱼受害者每天过万(某先前被腾讯忽略的报告)
- 系统分层架构设计参考
- 架构之路(一):目标