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
{ }
}
}
}
浙公网安备 33010602011771号