-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathGrijjy.TextToSpeech.Base.pas
122 lines (104 loc) · 2.82 KB
/
Grijjy.TextToSpeech.Base.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
unit Grijjy.TextToSpeech.Base;
{< Base class for text-to-speech implementations }
interface
uses
System.Classes,
Grijjy.TextToSpeech;
type
{ Base class that implements IgoTextToSpeech.
Platform-specific implementations derive from this class. }
TgoTextToSpeechBase = class abstract(TInterfacedObject, IgoTextToSpeech)
{$REGION 'Internal Declarations'}
private
FAvailable: Boolean;
FOnAvailable: TNotifyEvent;
FOnSpeechStarted: TNotifyEvent;
FOnSpeechFinished: TNotifyEvent;
protected
{ IgoTextToSpeech }
function _GetAvailable: Boolean;
function _GetOnAvailable: TNotifyEvent;
procedure _SetOnAvailable(const AValue: TNotifyEvent);
function _GetOnSpeechFinished: TNotifyEvent;
procedure _SetOnSpeechFinished(const AValue: TNotifyEvent);
function _GetOnSpeechStarted: TNotifyEvent;
procedure _SetOnSpeechStarted(const AValue: TNotifyEvent);
function Speak(const AText: String): Boolean; virtual; abstract;
procedure Stop; virtual; abstract;
function IsSpeaking: Boolean; virtual; abstract;
protected
{ Fires the FOn* events in the main thread }
procedure DoAvailable;
procedure DoSpeechStarted;
procedure DoSpeechFinished;
property Available: Boolean read FAvailable write FAvailable;
{$ENDREGION 'Internal Declarations'}
end;
implementation
{ TgoTextToSpeechBase }
procedure TgoTextToSpeechBase.DoAvailable;
begin
if Assigned(FOnAvailable) then
begin
{ Fire event from main thread. Use Queue instead of Synchronize to avoid
blocking. }
TThread.Queue(nil,
procedure
begin
FOnAvailable(Self);
end);
end;
end;
procedure TgoTextToSpeechBase.DoSpeechFinished;
begin
if Assigned(FOnSpeechFinished) then
begin
TThread.Queue(nil,
procedure
begin
FOnSpeechFinished(Self);
end);
end;
end;
procedure TgoTextToSpeechBase.DoSpeechStarted;
begin
if Assigned(FOnSpeechStarted) then
begin
TThread.Queue(nil,
procedure
begin
FOnSpeechStarted(Self);
end);
end;
end;
function TgoTextToSpeechBase._GetAvailable: Boolean;
begin
Result := FAvailable;
end;
function TgoTextToSpeechBase._GetOnAvailable: TNotifyEvent;
begin
Result := FOnAvailable;
end;
function TgoTextToSpeechBase._GetOnSpeechFinished: TNotifyEvent;
begin
Result := FOnSpeechFinished;
end;
function TgoTextToSpeechBase._GetOnSpeechStarted: TNotifyEvent;
begin
Result := FOnSpeechStarted;
end;
procedure TgoTextToSpeechBase._SetOnAvailable(const AValue: TNotifyEvent);
begin
FOnAvailable := AValue;
if (FAvailable) then
DoAvailable;
end;
procedure TgoTextToSpeechBase._SetOnSpeechFinished(const AValue: TNotifyEvent);
begin
FOnSpeechFinished := AValue;
end;
procedure TgoTextToSpeechBase._SetOnSpeechStarted(const AValue: TNotifyEvent);
begin
FOnSpeechStarted := AValue;
end;
end.