系统->高级->环境变量->用户变量
SET PATH=C:\WINDOWS\Microsoft.NET\Framework\v3.5;%PATH%
运行 cmd
编译 csc.exe /r:System.Speech.dll /t:exe speak3.cs执行 speak3.exe hello 我是中国人
speak3.cs 如下:
using System; using System.Speech.Synthesis; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace Speak3 { class Program { static void Main(string[] args) { try { SpeechSynthesizer ss = new SpeechSynthesizer(); Regex re = new Regex("^[A-Za-z]+$"); for (int i = 0; i < args.Length; i++) { if (re.IsMatch(args[i])) { ss.SelectVoice("Microsoft Mary"); // english } else { ss.SelectVoice("Microsoft Simplified Chinese"); // 中文 } ss.Speak(args[i]); } ss.Dispose(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } } }