AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi Windows Speech to Text Sapi 5.4
Thema durchsuchen
Ansicht
Themen-Optionen

Windows Speech to Text Sapi 5.4

Ein Thema von ScharfeMietze · begonnen am 26. Jan 2023 · letzter Beitrag vom 9. Feb 2023
Antwort Antwort
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
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.060 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Windows Speech to Text Sapi 5.4

  Alt 26. Jan 2023, 15:23
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;
  Mit Zitat antworten Zitat
ZYLAGON

Registriert seit: 11. Nov 2015
49 Beiträge
 
Delphi 10.3 Rio
 
#3

AW: Windows Speech to Text Sapi 5.4

  Alt 26. Jan 2023, 16:38
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:
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.
VG ZYL
  Mit Zitat antworten Zitat
ScharfeMietze

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

AW: Windows Speech to Text Sapi 5.4

  Alt 9. Feb 2023, 12:56
Vielen Dank
Gruß
  Mit Zitat antworten Zitat
Antwort Antwort

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:04 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz