我想用delphi做一些语音识别,发现这个简单的项目效果很好,但我不能使用它,因为我无法导入SAPI 5.1。
在“导入类型库”窗口中,我可以找到SAPI 5.4,但遗憾的是我无法使用它。现在我想知道是否有办法导入SAPI 5.1,以便我可以使用下面的示例并根据需要进行扩展。德尔福不能导入SAPI 5.1
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SpeechLib_TLB, StdCtrls;
const SP_GETWHOLEPHRASE = -1;
type
TForm3 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private-Deklarationen }
public
SpSharedRecoContext1: TSpSharedRecoContext;
MyGrammar : ISpeechRecoGrammar;
procedure SpSharedRecoContext1Recognition(ASender: TObject;
StreamNumber: Integer;
StreamPosition: OleVariant;
RecognitionType: SpeechRecognitionType;
const Result: ISpeechRecoResult);
procedure SpSharedRecoContext1Hypothesis(ASender: TObject;
StreamNumber: Integer;
StreamPosition: OleVariant;
const Result: ISpeechRecoResult);
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SpSharedRecoContext1.Free;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
SpSharedRecoContext1 := TSpSharedRecoContext.Create(self);
SpSharedRecoContext1.OnRecognition := SpSharedRecoContext1Recognition;
SpSharedRecoContext1.OnHypothesis := SpSharedRecoContext1Hypothesis;
MyGrammar := SpSharedRecoContext1.CreateGrammar(0);
MyGrammar.DictationSetState(SGDSActive);
end;
procedure TForm3.SpSharedRecoContext1Recognition(ASender: TObject;
StreamNumber: Integer;
StreamPosition: OleVariant;
RecognitionType: SpeechRecognitionType;
const Result: ISpeechRecoResult);
begin
Caption := '';
Memo1.Lines.Add(Result.PhraseInfo.GetText(SP_GETWHOLEPHRASE,SP_GETWHOLEPHRASE,true));
end;
procedure TForm3.SpSharedRecoContext1Hypothesis(ASender: TObject;
StreamNumber: Integer;
StreamPosition: OleVariant;
const Result: ISpeechRecoResult);
begin
Caption := 'I am listening...';
end;
end.
任何帮助表示赞赏,
THX timo314
编辑: 我有德尔福6个人版
SAPI 5.1是不是在 “导入类型库” 窗口中列出
编译时我在第46行和第47行发现错误,说“不兼容的类型参数列表不同”
我注意到SpeechLib_TL示例中附带的B.pas不同于在“导入”目录中创建的导入。
更改SpSharedRecoContext1Recognition和SpSharedRecoContext1假设的参数列表后,应用程序将运行但不调用该过程。就好像程序没有注意到有人在说话。
欢迎来到StackOverflow。 Delphi的哪个版本? “无法导入”是什么意思?你的意思是没有安装你的Windows版本,但你有SAPI 5.4?如果是这样,5.4与早期版本向后兼容;你有什么问题?你会收到错误消息吗?请编辑您的问题,并记住这样做时,我们只有您提供给我们的信息来尝试并帮助您解决问题。如果你不告诉我们,我们无法知道 - 我们无法看到你的屏幕或代码,或从这里读出你的想法。 :) – 2012-03-15 22:42:39