• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

C#语音朗读文本 — TTS的实现

C#语音朗读文本 — TTS的实现

从 .NET 3.0开始,.NET Framework里,提供了托管的Speech API 调用方法,这样,就非常流畅了。而不必拘泥于繁琐的非托管COM调用了。

.Net 3.0 的实现代码:

using System.Speech.Synthesis;

SpeechSynthesizer synth = new SpeechSynthesizer();

synth.Speak("Hello, world! 你好么?,闫磊欢迎你");

synth.Dispose();

///=========================闫磊 write============================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Speech.Synthesis;
using System.Windows.Forms;


namespace cbjyq
{
public class MySpeech
{
private static string mystr;
private static void pSpeech()
{
SpeechSynthesizer synth = new SpeechSynthesizer();

synth.Speak(mystr);

synth.Dispose();
}
public static void MyMessageBox(string str)
{
Speech(str);
MessageBox.Show(str);
}
public static void Speech(string str)
{
try
{
mystr = str;
ThreadStart threadStart = new ThreadStart(pSpeech);

Thread thread = new Thread(threadStart);

thread.Start();
}
catch
{ }


}

}
}

posted on 2016-11-14 11:12  gisai  阅读(465)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3