|
1 /* |
|
2 * Copyright (c) 2004 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: Algorithms for Speech Synthesis |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef TTSHWDEVICE_H |
|
23 #define TTSHWDEVICE_H |
|
24 |
|
25 // INCLUDES |
|
26 #include <e32std.h> |
|
27 #include <e32base.h> |
|
28 #include <nssttscommon.h> |
|
29 #include <asrshwdevice.h> |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class CTtsAlgorithm; |
|
33 |
|
34 // CLASS DECLARATION |
|
35 /** |
|
36 * Class to define callback functions |
|
37 * |
|
38 * @lib asrsttshwdevice.lib |
|
39 * @since 2.8 |
|
40 */ |
|
41 class MTtsHwDeviceObserver |
|
42 { |
|
43 public: // New functions |
|
44 |
|
45 /** |
|
46 * Called by the HW device when the synthesis has been completed. |
|
47 * @since 2.8 |
|
48 * @param aStatus Error code, KErrNone if success |
|
49 * @return none |
|
50 */ |
|
51 virtual void MthdTtsCompleted( TInt aStatus ) = 0; |
|
52 |
|
53 /** |
|
54 * Invoked by TTS HW Device when it needs a configuration data package. |
|
55 * @since 2.8 |
|
56 * @param aPackageType Type identifier. |
|
57 * @param aPackageID Identifier of package |
|
58 * @param aStartPosition Start index in bytes |
|
59 * @param aEndPosition End index in bytes. If the position is bigger |
|
60 * than the size of data package, the end part will be returned. |
|
61 * @return Data package in a buffer |
|
62 */ |
|
63 virtual HBufC8* MthdoConfigurationData( TUint32 aPackageType, |
|
64 TUint32 aPackageID, |
|
65 TUint32 aStartPosition, |
|
66 TUint32 aEndPosition) = 0; |
|
67 /** |
|
68 * Called by the HW device when custom command implementation wants to notify a client. |
|
69 * @since 2.8 |
|
70 * @param aEvent Event code aStatus Error code, KErrNone if success. |
|
71 * @param aParameter Optional parameter |
|
72 * @return none |
|
73 */ |
|
74 virtual void MthdCustomEvent( TInt aEvent, |
|
75 TInt aStatus, |
|
76 const TDesC8& aParameter = KNullDesC8 ) = 0; |
|
77 |
|
78 /** |
|
79 * Called by the HW device when the HW device has synthesized a new audio buffer. |
|
80 * @since 2.8 |
|
81 * @param aBuffer Synthesized audio buffer. |
|
82 * @return none |
|
83 */ |
|
84 virtual void MthdProcessBuffer( const TDesC8& aBuffer ) = 0; |
|
85 |
|
86 }; |
|
87 |
|
88 |
|
89 |
|
90 /** |
|
91 * Class to provide speech synthesis |
|
92 * |
|
93 * @lib asrsttshwdevice.lib |
|
94 * @since 2.8 |
|
95 */ |
|
96 class CTtsHwDevice : public CASRSHwDevice |
|
97 { |
|
98 public: // Constructors and destructor |
|
99 |
|
100 /** |
|
101 * Two-phased constructor. |
|
102 * @param aObserver Observer which implements callback functions. |
|
103 * @param aSamplingRate Sampling rate for output audio |
|
104 * @param aBufferSize Buffer size for output audio |
|
105 */ |
|
106 IMPORT_C static CTtsHwDevice* NewL( MTtsHwDeviceObserver& aObserver, |
|
107 TUint aSamplingRate, |
|
108 TUint aBufferSize ); |
|
109 |
|
110 /** |
|
111 * Destructor. |
|
112 */ |
|
113 IMPORT_C virtual ~CTtsHwDevice(); |
|
114 |
|
115 public: // New functions |
|
116 |
|
117 /** |
|
118 * Adds new style to the collection. If equal style exists already, new style is not added. |
|
119 * @since 2.8 |
|
120 * @param aStyle Style to be added. |
|
121 * @return Identifier of added style. If equal style exists already, identifier to the old style will be returned. |
|
122 */ |
|
123 IMPORT_C TTtsStyleID AddStyleL( const TTtsStyle& aStyle ); |
|
124 |
|
125 /** |
|
126 * Analyses stucture of text and adds style information. |
|
127 * @since 2.8 |
|
128 * @param aText Updates text object by dividing it into segments with new styles. |
|
129 * @return none |
|
130 */ |
|
131 IMPORT_C void AnalyzeProsodyL( CTtsParsedText& aText ); |
|
132 |
|
133 /** |
|
134 * Analyses stucture of text by finding paragraphs and sentences. |
|
135 * @since 2.8 |
|
136 * @param aText Updates text object by segmenting it into paragraphs and sentences. |
|
137 * @return none |
|
138 */ |
|
139 IMPORT_C void AnalyzeStructureL( CTtsParsedText& aText ); |
|
140 |
|
141 /** |
|
142 * Notifies that the buffer has been processed |
|
143 * @since 2.8 |
|
144 * @param aBuffer The buffer which has been processed |
|
145 * @return none |
|
146 */ |
|
147 IMPORT_C void BufferProcessed( const TDesC8& aBuffer ); |
|
148 |
|
149 /** |
|
150 * Deletes style. |
|
151 * @since 2.8 |
|
152 * @param aStyleID Identifier of style to be deleted. |
|
153 * @return none |
|
154 */ |
|
155 IMPORT_C void DeleteStyleL( TTtsStyleID aStyleID ); |
|
156 |
|
157 /** |
|
158 * Gives current position of synthesizing. |
|
159 * @since 2.8 |
|
160 * @param aTime Time of the synthesizing position. |
|
161 * @return none |
|
162 */ |
|
163 IMPORT_C void GetPositionL( TTimeIntervalMicroSeconds& aTime ); |
|
164 |
|
165 /** |
|
166 * Gives current position of synthesizing. |
|
167 * @since 2.8 |
|
168 * @param aSegment The segment being synthesizing |
|
169 * @param aWordIndex The index of word being synthesizing |
|
170 * @return none |
|
171 */ |
|
172 IMPORT_C void GetPositionL( TTtsSegment& aSegment, |
|
173 TInt& aWordIndex ); |
|
174 |
|
175 /** |
|
176 * Ask if a language is supported or not. |
|
177 * @since 2.8 |
|
178 * @param aLanguage Synthesizing language. |
|
179 * @return ETrue language is supported otherwise EFalse |
|
180 */ |
|
181 IMPORT_C TBool IsLanguageSupported( TLanguage aLanguage ); |
|
182 |
|
183 /** |
|
184 * Gives number of styles. |
|
185 * @since 2.8 |
|
186 * @param none |
|
187 * @return Number of styles. |
|
188 */ |
|
189 IMPORT_C TUint16 NumberOfStyles() const; |
|
190 |
|
191 /** |
|
192 * Pauses synthesizing. |
|
193 * @since 2.8 |
|
194 * @param none |
|
195 * @return none |
|
196 */ |
|
197 IMPORT_C void Pause(); |
|
198 |
|
199 /** |
|
200 * Prepares for synthesizing. |
|
201 * @since 2.8 |
|
202 * @param aStream Stream to be synthesized. |
|
203 * @return none |
|
204 */ |
|
205 IMPORT_C void PrimeSynthesisL( MTtsSegmentStream& aStream ); |
|
206 |
|
207 /** |
|
208 * Prepares for synthesizing. |
|
209 * @since 2.8 |
|
210 * @param aText Text containing segments to be synthesized. |
|
211 * @return none |
|
212 */ |
|
213 IMPORT_C void PrimeSynthesisL( CTtsParsedText& aText ); |
|
214 |
|
215 /** |
|
216 * Sets new position for synthesizing. |
|
217 * @since 2.8 |
|
218 * @param aTime Time of the synthesizing postion. |
|
219 * @return none |
|
220 */ |
|
221 IMPORT_C void SetPositionL( const TTimeIntervalMicroSeconds& aTime ); |
|
222 |
|
223 /** |
|
224 * Sets new position for synthesizing. |
|
225 * @since 2.8 |
|
226 * @param aSegment The segment being synthesizing |
|
227 * @param aWordIndex The index of word being synthesizing |
|
228 * @return none |
|
229 */ |
|
230 IMPORT_C void SetPositionL( const TTtsSegment& aSegment, |
|
231 TInt aWordIndex ); |
|
232 |
|
233 /** |
|
234 * Stops synthesizing and releases resources of synthesizing. |
|
235 * The method does nothing if already stopped. |
|
236 * @since 2.8 |
|
237 * @param |
|
238 * @return none |
|
239 */ |
|
240 IMPORT_C void Stop(); |
|
241 |
|
242 /** |
|
243 * Receives style information |
|
244 * @since 2.8 |
|
245 * @param aStyleID Style identifier |
|
246 * @return Style |
|
247 */ |
|
248 IMPORT_C TTtsStyle& StyleL( TTtsStyleID aStyleID ); |
|
249 |
|
250 /** |
|
251 * Receives style information |
|
252 * @since 2.8 |
|
253 * @param aIndex Index to style: 0..NumberOfStyles() |
|
254 * @return Style |
|
255 */ |
|
256 IMPORT_C TTtsStyle& StyleL( TUint16 aIndex ); |
|
257 |
|
258 /** |
|
259 * Starts waveform production. The synthesized audio buffers are send back |
|
260 * to client using MthdProcessBuffer(). |
|
261 * @since 2.8 |
|
262 * @param none |
|
263 * @return none |
|
264 */ |
|
265 IMPORT_C void SynthesizeL(); |
|
266 |
|
267 private: |
|
268 |
|
269 /** |
|
270 * C++ default constructor. |
|
271 */ |
|
272 CTtsHwDevice(); |
|
273 |
|
274 /** |
|
275 * By default Symbian 2nd phase constructor is private. |
|
276 */ |
|
277 void ConstructL( MTtsHwDeviceObserver& aObserver, |
|
278 TUint aSamplingRate, |
|
279 TUint aBufferSize ); |
|
280 |
|
281 private: // Data |
|
282 |
|
283 // Actual algorithm where all processing happens |
|
284 CTtsAlgorithm* iAlgorithm; |
|
285 |
|
286 // Reserved pointer for future extension |
|
287 TAny* iReserved; |
|
288 |
|
289 }; |
|
290 |
|
291 #endif // TTSHWDEVICE_H |
|
292 |
|
293 // End of File |