2022-08-20 乐帮网
speech
在Windows中开发TTS主要是使用SpeechSynthesizer类,本篇编写了一个示例,使用的是.Net Framework4.0可在Windows XP以上系统中运行。其中XP上推荐安装 SpeechSDK51.exe ,在Win7及以上推荐安装一下Windows Microsoft Speech (Version 11)
分别参考我以前的文章:
https://lebang2020.cn/details/220819vt5alxue.html
https://lebang2020.cn/details/220819pngrhwh0.html
里面都包含语音包。
引入类库在.Net Framework4.0中我们可以直接添加添加引用,找到System.Speech.dll,如果是在较高版本下开发则可以 在NuGet中查找System.Speech加以引用 ,下面是开发中代码示例:
// Initialize a new instance of the SpeechSynthesizer.
SpeechSynthesizer synth = new SpeechSynthesizer();
// Configure the audio output. 这里取决于操作系统 是中文还是英文
synth.SetOutputToDefaultAudioDevice();
// Speak a string. 中文和英文不同
synth.Speak("This example demonstrates a basic use of Speech Synthesizer");
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
我们可以通过以下的方法来查看系统中安装的语音引擎
// Initialize a new instance of the SpeechSynthesizer.
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Output information about all of the installed voices.
Console.WriteLine("Installed voices -");
foreach (InstalledVoice voice in synth.GetInstalledVoices())
{
VoiceInfo info = voice.VoiceInfo;
string AudioFormats = "";
foreach (SpeechAudioFormatInfo fmt in info.SupportedAudioFormats)
{
AudioFormats += String.Format("{0}\n",
fmt.EncodingFormat.ToString());
}
Console.WriteLine(" Name: " + info.Name);
Console.WriteLine(" Culture: " + info.Culture);
Console.WriteLine(" Age: " + info.Age);
Console.WriteLine(" Gender: " + info.Gender);
Console.WriteLine(" Description: " + info.Description);
Console.WriteLine(" ID: " + info.Id);
Console.WriteLine(" Enabled: " + voice.Enabled);
if (info.SupportedAudioFormats.Count != 0)
{
Console.WriteLine( " Audio formats: " + AudioFormats);
}
else
{
Console.WriteLine(" No supported audio formats found");
}
string AdditionalInfo = "";
foreach (string key in info.AdditionalInfo.Keys)
{
AdditionalInfo += String.Format(" {0}: {1}\n", key, info.AdditionalInfo[key]);
}
Console.WriteLine(" Additional Info - " + AdditionalInfo);
Console.WriteLine();
}
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
使用以上代码编写一个示例程序可以直接下载,就是以下程序的源码
https://lebang2020.cn/details/220820lsmkf2ko.html
源码下载:链接:https://pan.baidu.com/s/1GgebVCOdUkNuWzSP869KlA
关注我的微信公众号
在公众号里留言交流
投稿邮箱:1052839972@qq.com
庭院深深深几许?杨柳堆烟,帘幕无重数。
玉勒雕鞍游冶处,楼高不见章台路。
雨横风狂三月暮。门掩黄昏,无计留春住。
泪眼问花花不语,乱红飞过秋千去。
如果感觉对您有帮助
欢迎向作者提供捐赠
这将是创作的最大动力