1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "texttospeechengine.h" |
|
22 |
|
23 // ================= MEMBER FUNCTIONS ======================= |
|
24 |
|
25 // ---------------------------------------------------------- |
|
26 // CTextToSpeechEngine::NewL() |
|
27 // |
|
28 // ---------------------------------------------------------- |
|
29 // |
|
30 CTextToSpeechEngine* CTextToSpeechEngine::NewL() |
|
31 { |
|
32 CTextToSpeechEngine* self = new( ELeave ) CTextToSpeechEngine(); |
|
33 |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop( self ); |
|
37 |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ---------------------------------------------------------- |
|
42 // CTextToSpeechEngine::ConstructL() |
|
43 // |
|
44 // ---------------------------------------------------------- |
|
45 // |
|
46 void CTextToSpeechEngine::ConstructL() |
|
47 { |
|
48 // Add ourselves to active scheduler |
|
49 CActiveScheduler::Add( this ); |
|
50 |
|
51 User::LeaveIfError( iServer.Open() ); |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------- |
|
55 // CTextToSpeechEngine::CTextToSpeechEngine() |
|
56 // |
|
57 // ---------------------------------------------------------- |
|
58 // |
|
59 CTextToSpeechEngine::CTextToSpeechEngine() : |
|
60 CActive( EPriorityStandard ) |
|
61 { |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------- |
|
65 // CTextToSpeechEngine::~CTextToSpeechEngine() |
|
66 // Destructor |
|
67 // Frees reserved resources |
|
68 // ---------------------------------------------------------- |
|
69 // |
|
70 CTextToSpeechEngine::~CTextToSpeechEngine() |
|
71 { |
|
72 Cancel(); |
|
73 |
|
74 iServer.Close(); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------- |
|
78 // CTextToSpeechEngine::InitAndPlayText |
|
79 // |
|
80 // ---------------------------------------------------------- |
|
81 // |
|
82 void CTextToSpeechEngine::InitAndPlayText( const TDesC& aText ) |
|
83 { |
|
84 Cancel(); |
|
85 SetActive(); |
|
86 iState = EPriming; |
|
87 |
|
88 iServer.InitialiseSynthesis( aText, iStatus ); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------- |
|
92 // CTextToSpeechEngine::InitAndPlayTextToFile |
|
93 // |
|
94 // ---------------------------------------------------------- |
|
95 // |
|
96 void CTextToSpeechEngine::InitAndPlayTextToFile( const TDesC& aText, |
|
97 const TFileName& aFileName ) |
|
98 { |
|
99 iFileName = aFileName; |
|
100 |
|
101 Cancel(); |
|
102 SetActive(); |
|
103 iState = EPriming; |
|
104 |
|
105 iServer.InitialiseSynthesis( aText, iFileName, iStatus ); |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------- |
|
109 // CTextToSpeechEngine::PauseL |
|
110 // |
|
111 // ---------------------------------------------------------- |
|
112 // |
|
113 void CTextToSpeechEngine::PauseL() |
|
114 { |
|
115 iServer.PauseL(); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------- |
|
119 // CTextToSpeechEngine::Play |
|
120 // |
|
121 // ---------------------------------------------------------- |
|
122 // |
|
123 void CTextToSpeechEngine::Play() |
|
124 { |
|
125 Cancel(); |
|
126 SetActive(); |
|
127 iState = ESpeaking; |
|
128 |
|
129 iServer.Synthesise( iStatus ); |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------- |
|
133 // CTextToSpeechEngine::StopL |
|
134 // |
|
135 // ---------------------------------------------------------- |
|
136 // |
|
137 void CTextToSpeechEngine::StopL() |
|
138 { |
|
139 iServer.StopL(); |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------------- |
|
143 // CTextToSpeechEngine::VolumeL |
|
144 // |
|
145 // ---------------------------------------------------------- |
|
146 // |
|
147 TInt CTextToSpeechEngine::VolumeL() |
|
148 { |
|
149 return iServer.VolumeL(); |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------------- |
|
153 // CTextToSpeechEngine::SetVolumeL |
|
154 // |
|
155 // ---------------------------------------------------------- |
|
156 // |
|
157 void CTextToSpeechEngine::SetVolumeL( TInt aVolume ) |
|
158 { |
|
159 iServer.SetVolumeL( aVolume ); |
|
160 } |
|
161 |
|
162 // ---------------------------------------------------------- |
|
163 // CTextToSpeechEngine::MaxVolumeL |
|
164 // |
|
165 // ---------------------------------------------------------- |
|
166 // |
|
167 TInt CTextToSpeechEngine::MaxVolumeL() |
|
168 { |
|
169 return iServer.MaxVolumeL(); |
|
170 } |
|
171 |
|
172 // ---------------------------------------------------------- |
|
173 // CTextToSpeechEngine::SpeakingRateL |
|
174 // |
|
175 // ---------------------------------------------------------- |
|
176 // |
|
177 TInt CTextToSpeechEngine::SpeakingRateL() |
|
178 { |
|
179 return iServer.SpeakingRateL(); |
|
180 } |
|
181 |
|
182 // ---------------------------------------------------------- |
|
183 // CTextToSpeechEngine::SetSpeakingRateL |
|
184 // |
|
185 // ---------------------------------------------------------- |
|
186 // |
|
187 void CTextToSpeechEngine::SetSpeakingRateL( TInt aRate ) |
|
188 { |
|
189 iServer.SetSpeakingRateL( aRate ); |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------- |
|
193 // CTextToSpeechEngine::MaxSpeakingRateL |
|
194 // |
|
195 // ---------------------------------------------------------- |
|
196 // |
|
197 TInt CTextToSpeechEngine::MaxSpeakingRateL() |
|
198 { |
|
199 return iServer.MaxSpeakingRateL(); |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------- |
|
203 // CTextToSpeechEngine::VoiceL |
|
204 // |
|
205 // ---------------------------------------------------------- |
|
206 // |
|
207 TVoice CTextToSpeechEngine::VoiceL() |
|
208 { |
|
209 return iServer.VoiceL(); |
|
210 } |
|
211 |
|
212 // ---------------------------------------------------------- |
|
213 // CTextToSpeechEngine::SetVoiceL |
|
214 // |
|
215 // ---------------------------------------------------------- |
|
216 // |
|
217 void CTextToSpeechEngine::SetVoiceL( const TVoice& aVoice ) |
|
218 { |
|
219 iServer.SetVoiceL( aVoice ); |
|
220 } |
|
221 |
|
222 // ---------------------------------------------------------- |
|
223 // CTextToSpeechEngine::GetLanguagesL |
|
224 // |
|
225 // ---------------------------------------------------------- |
|
226 // |
|
227 void CTextToSpeechEngine::GetLanguagesL( RArray<TLanguage>& aLanguages ) |
|
228 { |
|
229 iServer.GetLanguagesL( aLanguages ); |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------- |
|
233 // CTextToSpeechEngine::GetVoicesL |
|
234 // |
|
235 // ---------------------------------------------------------- |
|
236 // |
|
237 void CTextToSpeechEngine::GetVoicesL( RArray<TVoice>& aVoices, |
|
238 TLanguage aLanguage ) |
|
239 { |
|
240 iServer.GetVoicesL( aVoices, aLanguage ); |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------- |
|
244 // CTextToSpeechEngine::RunL |
|
245 // |
|
246 // ---------------------------------------------------------- |
|
247 // |
|
248 void CTextToSpeechEngine::RunL() |
|
249 { |
|
250 switch ( iState ) |
|
251 { |
|
252 case EPriming: |
|
253 |
|
254 if ( iStatus == KErrNone ) |
|
255 { |
|
256 Play(); |
|
257 } |
|
258 else |
|
259 { |
|
260 User::Leave( iStatus.Int() ); |
|
261 } |
|
262 |
|
263 break; |
|
264 |
|
265 case ESpeaking: |
|
266 |
|
267 if ( iStatus != KErrNone && iStatus != KErrCancel ) |
|
268 { |
|
269 User::Leave( iStatus.Int() ); |
|
270 } |
|
271 |
|
272 iState = EIdle; |
|
273 |
|
274 break; |
|
275 |
|
276 default: |
|
277 |
|
278 break; |
|
279 |
|
280 } |
|
281 } |
|
282 |
|
283 // ---------------------------------------------------------- |
|
284 // CTextToSpeechEngine::DoCancel |
|
285 // |
|
286 // ---------------------------------------------------------- |
|
287 // |
|
288 void CTextToSpeechEngine::DoCancel() |
|
289 { |
|
290 TRAP_IGNORE( iServer.StopL() ); |
|
291 } |
|
292 |
|
293 |
|
294 // End of File |
|