.NET 3.5 C# 调用TTS 说中文

从 .NET 3.0开始,.NET Framework里,提供了托管的Speech API 调用方法,这样,就非常流畅了。而不必拘泥于繁琐的非托管COM调用了。
 系统->高级->环境变量->用户变量

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());
            }

        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值