Publié le 07/06/2006 Dans Programmation
On lance Delphi!
Première étape, on va importer la librairie Acapela pour pouvoir utiliser le contrôle ActiveX dans Delphi. Plus besoin de s'amuser à lire des headers en C et de tenter des les convertir, les interfaces simplifient grandement le travail.Après avoir cliqué sur "Import ActiveX Control", il faut ensuite locliser la librairie d'Acapela dans la liste, à savoir ASASpeechCtl. Une fois cela fait, on clique ensuite sur "Create Unit" pour générer le code du composant permettant d'utiliser la librairie.
Comme pour ton nouveau composant Delphi, il faut maintenant l'installer dans un package et ensuite compiler et installer le package pour avoir accès au nouveau composant.
- type
- // *********************************************************************//
- // Forward declaration of types defined in TypeLibrary
- // *********************************************************************//
- _IAASpeechCtrlEvents = dispinterface;
- IAAVoiceCtrl = interface;
- IAAVoiceCtrlDisp = dispinterface;
- IAASpeechCtrl = interface;
- IAASpeechCtrlDisp = dispinterface;
- // *********************************************************************//
- // Declaration of CoClasses defined in Type Library
- // (NOTE: Here we map each CoClass to its Default Interface)
- // *********************************************************************//
- AASpeechCtrl = IAASpeechCtrl;
- AAVoiceCtrl = IAAVoiceCtrl;
- // *********************************************************************//
- // DispIntf: _IAASpeechCtrlEvents
- // Flags: (4096) Dispatchable
- // GUID: {68C6D73C-A7EB-4899-BFA7-960793CF0EF6}
- // *********************************************************************//
- _IAASpeechCtrlEvents = dispinterface
- ['{68C6D73C-A7EB-4899-BFA7-960793CF0EF6}']
- procedure AudioOpen; dispid 1;
- procedure AudioClose; dispid 2;
- procedure TextStart(lTextId: Integer); dispid 3;
- procedure TextEnd(lTextId: Integer); dispid 4;
- procedure WordPosition(lTextId: Integer; lWordPos: Integer; lByteCount: Integer); dispid 5;
- procedure Phoneme(lTextId: Integer; sEnginePhoneme1: Smallint; sEnginePhoneme2: Smallint;
- sIPAPhoneme1: Smallint; sIPAPhoneme2: Smallint; lDuration: Integer;
- lByteCount: Integer); dispid 6;
- procedure AudioData(lTextId: Integer; lDataCount: Integer; lDataSize: Integer); dispid 7;
- procedure LastError(lErrorCode: Integer); dispid 8;
- procedure AcaPhoneme(lTextId: Integer; sEnginePhoneme1: Smallint; sEnginePhoneme2: Smallint;
- sEnginePhoneme3: Smallint; sEnginePhoneme4: Smallint;
- sIPAPhoneme1: Smallint; lDuration: Integer; lByteCount: Integer); dispid 9;
- procedure MouthPosition(lTextId: Integer; sIPAPhoneme1: Smallint; sMouthPos1: Smallint;
- sMouthPos2: Smallint; sMouthPos3: Smallint; sMouthPos4: Smallint;
- sMouthPos5: Smallint; sMouthPos6: Smallint; sMouthPos7: Smallint;
- sMouthPos8: Smallint; lDuration: Integer; lByteCount: Integer); dispid 10;
- end;
- // *********************************************************************//
- // Interface: IAAVoiceCtrl
- // Flags: (4416) Dual OleAutomation Dispatchable
- // GUID: {B94DA5AB-91C0-4B1A-B0E4-E45A0075905F}
- // *********************************************************************//
- IAAVoiceCtrl = interface(IDispatch)
- ['{B94DA5AB-91C0-4B1A-B0E4-E45A0075905F}']
- function Get_Cmd: WideString; safecall;
- function Get_Gender: Smallint; safecall;
- function Get_Language: Integer; safecall;
- function Get_Speaker: WideString; safecall;
- function Get_Index: Smallint; safecall;
- function Get_Frequency: Integer; safecall;
- property Cmd: WideString read Get_Cmd;
- property Gender: Smallint read Get_Gender;
- property Language: Integer read Get_Language;
- property Speaker: WideString read Get_Speaker;
- property Index: Smallint read Get_Index;
- property Frequency: Integer read Get_Frequency;
- end;
- // *********************************************************************//
- // DispIntf: IAAVoiceCtrlDisp
- // Flags: (4416) Dual OleAutomation Dispatchable
- // GUID: {B94DA5AB-91C0-4B1A-B0E4-E45A0075905F}
- // *********************************************************************//
- IAAVoiceCtrlDisp = dispinterface
- ['{B94DA5AB-91C0-4B1A-B0E4-E45A0075905F}']
- property Cmd: WideString readonly dispid 1;
- property Gender: Smallint readonly dispid 3;
- property Language: Integer readonly dispid 4;
- property Speaker: WideString readonly dispid 5;
- property Index: Smallint readonly dispid 6;
- property Frequency: Integer readonly dispid 7;
- end;
- // *********************************************************************//
- // Interface: IAASpeechCtrl
- // Flags: (4416) Dual OleAutomation Dispatchable
- // GUID: {543BD792-CB83-4E88-8868-FC8392ABD9D6}
- // *********************************************************************//
- IAASpeechCtrl = interface(IDispatch)
- ['{543BD792-CB83-4E88-8868-FC8392ABD9D6}']
- function ConnectEngine(nConnectionMode: SYSINT; nPort: SYSINT;
- const bstrServerAddress: WideString): Integer; safecall;
- function DisconnectEngine: Integer; safecall;
- function Enumerate: Integer; safecall;
- function Load(const bstrCmd: WideString): Integer; safecall;
- function Unload: Integer; safecall;
- function Speak(const bstrText: WideString; lTextId: Integer): Integer; safecall;
- function Stop: Integer; safecall;
- function Pause: Integer; safecall;
- function Resume: Integer; safecall;
- function EventMask(ulEvtMask: Integer): Integer; safecall;
- function GetVarAudioData(vData: OleVariant): Integer; safecall;
- function GetAudioData(var pData: Integer; lDataSize: Integer): Integer; safecall;
- function Get_Voice(nIndex: SYSINT): IAAVoiceCtrl; safecall;
- function Get_CurrentVoice: IAAVoiceCtrl; safecall;
- function Get_VoiceCount: Smallint; safecall;
- function Get_Output: Smallint; safecall;
- procedure Set_Output(pVal: Smallint); safecall;
- function Get_FileName: WideString; safecall;
- procedure Set_FileName(const pbstrFileName: WideString); safecall;
- function Get_Volume: Smallint; safecall;
- procedure Set_Volume(pVal: Smallint); safecall;
- function Get_Pitch: Smallint; safecall;
- procedure Set_Pitch(pVal: Smallint); safecall;
- function Get_Speed: Smallint; safecall;
- procedure Set_Speed(pVal: Smallint); safecall;
- function Get_Status: Smallint; safecall;
- function Get_LastError: Integer; safecall;
- procedure Set_OEMKey(const Param1: WideString); safecall;
- procedure ServerShutdown(nState: SYSINT); safecall;
- property Voice[nIndex: SYSINT]: IAAVoiceCtrl read Get_Voice;
- property CurrentVoice: IAAVoiceCtrl read Get_CurrentVoice;
- property VoiceCount: Smallint read Get_VoiceCount;
- property Output: Smallint read Get_Output write Set_Output;
- property FileName: WideString read Get_FileName write Set_FileName;
- property Volume: Smallint read Get_Volume write Set_Volume;
- property Pitch: Smallint read Get_Pitch write Set_Pitch;
- property Speed: Smallint read Get_Speed write Set_Speed;
- property Status: Smallint read Get_Status;
- property LastError: Integer read Get_LastError;
- property OEMKey: WideString write Set_OEMKey;
- end;
- // *********************************************************************//
- // DispIntf: IAASpeechCtrlDisp
- // Flags: (4416) Dual OleAutomation Dispatchable
- // GUID: {543BD792-CB83-4E88-8868-FC8392ABD9D6}
- // *********************************************************************//
- IAASpeechCtrlDisp = dispinterface
- ['{543BD792-CB83-4E88-8868-FC8392ABD9D6}']
- function ConnectEngine(nConnectionMode: SYSINT; nPort: SYSINT;
- const bstrServerAddress: WideString): Integer; dispid 1;
- function DisconnectEngine: Integer; dispid 2;
- function Enumerate: Integer; dispid 3;
- function Load(const bstrCmd: WideString): Integer; dispid 4;
- function Unload: Integer; dispid 5;
- function Speak(const bstrText: WideString; lTextId: Integer): Integer; dispid 6;
- function Stop: Integer; dispid 7;
- function Pause: Integer; dispid 8;
- function Resume: Integer; dispid 9;
- function EventMask(ulEvtMask: Integer): Integer; dispid 10;
- function GetVarAudioData(vData: OleVariant): Integer; dispid 11;
- function GetAudioData(var pData: Integer; lDataSize: Integer): Integer; dispid 12;
- property Voice[nIndex: SYSINT]: IAAVoiceCtrl readonly dispid 13;
- property CurrentVoice: IAAVoiceCtrl readonly dispid 14;
- property VoiceCount: Smallint readonly dispid 15;
- property Output: Smallint dispid 16;
- property FileName: WideString dispid 17;
- property Volume: Smallint dispid 18;
- property Pitch: Smallint dispid 19;
- property Speed: Smallint dispid 20;
- property Status: Smallint readonly dispid 21;
- property LastError: Integer readonly dispid 22;
- property OEMKey: WideString writeonly dispid 23;
- procedure ServerShutdown(nState: SYSINT); dispid 24;
- end;
- // *********************************************************************//
- // OLE Control Proxy class declaration
- // Control Name : TAASpeechCtrl
- // Help String : AASpeechCtrl Class
- // Default Interface: IAASpeechCtrl
- // Def. Intf. DISP? : No
- // Event Interface: _IAASpeechCtrlEvents
- // TypeFlags : (2) CanCreate
- // *********************************************************************//
- TAASpeechCtrlTextStart = procedure(ASender: TObject; lTextId: Integer) of object;
- TAASpeechCtrlTextEnd = procedure(ASender: TObject; lTextId: Integer) of object;
- TAASpeechCtrlWordPosition = procedure(ASender: TObject; lTextId: Integer; lWordPos: Integer;
- lByteCount: Integer) of object;
- TAASpeechCtrlPhoneme = procedure(ASender: TObject; lTextId: Integer; sEnginePhoneme1: Smallint;
- sEnginePhoneme2: Smallint;
- sIPAPhoneme1: Smallint;
- sIPAPhoneme2: Smallint; lDuration: Integer;
- lByteCount: Integer) of object;
- TAASpeechCtrlAudioData = procedure(ASender: TObject; lTextId: Integer; lDataCount: Integer;
- lDataSize: Integer) of object;
- TAASpeechCtrlLastError = procedure(ASender: TObject; lErrorCode: Integer) of object;
- TAASpeechCtrlAcaPhoneme = procedure(ASender: TObject; lTextId: Integer;
- sEnginePhoneme1: Smallint;
- sEnginePhoneme2: Smallint;
- sEnginePhoneme3: Smallint;
- sEnginePhoneme4: Smallint;
- sIPAPhoneme1: Smallint; lDuration: Integer;
- lByteCount: Integer) of object;
- TAASpeechCtrlMouthPosition = procedure(ASender: TObject; lTextId: Integer;
- sIPAPhoneme1: Smallint;
- sMouthPos1: Smallint;
- sMouthPos2: Smallint;
- sMouthPos3: Smallint;
- sMouthPos4: Smallint;
- sMouthPos5: Smallint;
- sMouthPos6: Smallint;
- sMouthPos7: Smallint;
- sMouthPos8: Smallint;
- lDuration: Integer; lByteCount: Integer) of object;
- TAASpeechCtrl = class(TOleControl)
- private
- FOnAudioOpen: TNotifyEvent;
- FOnAudioClose: TNotifyEvent;
- FOnTextStart: TAASpeechCtrlTextStart;
- FOnTextEnd: TAASpeechCtrlTextEnd;
- FOnWordPosition: TAASpeechCtrlWordPosition;
- FOnPhoneme: TAASpeechCtrlPhoneme;
- FOnAudioData: TAASpeechCtrlAudioData;
- FOnLastError: TAASpeechCtrlLastError;
- FOnAcaPhoneme: TAASpeechCtrlAcaPhoneme;
- FOnMouthPosition: TAASpeechCtrlMouthPosition;
- FIntf: IAASpeechCtrl;
- function GetControlInterface: IAASpeechCtrl;
- protected
- procedure CreateControl;
- procedure InitControlData; override;
- function Get_Voice(nIndex: SYSINT): IAAVoiceCtrl;
- function Get_CurrentVoice: IAAVoiceCtrl;
- public
- function ConnectEngine(nConnectionMode: SYSINT; nPort: SYSINT;
- const bstrServerAddress: WideString): Integer;
- function DisconnectEngine: Integer;
- function Enumerate: Integer;
- function Load(const bstrCmd: WideString): Integer;
- function Unload: Integer;
- function Speak(const bstrText: WideString; lTextId: Integer): Integer;
- function Stop: Integer;
- function Pause: Integer;
- function Resume: Integer;
- function EventMask(ulEvtMask: Integer): Integer;
- function GetVarAudioData(vData: OleVariant): Integer;
- function GetAudioData(var pData: Integer; lDataSize: Integer): Integer;
- procedure ServerShutdown(nState: SYSINT);
- property ControlInterface: IAASpeechCtrl read GetControlInterface;
- property DefaultInterface: IAASpeechCtrl read GetControlInterface;
- property Voice[nIndex: SYSINT]: IAAVoiceCtrl read Get_Voice;
- property CurrentVoice: IAAVoiceCtrl read Get_CurrentVoice;
- property VoiceCount: Smallint index 15 read GetSmallintProp;
- property Status: Smallint index 21 read GetSmallintProp;
- property LastError: Integer index 22 read GetIntegerProp;
- property OEMKey: WideString index 23 write SetWideStringProp;
- published
- property Anchors;
- property TabStop;
- property Align;
- property DragCursor;
- property DragMode;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property TabOrder;
- property Visible;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDrag;
- property OnEnter;
- property OnExit;
- property OnStartDrag;
- property Output: Smallint index 16 read GetSmallintProp write SetSmallintProp stored False;
- property FileName: WideString index 17 read GetWideStringProp write SetWideStringProp stored False;
- property Volume: Smallint index 18 read GetSmallintProp write SetSmallintProp stored False;
- property Pitch: Smallint index 19 read GetSmallintProp write SetSmallintProp stored False;
- property Speed: Smallint index 20 read GetSmallintProp write SetSmallintProp stored False;
- property OnAudioOpen: TNotifyEvent read FOnAudioOpen write FOnAudioOpen;
- property OnAudioClose: TNotifyEvent read FOnAudioClose write FOnAudioClose;
- property OnTextStart: TAASpeechCtrlTextStart read FOnTextStart write FOnTextStart;
- property OnTextEnd: TAASpeechCtrlTextEnd read FOnTextEnd write FOnTextEnd;
- property OnWordPosition: TAASpeechCtrlWordPosition read FOnWordPosition write FOnWordPosition;
- property OnPhoneme: TAASpeechCtrlPhoneme read FOnPhoneme write FOnPhoneme;
- property OnAudioData: TAASpeechCtrlAudioData read FOnAudioData write FOnAudioData;
- property OnLastError: TAASpeechCtrlLastError read FOnLastError write FOnLastError;
- property OnAcaPhoneme: TAASpeechCtrlAcaPhoneme read FOnAcaPhoneme write FOnAcaPhoneme;
- property OnMouthPosition: TAASpeechCtrlMouthPosition read FOnMouthPosition write FOnMouthPosition;
- end;
- // *********************************************************************//
- // The Class CoAAVoiceCtrl provides a Create and CreateRemote method to
- // create instances of the default interface IAAVoiceCtrl exposed by
- // the CoClass AAVoiceCtrl. The functions are intended to be used by
- // clients wishing to automate the CoClass objects exposed by the
- // server of this typelibrary.
- // *********************************************************************//
- CoAAVoiceCtrl = class
- class function Create: IAAVoiceCtrl;
- class function CreateRemote(const MachineName: string): IAAVoiceCtrl;
- end;
Mais Bruno et Claire wouw p'tain respect, on dirait des vrais
C'est assez impressionant à écouter et à faire parler sur sa propre machine. Dommage que l'on ne puisse s'amuser que 30 jours avec ce petit jouet sinon je me ferais un plaisir de programmer l'un ou l'autre automatisme pour m'annoncer des événements. (en gros comme le nabaztag, mais sur ma machine )
Ca me rapelle la lecture audio de texte sur les macs.
Ca existe tjrs dans OS X ?