![]() |
Windows Speech to Text Sapi 5.4
Hey Leute ich hab ein Problem und brauche Hilfe :-D
Ich möchte ein kleines Tool schreiben welches eine Stimme in ein Memo schreibt( um später das ganze an die API Chat GPT zu senden). Leider bekomme ich es nicht hin und hoffe jemand kann helfen. Hier der Code
Delphi-Quellcode:
Die Fehlermeldungen ist bei
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleServer, SpeechLib_TLB,ActiveX, ComObj; type TForm17 = class(TForm) btn1: TButton; mmo1: TMemo; spshrdrcntxt1: TSpSharedRecoContext; procedure btn1Click(Sender: TObject); private FSAPI: ISpeechRecognizer; FRecoContext: ISpeechRecoContext; FRecoGrammar: ISpeechRecoGrammar; { Private-Deklarationen } public procedure OnRecognition(ASender: TObject; const StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: SpeechRecognitionType; const Result: ISpeechRecoResult); { Public-Deklarationen } end; var Form17: TForm17; SpVoice: ISpeechVoice; implementation {$R *.dfm} { TForm17 } procedure TForm17.btn1Click(Sender: TObject); begin FSAPI := CreateOleObject('SAPI.SpVoice') as ISpeechRecognizer; FRecoContext := FSAPI.CreateRecoContext; FRecoGrammar := FRecoContext.CreateGrammar(0); FRecoGrammar.DictationSetState(SGDSActive); FRecoContext.OnRecognition := OnRecognition; end; procedure TForm17.OnRecognition(ASender: TObject; const StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: SpeechRecognitionType; const Result: ISpeechRecoResult); begin mmo1.Lines.Add(Result.PhraseInfo.GetText(0, -1, True)); end;
Delphi-Quellcode:
FRecoContext.OnRecognition := OnRecognition;
Delphi-Quellcode:
Ich versuche es bereits seit 2 Tagen ohne Erfolg.
[dcc32 Fehler] Unit17.pas(43): E2003 Undeklarierter Bezeichner: 'OnRecognition'
[dcc32 Fehler] Unit17.pas(43): E2035 Nicht genügend wirkliche Parameter Ich hoffe jemand kann helfen :) Grüße eure Scharfe Mieze |
AW: Windows Speech to Text Sapi 5.4
Wie soll es auch gehen?
Wenn ich die "Microsoft Speech Object Library" Version 5.4 aus C:\Windows\System32\Speech\Common\sapi.dll als Type Liberary in Delphi importiere und mir eine Quelltext-Unit erzeugen lasse, dann hat ISpeechRecoContext nichts passendes dazu!
Delphi-Quellcode:
// *********************************************************************//
// Interface: ISpeechRecoContext // Flags: (4416) Dual OleAutomation Dispatchable // GUID: {580AA49D-7E1E-4809-B8E2-57DA806104B8} // *********************************************************************// ISpeechRecoContext = interface(IDispatch) ['{580AA49D-7E1E-4809-B8E2-57DA806104B8}'] function Get_Recognizer: ISpeechRecognizer; safecall; function Get_AudioInputInterferenceStatus: SpeechInterference; safecall; function Get_RequestedUIType: WideString; safecall; procedure _Set_Voice(const Voice: ISpeechVoice); safecall; function Get_Voice: ISpeechVoice; safecall; procedure Set_AllowVoiceFormatMatchingOnNextSet(pAllow: WordBool); safecall; function Get_AllowVoiceFormatMatchingOnNextSet: WordBool; safecall; procedure Set_VoicePurgeEvent(EventInterest: SpeechRecoEvents); safecall; function Get_VoicePurgeEvent: SpeechRecoEvents; safecall; procedure Set_EventInterests(EventInterest: SpeechRecoEvents); safecall; function Get_EventInterests: SpeechRecoEvents; safecall; procedure Set_CmdMaxAlternates(MaxAlternates: Integer); safecall; function Get_CmdMaxAlternates: Integer; safecall; procedure Set_State(State: SpeechRecoContextState); safecall; function Get_State: SpeechRecoContextState; safecall; procedure Set_RetainedAudio(Option: SpeechRetainedAudioOptions); safecall; function Get_RetainedAudio: SpeechRetainedAudioOptions; safecall; procedure _Set_RetainedAudioFormat(const Format: ISpeechAudioFormat); safecall; function Get_RetainedAudioFormat: ISpeechAudioFormat; safecall; procedure Pause; safecall; procedure Resume; safecall; function CreateGrammar(GrammarId: OleVariant): ISpeechRecoGrammar; safecall; function CreateResultFromMemory(const ResultBlock: OleVariant): ISpeechRecoResult; safecall; procedure Bookmark(Options: SpeechBookmarkOptions; StreamPos: OleVariant; BookmarkId: OleVariant); safecall; procedure SetAdaptationData(const AdaptationString: WideString); safecall; property Recognizer: ISpeechRecognizer read Get_Recognizer; property AudioInputInterferenceStatus: SpeechInterference read Get_AudioInputInterferenceStatus; property RequestedUIType: WideString read Get_RequestedUIType; property Voice: ISpeechVoice read Get_Voice write _Set_Voice; property AllowVoiceFormatMatchingOnNextSet: WordBool read Get_AllowVoiceFormatMatchingOnNextSet write Set_AllowVoiceFormatMatchingOnNextSet; property VoicePurgeEvent: SpeechRecoEvents read Get_VoicePurgeEvent write Set_VoicePurgeEvent; property EventInterests: SpeechRecoEvents read Get_EventInterests write Set_EventInterests; property CmdMaxAlternates: Integer read Get_CmdMaxAlternates write Set_CmdMaxAlternates; property State: SpeechRecoContextState read Get_State write Set_State; property RetainedAudio: SpeechRetainedAudioOptions read Get_RetainedAudio write Set_RetainedAudio; property RetainedAudioFormat: ISpeechAudioFormat read Get_RetainedAudioFormat write _Set_RetainedAudioFormat; end; |
AW: Windows Speech to Text Sapi 5.4
Ich hatte vor mehr als ein Jahrzehnt mal ein kleines Testprogramm geschrieben, was auch tatsächlich funktionierte (die Spracherkennung war allerdings sehr dürftig).
SAPI-Version war auf alle Fälle älter als 5.4. Sieht sehr ähnlich aus wie Dein Code, ich stelle den mal hier rein, vielleicht hilft´s ja ein wenig:
Delphi-Quellcode:
VG ZYL
unit Unit2;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleServer, SpeechLib_TLB, ActiveX; type TForm2 = class(TForm) SpSharedRecoContext1: TSpSharedRecoContext; Memo1: TMemo; procedure cre(Sender: TObject); procedure SpSharedRecoContext1Hypothesis(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; const Result: ISpeechRecoResult); procedure SpSharedRecoContext1Recognition(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: TOleEnum; const Result: ISpeechRecoResult); private { Private-Deklarationen } fMyGrammar:ISpeechRecoGrammar; public { Public-Deklarationen } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.cre(Sender: TObject); begin fMyGrammar:=SpSharedRecoContext1.CreateGrammar(0); fMyGrammar.DictationSetState(SGDSActive); end; procedure TForm2.SpSharedRecoContext1Hypothesis(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; const Result: ISpeechRecoResult); begin Memo1.Text := Result.PhraseInfo.GetText(0,-1,true); end; procedure TForm2.SpSharedRecoContext1Recognition(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; RecognitionType: TOleEnum; const Result: ISpeechRecoResult); begin Memo1.Text := Result.PhraseInfo.GetText(0,-1,true); end; end. |
AW: Windows Speech to Text Sapi 5.4
Vielen Dank :)
Gruß |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:23 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz