它看起来像我实例化这个SpeechAPI接口。这怎么可能? [英] It looks like I'm instantiating this SpeechAPI interface. How is that possible?

查看:204
本文介绍了它看起来像我实例化这个SpeechAPI接口。这怎么可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用Microsoft文本到文本语音功能。但我有一个问题,实际上并不直接。所以:



通常程序员在创建Interface时,将I作为接口名称的前缀,如IReadable,IEnumerator等。但是我遇到了一些让我震惊的东西。



在Microsoft Text Speech DLL中有这样的:SpVoice是接口(他们没有把我作为前缀的某些原因,我不知道为什么?)和SpVoiceClass。那么,你可能会问的问题是,这里:

  SpVoice speak = new SpVoice //我从SpVoice接口创建了一个对象
speak.Speak(Hello StackOverFlow); //它说话,说我写的是什么。

  SpVoiceClass speak = new SpVoiceClass(); 
speak.Speak(Hello Kowanichi); //它做同样的事情。

我没有得到的东西是怎么样的?



请一些人解释一下我为什么?



我真的很困惑,现在也许微软开发人员没有把我的前缀,因为这个原因,它可以实例化。



提前感谢。

src =http://www.pixelshack.us/images/dngpe9kzoq83obtiami.pngalt =alt text>

解决方案

EDIT :啊,我明白了。看看SpVoice的定义:

  [CoClass(typeof(SpVoiceClass))] 
public interface SpVoice:ISpeechVoice, _ISpeechVoiceEvents_Event
{}

然后查找CoClass属性:


coclass提供一个或多个
接口的具体
实现。在COM中,这种具体的
实现可以用支持COM
组件开发的任何
编程语言编写。 Delphi,
C ++,Visual Basic等。


我不熟悉这个,所以不要作为福音,但似乎通过 CoClass 属性触发的编译器魔法,你实例化一个 SpVoiceClass 看起来你正在实例化一个界面。


I am using Microsoft Text-to-Text Speech feature in my project. But I have a question about that, actually not directly about that. So :

Normally programmers when creating Interface, they put I as a prefix of the interface name like IReadable,IEnumerator etc. But I've come across something that actually shocked me.

in Microsoft Text Speech DLL there is something like this : SpVoice which is interface (they didn't put I as prefix for some reason and I don't know why ?) and SpVoiceClass. So then what's the problem you may ask, Here :

SpVoice speak= new SpVoice(); //I created an object from SpVoice Interface
speak.Speak("Hello StackOverFlow"); //and it speaks and say exactly what I write.

and

SpVoiceClass speak =  new SpVoiceClass();
speak.Speak("Hello Kowanichi"); //and it does the same thing.

The thing I don't get is how ? How does the first one work although it says it is an interface with tons of unimplemented methods etc.

Please some one explain me HOW ?

I am really confused now and maybe Microsoft developers didn't put I prefix for that reason, it can be instantiated.

Thanks in advance. Hope I describe my problem clearly.

Here is the image that I want you to see :

解决方案

EDIT: Ah, I see. Look at the definition of SpVoice:

[CoClass(typeof(SpVoiceClass))]
public interface SpVoice : ISpeechVoice, _ISpeechVoiceEvents_Event
{}

Then look up the CoClass attribute:

A coclass supplies concrete implementation(s) of one or more interfaces. In COM, such concrete implementations can be written in any programming language that supports COM component development, e.g. Delphi, C++, Visual Basic, etc.

I'm not familiar with this, so don't take this as gospel, but it appears that, through compiler magic triggered by the CoClass attribute, you're instantiating an instance of SpVoiceClass when it looks like you're instantiating an interface.

这篇关于它看起来像我实例化这个SpeechAPI接口。这怎么可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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