使用 .NET 类库 System.Speech 进行语音播放

一、添加类库

1:选择引用-->程序集-->框架,找到System.Speech类库

 2:添加引用后,可以使用如下代码进行调试

 1  static void Main(string[] args)
 2         {
 3             SpeechSynthesizer ssh = new SpeechSynthesizer()
 4             {
 5                 //音量控制(0~100)
 6                 Volume = 100,
 7 
 8                 //语速控制(-10,10)
 9                 Rate=0,
10             };
11 
12             //选择语音播放人的性别与年龄
13             ssh.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child);
14 
15             //语音保存(执行需在语音播放之前)
16             ssh.SetOutputToWaveFile("1.wav");
17 
18             //语音输出(同步)
19             ssh.Speak("您好,欢迎语音转换功能.");
20 
21             //语音输出(异步)
22             ssh.SpeakAsync("大漠孤烟直,长河落日圆");
23 
24             Console.WriteLine("end");
25             Console.ReadKey();
26         }

猜你喜欢

转载自www.cnblogs.com/dongweian/p/13366554.html