Windows有文字转语音功能,C#提供了调用的类库Interop.SpeechLib.dll
使用方法很简单,在你的项目中添加Interop.SpeechLib.dll引用,在类中引用:
using SpeechLib;
**************************************************************************************************************
定义一个全局的变量
private static SpVoice m_spVoice;
实现语音播放(文本播放)
public bool VoicePlayback (string PlayText)
{
try
{
m_spVoice = new SpVoice();
m_spVoice.Rate = 0;//语速
m_spVoice.Volume = 100;//音量0-100
m_spVoice.Speak(PlayText, SpeechVoiceSpeakFlags.SVSFlagsAsync);//开始
return true;
}
catch (Exception e)
{
Console.Write(e);
return false;
}
}
实现语音播放暂停
public bool VoicePlaybackPause()
{
try
{
m_spVoice.Pause();//暂停
return true;
}
catch (Exception e)
{
Console.Write(e);
return false;
}
}
实现语音播放继续
public bool VoicePlaybackResume()
{
try
{
m_spVoice.Resume();//继续
return true;
}
catch (Exception e)
{
Console.Write(e);
return false;
}
}
实现语音播放停止
public bool VoicePlaybackStop()
{
try
{
m_spVoice.Speak(string.Empty,SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);//停止
return true;
}
catch (Exception e)
{
Console.Write(e);
return false;
}
}
**************************************************************************************************************