Einzelnen Beitrag anzeigen

ScharfeMietze

Registriert seit: 5. Mär 2014
165 Beiträge
 
Delphi 10.2 Tokyo Architect
 
#1

Windows Speech to Text Sapi 5.4

  Alt 26. Jan 2023, 13:34
Hey Leute ich hab ein Problem und brauche Hilfe
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:
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;
Die Fehlermeldungen ist bei
 FRecoContext.OnRecognition := OnRecognition;
Delphi-Quellcode:
[dcc32 Fehler] Unit17.pas(43): E2003 Undeklarierter Bezeichner: 'OnRecognition'
[dcc32 Fehler] Unit17.pas(43): E2035 Nicht genügend wirkliche Parameter
Ich versuche es bereits seit 2 Tagen ohne Erfolg.
Ich hoffe jemand kann helfen
Grüße eure
Scharfe Mieze
  Mit Zitat antworten Zitat