如何在C#.net中使用SAPI4 [英] How to use SAPI4 in C#.net

查看:145
本文介绍了如何在C#.net中使用SAPI4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个文本语音转换应用程序,我希望能够支持SAPI版本4和SAPI5.

我使用的是.NET 2.0兼容版本,请使用COM互操作(通过自动生成的SpeechLib.dll).
这样我就只能获得SAPI5版本的声音,如何获得SAPI4版本的声音.

我还需要使用/做些什么来利用SAPI4?

预先感谢您的帮助!

Hello,

I have a text-to-speech application and I want to be able to support SAPI version 4 as well as SAPI5.

I am using .NET 2.0 compatible, use COM interop (via the auto-generated SpeechLib.dll).
With this I am able to get only SAPI5 version voices, How to get SAPI4 version voices.

What would I need to use/do to make use of SAPI4 as well?

Thanks in advance for any help!

推荐答案

只需确定已安装的版本,然后在代码中进行检查,以确定是否应使用某些功能. .

Just determine the version that''s installed, and put checks in your code to determine whether or not certain functions should be used.

public interface ISapiFunctions
{
    public void Function1();
    public void Function2();
}

public class SapiBase : ISapiFunctions
{
    public virtual void Function1()
    {
        // do nothing
    }

    public virtual void Function2()
    {
        // do nothing
    }
}

public class Sapi4 : SapiBase
{
    public override void Function1()
    {
        // do something 
    }
}

public void Sapi5 : SapiBase
{
    public override void Function1()
    {
        // do something
    }

    public override void Function2()
    {
        // do something
    }
}



在上面的代码中,如果实例化sapi4类(因为sapi v4当前已安装),它将支持Function1中的功能,但不支持Function2中的功能(导致基类) ''不执行任何复制).如果实例化sapi5,则所有功能都将可用,因为sapi5可以执行所需的任务.最终结果是,您可以从实例化任何一个类的代码中调用Function1Function2,而不必担心当前安装的sapi版本是否支持它.



In the code above, if you instantiated the sapi4 class (because sapi v4 is currently what''s installed), it would support the functionality in Function1, but NOT the functionality in Function2 (resulting in the base class'' do-nothing copy to be executed). If you instantiate sapi5, all functionality would be available because sapi5 can perform the desired task. The end result would be that you could call Function1 AND Function2 from the code that instantiates either of the classes without worrying if the currently installed sapi version even supports it.


这篇关于如何在C#.net中使用SAPI4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆