{ FLuencyAPI.PAS Fluency API for Delphi Requires: Fluency TTS 5.0 or higher Copyright (C) 2008 Fluency, Amsterdam All rights reserved } unit FLuencyAPI; interface uses Windows, SysUtils; const // events SYNC_START = 0; SYNC_PROGRESS = 1; SYNC_FINISH = 2; SYNC_PHONEME = 3; SYNC_SCAN = 4; // wrapper functions function fluencyInitialize: Boolean; function fluencyInitializeFrom(TTSPath, UserPath: PChar): Boolean; procedure fluencyClose; // to load DLL manually (and then call _fluencyInitialize(From)) function _fluencyLoadDLL(Path: string): Boolean; // API functions var // version info fluencyGetMajorVersion : function (): Cardinal; stdcall; fluencyGetMinorVersion : function (): Cardinal; stdcall; fluencyAboutWindow : procedure (Win: HWND); stdcall; // initialize/close (normally called from wrapper functions) _fluencyUnlock : procedure (LicenseKey, Extra: PChar); stdcall; _fluencyInitialize : function (): Boolean; stdcall; _fluencyInitializeFrom : function (TTSPath, UserPath: PChar): Boolean; stdcall; _fluencyClose : procedure (); stdcall; // enumerate voices fluencyGetVoiceCount : function (): Cardinal; stdcall; fluencyGetVoiceName : function (Voice: Cardinal; Name: PChar; MaxLen: Cardinal): Cardinal; stdcall; // user settings fluencyGetPreferredVoiceName : function (Name: PChar; MaxLen: Cardinal): Cardinal; stdcall; fluencySetPreferredVoiceName : procedure (Name: PChar); stdcall; fluencyGetPreferredTempo : function (): Integer; stdcall; fluencySetPreferredTempo : procedure (Tempo: Integer); stdcall; fluencyGetPreferredVolume : function (): Integer; stdcall; fluencySetPreferredVolume : procedure (Volume: Cardinal); stdcall; fluencyGetPreferredBalance : function (): Cardinal; stdcall; fluencySetPreferredBalance : procedure (Balance: Integer); stdcall; fluencyGetReadingMode : function (): Cardinal; stdcall; fluencySetReadingMode : procedure (Mode: Cardinal); stdcall; fluencyGetSpellOutMode : function (): Cardinal; stdcall; fluencySetSpellOutMode : procedure (Mode: Cardinal); stdcall; fluencyGetPunctuationMode : function (): Boolean; stdcall; fluencySetPunctuationMode : procedure (Mode: Boolean); stdcall; fluencySaveSettings: procedure (); stdcall; fluencyUpdateSettings: procedure (); stdcall; // lexicon fluencyLookupWord : function (Word, Transcription: PChar; MaxLen: Cardinal): Cardinal; stdcall; fluencyAddWord : procedure (Word, Transcription: PChar); stdcall; fluencyUserLexiconNextWord : function (Word, NextWord: PChar; MaxLen: Cardinal): Cardinal; stdcall; fluencyGetUserDataPath : function (Path: PChar; MaxLen: Cardinal): Cardinal; stdcall; // voice object fluencyCreateVoice : function (Name: PChar): Pointer; stdcall; fluencyDeleteVoice : procedure (VoiceObject: pointer); stdcall; // channel object fluencyCreateChannel : function (VoiceObject: Pointer; SamplingRate: Cardinal; Stereo: Boolean): Pointer; stdcall; fluencyDeleteChannel : procedure (ChannelObject: Pointer); stdcall; fluencySetVoice : procedure (ChannelObject, VoiceObject: Pointer); stdcall; fluencySetTempo : procedure (ChannelObject: Pointer; Tempo: Integer); stdcall; fluencySetVolume : procedure(ChannelObject: Pointer; Volume: Cardinal); stdcall; fluencySetBalance : procedure(ChannelObject: Pointer; Balance: Integer); stdcall; fluencySetInputText : procedure (ChannelObject: Pointer; Text: PChar); stdcall; fluencyGetPhone : function (ChannelObject: Pointer; out Phone: PChar; out Samples: Cardinal; out Wav: Pointer; out TextIndex, WordLength: Cardinal): Boolean; stdcall; fluencySpeak : function (ChannelObject: Pointer; SyncProc: Pointer; User: Cardinal): Boolean; stdcall; fluencyStopSpeaking : procedure (ChannelObject: Pointer); stdcall; fluencyPauseResumeSpeaking : procedure (ChannelObject: Pointer); stdcall; fluencySpeakToFile : procedure(ChannelObject: Pointer; Filename: PChar; SyncProc: Pointer; User: Cardinal); stdcall; fluencyAbortSpeakToFile : procedure(ChannelObject: Pointer); stdcall; fluencyScanText : procedure(ChannelObject: Pointer; Sensitivity: Cardinal; SyncProc: Pointer; User: Cardinal); stdcall; fluencyAbortScanText : procedure(ChannelObject: Pointer); stdcall; // Fluency only fluencySetTuningWeights : procedure (PitchWeight, DurationWeight, ContextWeight: Cardinal); stdcall; fluencyGenerateHardwareKey : function (HardwareKey, LicenseKey: PChar): Cardinal; stdcall; fluencyTTSPath: string; // set by _fluencyLoadDLL implementation uses Registry; var hFluency : THandle = 0; function _fluencyLoadDLL(Path: string): Boolean; begin _fluencyLoadDLL := false; if hFluency <> 0 then begin // DLL already loaded _fluencyLoadDLL := true; Exit; end; if Path = '' then begin with TRegistry.Create do try Access := KEY_READ; RootKey := HKEY_LOCAL_MACHINE; OpenKey('Software\Fluency\TTS', false); Path := ReadString('Path'); finally Free; end; end; fluencyTTSPath := Path; if Path <> '' then begin Path := Path + '\FLUENCY.DLL'; hFluency := LoadLibrary(PChar(Path)); end; if hFluency <> 0 then begin fluencyGetMajorVersion := GetProcAddress(hFluency, 'fluencyGetMajorVersion'); fluencyGetMinorVersion := GetProcAddress(hFluency, 'fluencyGetMinorVersion'); fluencyAboutWindow := GetProcAddress(hFluency, 'fluencyAboutWindow'); _fluencyUnlock := GetProcAddress(hFluency, 'fluencyUnlock'); _fluencyInitialize := GetProcAddress(hFluency, 'fluencyInitialize'); _fluencyInitializeFrom := GetProcAddress(hFluency, 'fluencyInitializeFrom'); _fluencyClose := GetProcAddress(hFluency, 'fluencyClose'); fluencyGetVoiceCount := GetProcAddress(hFluency, 'fluencyGetVoiceCount'); fluencyGetVoiceName := GetProcAddress(hFluency, 'fluencyGetVoiceName'); fluencyGetPreferredVoiceName := GetProcAddress(hFluency, 'fluencyGetPreferredVoiceName'); fluencySetPreferredVoiceName := GetProcAddress(hFluency, 'fluencySetPreferredVoiceName'); fluencyGetPreferredTempo := GetProcAddress(hFluency, 'fluencyGetPreferredTempo'); fluencySetPreferredTempo := GetProcAddress(hFluency, 'fluencySetPreferredTempo'); fluencyGetPreferredVolume := GetProcAddress(hFluency, 'fluencyGetPreferredVolume'); fluencySetPreferredVolume := GetProcAddress(hFluency, 'fluencySetPreferredVolume'); fluencyGetPreferredBalance := GetProcAddress(hFluency, 'fluencyGetPreferredBalance'); fluencySetPreferredBalance := GetProcAddress(hFluency, 'fluencySetPreferredBalance'); fluencyGetReadingMode := GetProcAddress(hFluency, 'fluencyGetReadingMode'); fluencySetReadingMode := GetProcAddress(hFluency, 'fluencySetReadingMode'); fluencyGetSpellOutMode := GetProcAddress(hFluency, 'fluencyGetSpellOutMode'); fluencySetSpellOutMode := GetProcAddress(hFluency, 'fluencySetSpellOutMode'); fluencyGetPunctuationMode := GetProcAddress(hFluency, 'fluencyGetPunctuationMode'); fluencySetPunctuationMode := GetProcAddress(hFluency, 'fluencySetPunctuationMode'); fluencyAddWord := GetProcAddress(hFluency, 'fluencyAddWord'); fluencyUserLexiconNextWord := GetProcAddress(hFluency, 'fluencyUserLexiconNextWord'); fluencyGetUserDataPath := GetProcAddress(hFluency, 'fluencyGetUserDataPath'); fluencyLookupWord := GetProcAddress(hFluency, 'fluencyLookupWord'); fluencyCreateVoice := GetProcAddress(hFluency, 'fluencyCreateVoice'); fluencyDeleteVoice := GetProcAddress(hFluency, 'fluencyDeleteVoice'); fluencyCreateChannel := GetProcAddress(hFluency, 'fluencyCreateChannel'); fluencyDeleteChannel := GetProcAddress(hFluency, 'fluencyDeleteChannel'); fluencySetVoice := GetProcAddress(hFluency, 'fluencySetVoice'); fluencySetTempo := GetProcAddress(hFluency, 'fluencySetTempo'); fluencySetVolume := GetProcAddress(hFluency, 'fluencySetVolume'); fluencySetBalance := GetProcAddress(hFluency, 'fluencySetBalance'); fluencySetInputText := GetProcAddress(hFluency, 'fluencySetInputText'); fluencyUpdateSettings := GetProcAddress(hFluency, 'fluencyUpdateSettings'); fluencySaveSettings := GetProcAddress(hFluency, 'fluencySaveSettings'); fluencyGetPhone := GetProcAddress(hFluency, 'fluencyGetPhone'); fluencySpeak := GetProcAddress(hFluency, 'fluencySpeak'); fluencyStopSpeaking := GetProcAddress(hFluency, 'fluencyStopSpeaking'); fluencyPauseResumeSpeaking := GetProcAddress(hFluency, 'fluencyPauseResumeSpeaking'); fluencySpeakToFile := GetProcAddress(hFluency, 'fluencySpeakToFile'); fluencyAbortSpeakToFile := GetProcAddress(hFluency, 'fluencyAbortSpeakToFile'); fluencyScanText := GetProcAddress(hFluency, 'fluencyScanText'); fluencyAbortScanText := GetProcAddress(hFluency, 'fluencyAbortScanText'); fluencySetTuningWeights := GetProcAddress(hFluency, 'fluencySetTuningWeights'); fluencyGenerateHardwareKey := GetProcAddress(hFluency, 'fluencyGenerateHardwareKey'); _fluencyLoadDLL := true; end; end; function fluencyInitialize: Boolean; begin fluencyInitialize := _fluencyLoadDLL('') and _fluencyInitialize; end; function fluencyInitializeFrom(TTSPath, UserPath: PChar): Boolean; begin fluencyInitializeFrom := _fluencyLoadDLL(TTSPath) and _fluencyInitializeFrom(TTSPath, UserPath); end; procedure fluencyClose; begin if hFluency = 0 then Exit; if Assigned(_fluencyClose) then _fluencyClose; end; initialization finalization if hFluency <> 0 then FreeLibrary(hFluency); end.