|
1 /* |
|
2 * Copyright (c) 2004-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: Implementations for CTtsControllerPluginBody methods. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <AudioPreference.h> |
|
21 #include <e32base.h> |
|
22 #include <mmfdes.h> |
|
23 #include <mmffile.h> |
|
24 #include <reent.h> |
|
25 #include <sysutil.h> |
|
26 #include <utf.h> |
|
27 |
|
28 #include "ttsplugin.h" |
|
29 #include "ttspluginbody.h" |
|
30 #include "ttsplugindataloader.h" |
|
31 #include "ttspluginresourcehandler.h" |
|
32 #include "rubydebug.h" |
|
33 #include "srsfbldvariant.hrh" |
|
34 |
|
35 // CONSTANTS |
|
36 // Playback state |
|
37 const TInt KPlay = 1; |
|
38 |
|
39 // Package types for general & language specific TTP data |
|
40 // const TUint32 KTtpGeneralDataPackageType = 1; |
|
41 const TUint32 KTtpLanguageDataPackageType = 0; |
|
42 const TUint32 KTtsDataPackageType = 2; |
|
43 |
|
44 // Header used to direct input to us from CMdaAudioPlayerUtility |
|
45 _LIT8( KTtsContentHeader, "(tts)" ); |
|
46 |
|
47 // TTS language can be set by adding "(l:lang_id)" to the beginning of descriptor |
|
48 // or file input. |
|
49 _LIT8( KTtsLanguageStartTag, "(l:" ); |
|
50 _LIT8( KTtsLanguageEndTag, ")" ); |
|
51 |
|
52 _LIT( KTextFileExtension, ".txt" ); |
|
53 |
|
54 const TInt KSamplingRate = 16000; // Hz |
|
55 |
|
56 // ============================ MEMBER FUNCTIONS =============================== |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CTtsControllerPluginBody::CTtsControllerPluginBody |
|
60 // C++ default constructor can NOT contain any code, that |
|
61 // might leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CTtsControllerPluginBody::CTtsControllerPluginBody( CTtsControllerPlugin* aObserver ) : |
|
65 CActive( CActive::EPriorityStandard ), |
|
66 iObserver( aObserver ), |
|
67 iTtsOutputMode( EDevTTSSoundDeviceMode ) |
|
68 { |
|
69 // Nothing |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CTtsControllerPluginBody::ConstructL |
|
74 // Symbian 2nd phase constructor can leave. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CTtsControllerPluginBody::ConstructL() |
|
78 { |
|
79 RUBY_DEBUG1( "CTtsControllerPluginBody::ConstructL [%x]", this ); |
|
80 |
|
81 User::LeaveIfError( iFs.Connect() ); |
|
82 |
|
83 // Loads resource file |
|
84 CTtsPluginResourceHandler* resourceHandler = |
|
85 CTtsPluginResourceHandler::NewL( iFs ); |
|
86 |
|
87 TFileName generalTTPFileName( *resourceHandler->iTtpGeneralFilename ); |
|
88 TFileName languageTTPFileName( *resourceHandler->iTtpLanguangeFilename ); |
|
89 TFileName postfixOfTTPFileName( *resourceHandler->iTtpFilenamePostfix ); |
|
90 TFileName TTSFileName( *resourceHandler->iTtsFilename ); |
|
91 TFileName postfixOfTTSFileName( *resourceHandler->iTtsFilenamePostfix ); |
|
92 |
|
93 delete resourceHandler; |
|
94 resourceHandler = NULL; |
|
95 |
|
96 // TTP Data loader |
|
97 iTtsLoader = CTTSDataLoader::NewL( iFs, |
|
98 generalTTPFileName, |
|
99 languageTTPFileName, |
|
100 postfixOfTTPFileName, |
|
101 TTSFileName, |
|
102 postfixOfTTSFileName ); |
|
103 |
|
104 // DevTTS |
|
105 iDevTts = CDevTTS::NewL( *this ); |
|
106 |
|
107 // Add default style to DevTTS |
|
108 iDefaultStyleID = iDevTts->AddStyleL( iDefaultStyle ); |
|
109 |
|
110 // Add ourselves to active scheduler |
|
111 CActiveScheduler::Add( this ); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CTtsControllerPluginBody::NewL |
|
116 // Two-phased constructor. |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 CTtsControllerPluginBody* CTtsControllerPluginBody::NewL( CTtsControllerPlugin* aObserver ) |
|
120 { |
|
121 CTtsControllerPluginBody* self = new( ELeave ) CTtsControllerPluginBody( aObserver ); |
|
122 |
|
123 CleanupStack::PushL( self ); |
|
124 self->ConstructL(); |
|
125 CleanupStack::Pop( self ); |
|
126 |
|
127 return self; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CTtsControllerPluginBody::~CTtsControllerPluginBody |
|
132 // Destructor. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 CTtsControllerPluginBody::~CTtsControllerPluginBody() |
|
136 { |
|
137 delete iParsedTextPointer; |
|
138 delete iDevTts; |
|
139 delete iTtsLoader; |
|
140 |
|
141 iFs.Close(); |
|
142 |
|
143 CloseSTDLIB(); |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CTtsControllerPluginBody::AddDataSourceL |
|
148 // Adds data suorce. |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CTtsControllerPluginBody::AddDataSourceL( MDataSource& aDataSource ) |
|
152 { |
|
153 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::AddDataSourceL" ); |
|
154 |
|
155 iEarlyPrimingDone = EFalse; |
|
156 |
|
157 // Check the source type |
|
158 if ( aDataSource.DataSourceType() == KUidMmfDescriptorSource ) |
|
159 { |
|
160 CMMFDescriptor* des = STATIC_CAST( CMMFDescriptor*, &aDataSource ); |
|
161 |
|
162 RUBY_DEBUG1( "Descriptor source detected, size: %x bytes", des->Size() ); |
|
163 |
|
164 // Copy data to CMMFDescriptorBuffer |
|
165 CMMFDescriptorBuffer* desBuf = CMMFDescriptorBuffer::NewL( des->Size() ); |
|
166 CleanupStack::PushL( desBuf ); |
|
167 des->ReadBufferL( desBuf, 0 ); |
|
168 |
|
169 // To 'normal' descriptor |
|
170 TDes8& descriptor = desBuf->Data(); |
|
171 |
|
172 RUBY_DEBUG1( "Created descriptor, size: %x", descriptor.Size() ); |
|
173 |
|
174 ConstructParsedTextL( descriptor ); |
|
175 |
|
176 CleanupStack::PopAndDestroy( desBuf ); |
|
177 |
|
178 DoEarlyPrimingL(); |
|
179 } |
|
180 else if ( aDataSource.DataSourceType() == KUidMmfFileSource ) |
|
181 { |
|
182 RUBY_DEBUG0( "File source detected" ); |
|
183 |
|
184 CMMFFile* mmfFile = STATIC_CAST( CMMFFile*, &aDataSource ); |
|
185 |
|
186 RUBY_DEBUG1( "Filename: %s", mmfFile->FullName().Ptr() ); |
|
187 |
|
188 // Check that correct filename extension is used |
|
189 if ( mmfFile->FullName().Find( KTextFileExtension ) == KErrNotFound ) |
|
190 { |
|
191 User::Leave( KErrNotSupported ); |
|
192 } |
|
193 |
|
194 // Open file first if not yet open |
|
195 mmfFile->SourcePrimeL(); |
|
196 RFile file( mmfFile->FileL() ); |
|
197 |
|
198 // Find the size of tts input file |
|
199 TInt fileSize( 0 ); |
|
200 User::LeaveIfError( file.Size( fileSize ) ); |
|
201 |
|
202 // Create buffer for data |
|
203 HBufC8* fileBuffer = HBufC8::NewLC( fileSize ); |
|
204 |
|
205 // Make sure we are in the beginnig of the file |
|
206 TInt tmp( 0 ); |
|
207 file.Seek( ESeekStart, tmp ); |
|
208 |
|
209 // Read data |
|
210 TPtr8 bufferPtr( fileBuffer->Des() ); |
|
211 User::LeaveIfError( file.Read( bufferPtr ) ); |
|
212 |
|
213 ConstructParsedTextL( bufferPtr ); |
|
214 |
|
215 // No need to store the 8-bit text |
|
216 CleanupStack::PopAndDestroy( fileBuffer ); |
|
217 |
|
218 DoEarlyPrimingL(); |
|
219 } |
|
220 else |
|
221 { |
|
222 RUBY_ERROR0( "Unknown source!" ); |
|
223 User::Leave( KErrNotSupported ); |
|
224 } |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CTtsControllerPluginBody::AddDataSinkL |
|
229 // Adds data sink. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 void CTtsControllerPluginBody::AddDataSinkL( MDataSink& aDataSink ) |
|
233 { |
|
234 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::AddDataSinkL" ); |
|
235 |
|
236 if ( aDataSink.DataSinkType() == KUidMmfAudioOutput ) |
|
237 { |
|
238 iTtsOutputMode = EDevTTSSoundDeviceMode; |
|
239 } |
|
240 else if ( aDataSink.DataSinkType() == KUidMmfFileSink ) |
|
241 { |
|
242 iTtsOutputMode = EDevTTSClientMode; |
|
243 |
|
244 CMMFFile* mmfFile = STATIC_CAST( CMMFFile*, &aDataSink ); |
|
245 |
|
246 mmfFile->SinkPrimeL(); |
|
247 iOutputFile = &mmfFile->FileL(); |
|
248 |
|
249 TDriveInfo driveInfo; |
|
250 User::LeaveIfError( iOutputFile->Drive( iOutFileDriveNumber, driveInfo ) ); |
|
251 } |
|
252 else |
|
253 { |
|
254 User::Leave( KErrNotSupported ); |
|
255 } |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CTtsControllerPluginBody::RemoveDataSourceL |
|
260 // Removes data source. |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 void CTtsControllerPluginBody::RemoveDataSourceL( MDataSource& /*aDataSource*/ ) |
|
264 { |
|
265 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::RemoveDataSourceL" ); |
|
266 User::Leave( KErrNotSupported ); |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CTtsControllerPluginBody::RemoveDataSinkL |
|
271 // Removes data sink. |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void CTtsControllerPluginBody::RemoveDataSinkL( MDataSink& /*aDataSink*/ ) |
|
275 { |
|
276 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::RemoveDataSinkL" ); |
|
277 |
|
278 if ( iOutputFile ) |
|
279 { |
|
280 iOutputFile->Close(); |
|
281 iOutputFile = NULL; |
|
282 } |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CTtsControllerPluginBody::ResetL |
|
287 // Resets plugin & DevTTS to starting state. |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CTtsControllerPluginBody::ResetL() |
|
291 { |
|
292 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::ResetL" ); |
|
293 |
|
294 iDevTts->Stop(); |
|
295 delete iDevTts; |
|
296 iDevTts = NULL; |
|
297 iDevTts = CDevTTS::NewL( *this ); |
|
298 |
|
299 // Add default style to DevTTS |
|
300 iDefaultStyleID = iDevTts->AddStyleL( iDefaultStyle ); |
|
301 |
|
302 delete iParsedTextPointer; |
|
303 iParsedTextPointer = NULL; |
|
304 iEarlyPrimingDone = EFalse; |
|
305 |
|
306 if ( iOutputFile ) |
|
307 { |
|
308 iOutputFile->Close(); |
|
309 iOutputFile = NULL; |
|
310 } |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CTtsControllerPluginBody::PrimeL |
|
315 // Initializes synthesis. |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 void CTtsControllerPluginBody::PrimeL() |
|
319 { |
|
320 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::PrimeL" ); |
|
321 TInt error( KErrNone ); |
|
322 |
|
323 if ( iEarlyPrimingDone ) |
|
324 { |
|
325 iEarlyPrimingDone = EFalse; |
|
326 } |
|
327 else |
|
328 { |
|
329 // Make sure that parsed text contains at least something to synthesize |
|
330 if ( iParsedTextPointer->Text() != KNullDesC || |
|
331 iParsedTextPointer->PhonemeSequence() != KNullDesC8 ) |
|
332 { |
|
333 TRAP( error, iDevTts->PrimeSynthesisL( *iParsedTextPointer ) ); |
|
334 } |
|
335 } |
|
336 iObserver->InitializationReady( error ); |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CTtsControllerPluginBody::DoEarlyPrimingL |
|
341 // Initializes synthesis. |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 void CTtsControllerPluginBody::DoEarlyPrimingL() |
|
345 { |
|
346 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::DoEarlyPrimingL" ); |
|
347 |
|
348 // Make sure that parsed text contains at least something to synthesize |
|
349 if ( iParsedTextPointer->Text() != KNullDesC || |
|
350 iParsedTextPointer->PhonemeSequence() != KNullDesC8 ) |
|
351 { |
|
352 iDevTts->PrimeSynthesisL( *iParsedTextPointer ); |
|
353 } |
|
354 iEarlyPrimingDone = ETrue; |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CTtsControllerPluginBody::PlayL |
|
359 // Starts playback. |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 void CTtsControllerPluginBody::PlayL() |
|
363 { |
|
364 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::PlayL" ); |
|
365 |
|
366 if ( IsActive() ) |
|
367 { |
|
368 User::Leave( KErrServerBusy ); |
|
369 } |
|
370 |
|
371 iRequestFunction = KPlay; |
|
372 Ready(); |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CTtsControllerPluginBody::HandlePlay |
|
377 // Async handler for play |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 void CTtsControllerPluginBody::HandlePlay() |
|
381 { |
|
382 // Make sure that parsed text contains at least something to synthesize |
|
383 if ( iParsedTextPointer->Text() != KNullDesC || |
|
384 iParsedTextPointer->PhonemeSequence() != KNullDesC8 ) |
|
385 { |
|
386 |
|
387 TRAPD( error, iDevTts->SynthesizeL( iTtsOutputMode ) ); |
|
388 // Do client callback now if leave happens, otherwise wait for the callback |
|
389 // from DevTTS |
|
390 if ( error != KErrNone ) |
|
391 { |
|
392 // Try if we can get rid of the problem by first doing initialization |
|
393 TRAP( error, iDevTts->PrimeSynthesisL( *iParsedTextPointer ) ); |
|
394 if ( error != KErrNone ) |
|
395 { |
|
396 iObserver->SynthesisReady( error ); |
|
397 } |
|
398 // Then try to start synthesis again |
|
399 TRAP( error, iDevTts->SynthesizeL( iTtsOutputMode ) ); |
|
400 if ( error != KErrNone ) |
|
401 { |
|
402 iDevTts->Stop(); |
|
403 iObserver->SynthesisReady( error ); |
|
404 } |
|
405 } |
|
406 } |
|
407 else |
|
408 { |
|
409 iObserver->SynthesisReady( KErrNone ); |
|
410 } |
|
411 } |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // CTtsControllerPluginBody::PauseL |
|
415 // Pauses playback & synthesis. |
|
416 // ----------------------------------------------------------------------------- |
|
417 // |
|
418 void CTtsControllerPluginBody::PauseL() |
|
419 { |
|
420 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::PauseL" ); |
|
421 |
|
422 iDevTts->Pause(); |
|
423 } |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CTtsControllerPluginBody::StopL |
|
427 // Stops playback & synthesis. |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void CTtsControllerPluginBody::StopL() |
|
431 { |
|
432 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::StopL" ); |
|
433 iEarlyPrimingDone = EFalse; |
|
434 iDevTts->Stop(); |
|
435 |
|
436 if ( iOutputFile ) |
|
437 { |
|
438 iOutputFile->Close(); |
|
439 iOutputFile = NULL; |
|
440 } |
|
441 } |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CTtsControllerPluginBody::PositionL |
|
445 // Returns the current playback position in microseconds. |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 TTimeIntervalMicroSeconds CTtsControllerPluginBody::PositionL() const |
|
449 { |
|
450 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::PositionL" ); |
|
451 |
|
452 TTimeIntervalMicroSeconds time( 0 ); |
|
453 |
|
454 iDevTts->GetPositionL( time ); |
|
455 |
|
456 return time; |
|
457 } |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // CTtsControllerPluginBody::SetPositionL |
|
461 // Sets the playback position. |
|
462 // ----------------------------------------------------------------------------- |
|
463 // |
|
464 void CTtsControllerPluginBody::SetPositionL( const TTimeIntervalMicroSeconds& /*aPosition*/ ) |
|
465 { |
|
466 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::SetPositionL" ); |
|
467 // @todo Remove from comments when DevTTS does not anymore return |
|
468 // KErrNotSupported |
|
469 // iDevTts->SetPositionL( aPosition ); |
|
470 } |
|
471 |
|
472 // ----------------------------------------------------------------------------- |
|
473 // CTtsControllerPluginBody::DurationL |
|
474 // Returns duration of synthesized output. |
|
475 // ----------------------------------------------------------------------------- |
|
476 // |
|
477 TTimeIntervalMicroSeconds CTtsControllerPluginBody::DurationL() const |
|
478 { |
|
479 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::DurationL" ); |
|
480 |
|
481 TTimeIntervalMicroSeconds duration( 0 ); |
|
482 |
|
483 if ( iParsedTextPointer ) |
|
484 { |
|
485 // Count overall duration |
|
486 for ( TInt i = 0; i < iParsedTextPointer->NumberOfSegments(); i++ ) |
|
487 { |
|
488 TTtsSegment segment = iParsedTextPointer->SegmentL( i ); |
|
489 TTtsStyleID styleID = segment.StyleID(); |
|
490 TTtsStyle style = iDevTts->StyleL( styleID ); |
|
491 duration = duration.Int64() + style.iDuration.Int(); |
|
492 } |
|
493 } |
|
494 |
|
495 return duration; |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CTtsControllerPluginBody::SetPrioritySettings |
|
500 // Sets the playback priority. |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 void CTtsControllerPluginBody::SetPrioritySettings( const TMMFPrioritySettings& aPrioritySettings ) |
|
504 { |
|
505 RUBY_DEBUG0( "CTtsControllerPluginBody::SetPrioritySettings" ); |
|
506 |
|
507 iDevTts->SetAudioPriority( aPrioritySettings.iPriority, |
|
508 (TDevTTSAudioPreference)aPrioritySettings.iPref ); |
|
509 } |
|
510 |
|
511 // ----------------------------------------------------------------------------- |
|
512 // CTtsControllerPluginBody::CustomCommand |
|
513 // One supported custom command at the moment. |
|
514 // ----------------------------------------------------------------------------- |
|
515 // |
|
516 void CTtsControllerPluginBody::CustomCommand( TMMFMessage& aMessage ) |
|
517 { |
|
518 RUBY_DEBUG0( "CTtsControllerPluginBody::CustomCommand" ); |
|
519 |
|
520 TInt result( KErrNone ); |
|
521 |
|
522 if ( aMessage.Function() == ETtsCustomCommandSetAudioOutput ) |
|
523 { |
|
524 TBuf8<2> data; |
|
525 |
|
526 if ( aMessage.SizeOfData1FromClient() <= 2 && |
|
527 aMessage.ReadData1FromClient( data ) == KErrNone ) |
|
528 { |
|
529 TLex8 parser( data ); |
|
530 |
|
531 TInt newOutput; |
|
532 result = parser.Val( newOutput ); |
|
533 |
|
534 if ( result == KErrNone ) |
|
535 { |
|
536 TRAP( result, iDevTts->SetAudioOutputL( newOutput) ); |
|
537 } |
|
538 } |
|
539 else |
|
540 { |
|
541 result = KErrArgument; |
|
542 } |
|
543 } |
|
544 else |
|
545 { |
|
546 result = KErrNotSupported; |
|
547 } |
|
548 |
|
549 aMessage.Complete( result ); |
|
550 } |
|
551 |
|
552 // ----------------------------------------------------------------------------- |
|
553 // CTtsControllerPluginBody::GetNumberOfMetaDataEntriesL |
|
554 // Not supported. |
|
555 // ----------------------------------------------------------------------------- |
|
556 // |
|
557 void CTtsControllerPluginBody::GetNumberOfMetaDataEntriesL( TInt& /*aNumberOfEntries*/ ) |
|
558 { |
|
559 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::GetNumberOfMetaDataEntriesL" ); |
|
560 |
|
561 User::Leave( KErrNotSupported ); |
|
562 } |
|
563 |
|
564 // ----------------------------------------------------------------------------- |
|
565 // CTtsControllerPluginBody::GetMetaDataEntryL |
|
566 // Not supported. |
|
567 // ----------------------------------------------------------------------------- |
|
568 // |
|
569 CMMFMetaDataEntry* CTtsControllerPluginBody::GetMetaDataEntryL( TInt /*aIndex*/ ) |
|
570 { |
|
571 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::GetMetaDataEntryL" ); |
|
572 |
|
573 User::Leave( KErrNotSupported ); |
|
574 return NULL; |
|
575 } |
|
576 |
|
577 // ----------------------------------------------------------------------------- |
|
578 // CTtsControllerPluginBody::MacSetSourceSampleRateL |
|
579 // Leaves with value KErrNotSupported. |
|
580 // ----------------------------------------------------------------------------- |
|
581 // |
|
582 void CTtsControllerPluginBody::MacSetSourceSampleRateL( TUint /*aSampleRate*/ ) |
|
583 { |
|
584 User::Leave( KErrNotSupported ); |
|
585 } |
|
586 |
|
587 // ----------------------------------------------------------------------------- |
|
588 // CTtsControllerPluginBody::MacSetSourceBitRateL |
|
589 // Leaves with value KErrNotSupported. |
|
590 // ----------------------------------------------------------------------------- |
|
591 // |
|
592 void CTtsControllerPluginBody::MacSetSourceBitRateL( TUint /*aBitRate*/ ) |
|
593 { |
|
594 User::Leave( KErrNotSupported ); |
|
595 } |
|
596 |
|
597 // ----------------------------------------------------------------------------- |
|
598 // CTtsControllerPluginBody::MacSetSourceNumChannelsL |
|
599 // Leaves with value KErrNotSupported. |
|
600 // ----------------------------------------------------------------------------- |
|
601 // |
|
602 void CTtsControllerPluginBody::MacSetSourceNumChannelsL( TUint /*aNumChannels*/ ) |
|
603 { |
|
604 User::Leave( KErrNotSupported ); |
|
605 } |
|
606 |
|
607 // ----------------------------------------------------------------------------- |
|
608 // CTtsControllerPluginBody::MacSetSourceFormatL |
|
609 // Leaves with value KErrNotSupported. |
|
610 // ----------------------------------------------------------------------------- |
|
611 // |
|
612 void CTtsControllerPluginBody::MacSetSourceFormatL( TUid /*aFormatUid*/ ) |
|
613 { |
|
614 User::Leave( KErrNotSupported ); |
|
615 } |
|
616 |
|
617 // ----------------------------------------------------------------------------- |
|
618 // CTtsControllerPluginBody::MacSetSourceDataTypeL |
|
619 // Leaves with value KErrNotSupported. |
|
620 // ----------------------------------------------------------------------------- |
|
621 // |
|
622 void CTtsControllerPluginBody::MacSetSourceDataTypeL( TFourCC /*aDataType*/ ) |
|
623 { |
|
624 User::Leave( KErrNotSupported ); |
|
625 } |
|
626 |
|
627 // ----------------------------------------------------------------------------- |
|
628 // CTtsControllerPluginBody::MacSetSinkSampleRateL |
|
629 // Leaves with value KErrNotSupported. |
|
630 // ----------------------------------------------------------------------------- |
|
631 // |
|
632 void CTtsControllerPluginBody::MacSetSinkSampleRateL( TUint /*aSampleRate*/ ) |
|
633 { |
|
634 User::Leave( KErrNotSupported ); |
|
635 } |
|
636 |
|
637 // ----------------------------------------------------------------------------- |
|
638 // CTtsControllerPluginBody::MacSetSinkBitRateL |
|
639 // Leaves with value KErrNotSupported. |
|
640 // ----------------------------------------------------------------------------- |
|
641 // |
|
642 void CTtsControllerPluginBody::MacSetSinkBitRateL( TUint /*aRate*/ ) |
|
643 { |
|
644 User::Leave( KErrNotSupported ); |
|
645 } |
|
646 |
|
647 // ----------------------------------------------------------------------------- |
|
648 // CTtsControllerPluginBody::MacSetSinkNumChannelsL |
|
649 // Leaves with value KErrNotSupported. |
|
650 // ----------------------------------------------------------------------------- |
|
651 // |
|
652 void CTtsControllerPluginBody::MacSetSinkNumChannelsL( TUint /*aNumChannels*/ ) |
|
653 { |
|
654 User::Leave( KErrNotSupported ); |
|
655 } |
|
656 |
|
657 // ----------------------------------------------------------------------------- |
|
658 // CTtsControllerPluginBody::MacSetSinkFormatL |
|
659 // Leaves with value KErrNotSupported. |
|
660 // ----------------------------------------------------------------------------- |
|
661 // |
|
662 void CTtsControllerPluginBody::MacSetSinkFormatL( TUid /*aFormatUid*/ ) |
|
663 { |
|
664 User::Leave( KErrNotSupported ); |
|
665 } |
|
666 |
|
667 // ----------------------------------------------------------------------------- |
|
668 // CTtsControllerPluginBody::MacSetSinkDataTypeL |
|
669 // Leaves with value KErrNotSupported. |
|
670 // ----------------------------------------------------------------------------- |
|
671 // |
|
672 void CTtsControllerPluginBody::MacSetSinkDataTypeL( TFourCC /*aDataType*/ ) |
|
673 { |
|
674 User::Leave( KErrNotSupported ); |
|
675 } |
|
676 |
|
677 // ----------------------------------------------------------------------------- |
|
678 // CTtsControllerPluginBody::MacSetCodecL |
|
679 // Leaves with value KErrNotSupported. |
|
680 // ----------------------------------------------------------------------------- |
|
681 // |
|
682 void CTtsControllerPluginBody::MacSetCodecL( TFourCC /*aSourceDataType*/, TFourCC /*aSinkDataType*/ ) |
|
683 { |
|
684 User::Leave( KErrNotSupported ); |
|
685 } |
|
686 |
|
687 |
|
688 // ----------------------------------------------------------------------------- |
|
689 // CTtsControllerPluginBody::MacGetSourceSampleRateL |
|
690 // Leaves with value KErrNotSupported. |
|
691 // ----------------------------------------------------------------------------- |
|
692 // |
|
693 void CTtsControllerPluginBody::MacGetSourceSampleRateL( TUint& /*aRate*/ ) |
|
694 { |
|
695 User::Leave( KErrNotSupported ); |
|
696 } |
|
697 |
|
698 // ----------------------------------------------------------------------------- |
|
699 // CTtsControllerPluginBody::MacGetSourceBitRateL |
|
700 // Leaves with value KErrNotSupported. |
|
701 // ----------------------------------------------------------------------------- |
|
702 // |
|
703 void CTtsControllerPluginBody::MacGetSourceBitRateL( TUint& /*aRate*/ ) |
|
704 { |
|
705 User::Leave( KErrNotSupported ); |
|
706 } |
|
707 |
|
708 // ----------------------------------------------------------------------------- |
|
709 // CTtsControllerPluginBody::MacGetSourceNumChannelsL |
|
710 // Leaves with value KErrNotSupported. |
|
711 // ----------------------------------------------------------------------------- |
|
712 // |
|
713 void CTtsControllerPluginBody::MacGetSourceNumChannelsL( TUint& /*aNumChannels*/ ) |
|
714 { |
|
715 User::Leave( KErrNotSupported ); |
|
716 } |
|
717 |
|
718 // ----------------------------------------------------------------------------- |
|
719 // CTtsControllerPluginBody::MacGetSourceFormatL |
|
720 // Leaves with value KErrNotSupported. |
|
721 // ----------------------------------------------------------------------------- |
|
722 // |
|
723 void CTtsControllerPluginBody::MacGetSourceFormatL( TUid& /*aFormat*/ ) |
|
724 { |
|
725 User::Leave( KErrNotSupported ); |
|
726 } |
|
727 |
|
728 // ----------------------------------------------------------------------------- |
|
729 // CTtsControllerPluginBody::MacGetSourceDataTypeL |
|
730 // Leaves with value KErrNotSupported. |
|
731 // ----------------------------------------------------------------------------- |
|
732 // |
|
733 void CTtsControllerPluginBody::MacGetSourceDataTypeL( TFourCC& /*aDataType*/ ) |
|
734 { |
|
735 User::Leave( KErrNotSupported ); |
|
736 } |
|
737 |
|
738 // ----------------------------------------------------------------------------- |
|
739 // CTtsControllerPluginBody::MacGetSinkSampleRateL |
|
740 // Leaves with value KErrNotSupported. |
|
741 // ----------------------------------------------------------------------------- |
|
742 // |
|
743 void CTtsControllerPluginBody::MacGetSinkSampleRateL( TUint& /*aRate*/ ) |
|
744 { |
|
745 User::Leave( KErrNotSupported ); |
|
746 } |
|
747 |
|
748 // ----------------------------------------------------------------------------- |
|
749 // CTtsControllerPluginBody::MacGetSinkBitRateL |
|
750 // Leaves with value KErrNotSupported. |
|
751 // ----------------------------------------------------------------------------- |
|
752 // |
|
753 void CTtsControllerPluginBody::MacGetSinkBitRateL( TUint& /*aRate*/ ) |
|
754 { |
|
755 User::Leave( KErrNotSupported ); |
|
756 } |
|
757 |
|
758 // ----------------------------------------------------------------------------- |
|
759 // CTtsControllerPluginBody::MacGetSinkNumChannelsL |
|
760 // Leaves with value KErrNotSupported. |
|
761 // ----------------------------------------------------------------------------- |
|
762 // |
|
763 void CTtsControllerPluginBody::MacGetSinkNumChannelsL( TUint& /*aNumChannels*/ ) |
|
764 { |
|
765 User::Leave( KErrNotSupported ); |
|
766 } |
|
767 |
|
768 // ----------------------------------------------------------------------------- |
|
769 // CTtsControllerPluginBody::MacGetSinkFormatL |
|
770 // Leaves with value KErrNotSupported. |
|
771 // ----------------------------------------------------------------------------- |
|
772 // |
|
773 void CTtsControllerPluginBody::MacGetSinkFormatL( TUid& /*aFormat*/ ) |
|
774 { |
|
775 User::Leave( KErrNotSupported ); |
|
776 } |
|
777 |
|
778 // ----------------------------------------------------------------------------- |
|
779 // CTtsControllerPluginBody::MacGetSinkDataTypeL |
|
780 // Leaves with value KErrNotSupported. |
|
781 // ----------------------------------------------------------------------------- |
|
782 // |
|
783 void CTtsControllerPluginBody::MacGetSinkDataTypeL( TFourCC& /*aDataType*/ ) |
|
784 { |
|
785 User::Leave( KErrNotSupported ); |
|
786 } |
|
787 |
|
788 // ----------------------------------------------------------------------------- |
|
789 // CTtsControllerPluginBody::MacGetSupportedSourceSampleRatesL |
|
790 // Leaves with value KErrNotSupported. |
|
791 // ----------------------------------------------------------------------------- |
|
792 // |
|
793 void CTtsControllerPluginBody::MacGetSupportedSourceSampleRatesL( RArray<TUint>& /*aSupportedRates*/ ) |
|
794 { |
|
795 User::Leave( KErrNotSupported ); |
|
796 } |
|
797 |
|
798 // ----------------------------------------------------------------------------- |
|
799 // CTtsControllerPluginBody::MacGetSupportedSourceBitRatesL |
|
800 // Leaves with value KErrNotSupported. |
|
801 // ----------------------------------------------------------------------------- |
|
802 // |
|
803 void CTtsControllerPluginBody::MacGetSupportedSourceBitRatesL( RArray<TUint>& /*aSupportedRates*/ ) |
|
804 { |
|
805 User::Leave( KErrNotSupported ); |
|
806 } |
|
807 |
|
808 // ----------------------------------------------------------------------------- |
|
809 // CTtsControllerPluginBody::MacGetSupportedSourceNumChannelsL |
|
810 // Leaves with value KErrNotSupported. |
|
811 // ----------------------------------------------------------------------------- |
|
812 // |
|
813 void CTtsControllerPluginBody::MacGetSupportedSourceNumChannelsL( RArray<TUint>& /*aSupportedChannels*/ ) |
|
814 { |
|
815 User::Leave( KErrNotSupported ); |
|
816 } |
|
817 |
|
818 // ----------------------------------------------------------------------------- |
|
819 // CTtsControllerPluginBody::MacGetSupportedSourceDataTypesL |
|
820 // Leaves with value KErrNotSupported. |
|
821 // ----------------------------------------------------------------------------- |
|
822 // |
|
823 void CTtsControllerPluginBody::MacGetSupportedSourceDataTypesL( RArray<TFourCC>& /*aSupportedDataTypes*/ ) |
|
824 { |
|
825 User::Leave( KErrNotSupported ); |
|
826 } |
|
827 |
|
828 // ----------------------------------------------------------------------------- |
|
829 // CTtsControllerPluginBody::MacGetSupportedSinkSampleRatesL |
|
830 // Leaves with value KErrNotSupported. |
|
831 // ----------------------------------------------------------------------------- |
|
832 // |
|
833 void CTtsControllerPluginBody::MacGetSupportedSinkSampleRatesL( RArray<TUint>& /*aSupportedRates*/) |
|
834 { |
|
835 User::Leave( KErrNotSupported ); |
|
836 } |
|
837 |
|
838 // ----------------------------------------------------------------------------- |
|
839 // CTtsControllerPluginBody::MacGetSupportedSinkBitRatesL |
|
840 // Leaves with value KErrNotSupported. |
|
841 // ----------------------------------------------------------------------------- |
|
842 // |
|
843 void CTtsControllerPluginBody::MacGetSupportedSinkBitRatesL( RArray<TUint>& /*aSupportedRates*/) |
|
844 { |
|
845 User::Leave( KErrNotSupported ); |
|
846 } |
|
847 |
|
848 // ----------------------------------------------------------------------------- |
|
849 // CTtsControllerPluginBody::MacGetSupportedSinkNumChannelsL |
|
850 // Leaves with value KErrNotSupported. |
|
851 // ----------------------------------------------------------------------------- |
|
852 // |
|
853 void CTtsControllerPluginBody::MacGetSupportedSinkNumChannelsL( RArray<TUint>& /*aSupportedChannels*/ ) |
|
854 { |
|
855 User::Leave( KErrNotSupported ); |
|
856 } |
|
857 |
|
858 // ----------------------------------------------------------------------------- |
|
859 // CTtsControllerPluginBody::MacGetSupportedSinkDataTypesL |
|
860 // Leaves with value KErrNotSupported. |
|
861 // ----------------------------------------------------------------------------- |
|
862 // |
|
863 void CTtsControllerPluginBody::MacGetSupportedSinkDataTypesL( RArray<TFourCC>& /*aSupportedDataTypes*/ ) |
|
864 { |
|
865 User::Leave( KErrNotSupported ); |
|
866 } |
|
867 |
|
868 |
|
869 // ----------------------------------------------------------------------------- |
|
870 // CTtsControllerPluginBody::MapdSetVolumeL |
|
871 // Sets playback volume. |
|
872 // ----------------------------------------------------------------------------- |
|
873 // |
|
874 void CTtsControllerPluginBody::MapdSetVolumeL( TInt aVolume ) |
|
875 { |
|
876 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MapdSetVolumeL" ); |
|
877 |
|
878 iDevTts->SetVolume( aVolume ); |
|
879 } |
|
880 |
|
881 // ----------------------------------------------------------------------------- |
|
882 // CTtsControllerPluginBody::MapdGetMaxVolumeL |
|
883 // Returns the maximum volume setting. |
|
884 // ----------------------------------------------------------------------------- |
|
885 // |
|
886 void CTtsControllerPluginBody::MapdGetMaxVolumeL( TInt& aMaxVolume ) |
|
887 { |
|
888 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MapdGetMaxVolumeL" ); |
|
889 |
|
890 aMaxVolume = iDevTts->MaxVolume(); |
|
891 } |
|
892 |
|
893 // ----------------------------------------------------------------------------- |
|
894 // CTtsControllerPluginBody::MapdGetVolumeL |
|
895 // Returns the current volume. |
|
896 // ----------------------------------------------------------------------------- |
|
897 // |
|
898 void CTtsControllerPluginBody::MapdGetVolumeL( TInt& aVolume ) |
|
899 { |
|
900 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MapdGetVolumeL" ); |
|
901 |
|
902 aVolume = iDevTts->Volume(); |
|
903 } |
|
904 |
|
905 // ----------------------------------------------------------------------------- |
|
906 // CTtsControllerPluginBody::MapdSetVolumeRampL |
|
907 // Sets volume ramp time. |
|
908 // ----------------------------------------------------------------------------- |
|
909 // |
|
910 void CTtsControllerPluginBody::MapdSetVolumeRampL( const TTimeIntervalMicroSeconds& aRampDuration ) |
|
911 { |
|
912 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MapdSetVolumeRampL" ); |
|
913 |
|
914 iDevTts->SetVolumeRamp( aRampDuration ); |
|
915 } |
|
916 |
|
917 // ----------------------------------------------------------------------------- |
|
918 // CTtsControllerPluginBody::MapdSetBalanceL |
|
919 // Sets playback balance. |
|
920 // ----------------------------------------------------------------------------- |
|
921 // |
|
922 void CTtsControllerPluginBody::MapdSetBalanceL( TInt aBalance ) |
|
923 { |
|
924 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MapdSetBalanceL" ); |
|
925 |
|
926 iDevTts->SetBalance( aBalance ); |
|
927 } |
|
928 |
|
929 // ----------------------------------------------------------------------------- |
|
930 // CTtsControllerPluginBody::MapdGetBalanceL |
|
931 // Returns current balance setting. |
|
932 // ----------------------------------------------------------------------------- |
|
933 // |
|
934 void CTtsControllerPluginBody::MapdGetBalanceL( TInt& aBalance ) |
|
935 { |
|
936 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MapdGetBalanceL" ); |
|
937 |
|
938 aBalance = iDevTts->Balance(); |
|
939 } |
|
940 |
|
941 // ================= FUNCTIONS FROM MDevTTSObserver start ====================== |
|
942 |
|
943 |
|
944 // ----------------------------------------------------------------------------- |
|
945 // CTtsControllerPluginBody::MdtoConfigurationData |
|
946 // Called when DevTTS needs data. |
|
947 // ----------------------------------------------------------------------------- |
|
948 // |
|
949 HBufC8* CTtsControllerPluginBody::MdtoConfigurationData( TUint32 aPackageType, |
|
950 TUint32 aPackageID, |
|
951 TUint32 aStartPosition, |
|
952 TUint32 aEndPosition ) |
|
953 { |
|
954 RUBY_DEBUG2( "CTtsControllerPluginBody::MdtoConfigurationData [%d][%d]", aPackageType, aPackageID ); |
|
955 |
|
956 if ( aPackageType == KTtpLanguageDataPackageType ) |
|
957 { |
|
958 return iTtsLoader->LoadLanguageData( aPackageType, (TLanguage)aPackageID, |
|
959 aStartPosition, aEndPosition ); |
|
960 } |
|
961 else if ( aPackageType == KTtsDataPackageType ) |
|
962 { |
|
963 return iTtsLoader->LoadTtsData( aPackageType, aPackageID, |
|
964 aStartPosition, aEndPosition ); |
|
965 } |
|
966 else |
|
967 { |
|
968 return iTtsLoader->LoadGeneralData( aPackageType, aPackageID, |
|
969 aStartPosition, aEndPosition ); |
|
970 } |
|
971 } |
|
972 |
|
973 // ----------------------------------------------------------------------------- |
|
974 // CTtsControllerPluginBody::MdtoEvent |
|
975 // Called when synthesis has ended. |
|
976 // ----------------------------------------------------------------------------- |
|
977 // |
|
978 void CTtsControllerPluginBody::MdtoEvent( TDevTTSEvent aEvent, TInt aStatus ) |
|
979 { |
|
980 RUBY_DEBUG2( "CTtsControllerPluginBody::MdtoEvent [%d][%d]", aEvent, aStatus ); |
|
981 |
|
982 switch ( aEvent ) |
|
983 { |
|
984 case EDevTTSEventComplete: |
|
985 |
|
986 if ( iOutputFile ) |
|
987 { |
|
988 iOutputFile->Close(); |
|
989 iOutputFile = NULL; |
|
990 } |
|
991 |
|
992 // Call the upper level |
|
993 iObserver->SynthesisReady( aStatus ); |
|
994 break; |
|
995 |
|
996 default: |
|
997 break; |
|
998 } |
|
999 } |
|
1000 |
|
1001 // ----------------------------------------------------------------------------- |
|
1002 // CTtsControllerPluginBody::MdtoProcessBuffer |
|
1003 // Called when synthesis is directed to file and the next output buffer is ready. |
|
1004 // ----------------------------------------------------------------------------- |
|
1005 // |
|
1006 void CTtsControllerPluginBody::MdtoProcessBuffer( const TDesC8& aBuffer ) |
|
1007 { |
|
1008 RUBY_DEBUG0( "CTtsControllerPluginBody::MdtoProcessBuffer" ); |
|
1009 |
|
1010 TInt error( KErrCorrupt ); |
|
1011 |
|
1012 if ( iOutputFile ) |
|
1013 { |
|
1014 TBool diskFull( EFalse ); |
|
1015 |
|
1016 TRAP( error, diskFull = |
|
1017 SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aBuffer.Size(), |
|
1018 iOutFileDriveNumber ) ); |
|
1019 if ( !error ) |
|
1020 { |
|
1021 if ( diskFull ) |
|
1022 { |
|
1023 error = KErrDiskFull; |
|
1024 } |
|
1025 else |
|
1026 { |
|
1027 error = iOutputFile->Write( aBuffer ); |
|
1028 } |
|
1029 } |
|
1030 } |
|
1031 |
|
1032 if ( error ) |
|
1033 { |
|
1034 RUBY_ERROR1( "CTtsControllerPluginBody::MdtoProcessBuffer - Write failed with %d", |
|
1035 error ); |
|
1036 |
|
1037 // Stop synthesis |
|
1038 TRAP_IGNORE( StopL() ); |
|
1039 |
|
1040 // Inform observer we don't continue |
|
1041 iObserver->SynthesisReady( error ); |
|
1042 } |
|
1043 |
|
1044 // We are ready to receive the next buffer. |
|
1045 iDevTts->BufferProcessed( aBuffer ); |
|
1046 } |
|
1047 |
|
1048 // ================== FUNCTIONS FROM MDevTTSObserver end ======================= |
|
1049 |
|
1050 |
|
1051 // ----------------------------------------------------------------------------- |
|
1052 // CTtsControllerPluginBody::MttscAddStyleL |
|
1053 // Adds a new style to style collection. |
|
1054 // ----------------------------------------------------------------------------- |
|
1055 // |
|
1056 TTtsStyleID CTtsControllerPluginBody::MttscAddStyleL( const TTtsStyle& aStyle ) |
|
1057 { |
|
1058 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscAddStyleL" ); |
|
1059 |
|
1060 return iDevTts->AddStyleL( aStyle ); |
|
1061 } |
|
1062 |
|
1063 // ----------------------------------------------------------------------------- |
|
1064 // CTtsControllerPluginBody::MttscDeleteStyle |
|
1065 // Removes style from style collection. |
|
1066 // ----------------------------------------------------------------------------- |
|
1067 // |
|
1068 TInt CTtsControllerPluginBody::MttscDeleteStyle( TTtsStyleID aID ) |
|
1069 { |
|
1070 RUBY_DEBUG0( "CTtsControllerPluginBody::MttscDeleteStyle" ); |
|
1071 |
|
1072 TRAPD( error, iDevTts->DeleteStyleL( aID ) ); |
|
1073 return error; |
|
1074 } |
|
1075 |
|
1076 // ----------------------------------------------------------------------------- |
|
1077 // CTtsControllerPluginBody::MttscGetPositionL |
|
1078 // Returns current synthesis position in words. |
|
1079 // ----------------------------------------------------------------------------- |
|
1080 // |
|
1081 void CTtsControllerPluginBody::MttscGetPositionL( TInt& /*aWordIndex*/ ) |
|
1082 { |
|
1083 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscGetPositionL" ); |
|
1084 |
|
1085 // @todo DevTTS wants this starting from the beginning of segment |
|
1086 // iDevTts->GetPositionL( aWordIndex ); |
|
1087 } |
|
1088 |
|
1089 // ----------------------------------------------------------------------------- |
|
1090 // CTtsControllerPluginBody::MttscNumberOfStyles |
|
1091 // Returns number of registered styles. |
|
1092 // ----------------------------------------------------------------------------- |
|
1093 // |
|
1094 TUint16 CTtsControllerPluginBody::MttscNumberOfStyles() |
|
1095 { |
|
1096 RUBY_DEBUG0( "CTtsControllerPluginBody::MttscNumberOfStyles" ); |
|
1097 |
|
1098 return iDevTts->NumberOfStyles(); |
|
1099 } |
|
1100 |
|
1101 // ----------------------------------------------------------------------------- |
|
1102 // CTtsControllerPluginBody::MttscOpenParsedTextL |
|
1103 // Opens parsed text object as source. |
|
1104 // ----------------------------------------------------------------------------- |
|
1105 // |
|
1106 void CTtsControllerPluginBody::MttscOpenParsedTextL( CTtsParsedText& aText ) |
|
1107 { |
|
1108 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscOpenParsedTextL" ); |
|
1109 |
|
1110 // Go through styles inside the parsed text |
|
1111 for ( TInt i = 0; i < aText.NumberOfSegments(); i++ ) |
|
1112 { |
|
1113 TTtsSegment segment = aText.SegmentL( i ); |
|
1114 TTtsStyleID styleID = segment.StyleID(); |
|
1115 TTtsStyle& style = iDevTts->StyleL( styleID ); |
|
1116 } |
|
1117 |
|
1118 CopyParsedTextL( aText ); |
|
1119 } |
|
1120 |
|
1121 // ----------------------------------------------------------------------------- |
|
1122 // CTtsControllerPluginBody::MttscSetPositionL |
|
1123 // Sets the synthesis position in words. |
|
1124 // ----------------------------------------------------------------------------- |
|
1125 // |
|
1126 void CTtsControllerPluginBody::MttscSetPositionL( TInt /*aWordIndex*/ ) |
|
1127 { |
|
1128 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscSetPositionL" ); |
|
1129 |
|
1130 // @todo DevTTS returns this from starting of certain segment |
|
1131 // iDevTts->SetPositionL( aWordIndex ); |
|
1132 } |
|
1133 |
|
1134 // ----------------------------------------------------------------------------- |
|
1135 // CTtsControllerPluginBody::MttscStyleL |
|
1136 // Returns reference to registered style based on ID. |
|
1137 // ----------------------------------------------------------------------------- |
|
1138 // |
|
1139 TTtsStyle& CTtsControllerPluginBody::MttscStyleL( TTtsStyleID aStyleID ) |
|
1140 { |
|
1141 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscStyleL(aStyleID)" ); |
|
1142 |
|
1143 return iDevTts->StyleL( aStyleID ); |
|
1144 } |
|
1145 |
|
1146 |
|
1147 // ----------------------------------------------------------------------------- |
|
1148 // CTtsControllerPluginBody::MttscStyleL |
|
1149 // Returns reference to registered style based in index. |
|
1150 // ----------------------------------------------------------------------------- |
|
1151 // |
|
1152 TTtsStyle& CTtsControllerPluginBody::MttscStyleL( TUint16 aIndex ) |
|
1153 { |
|
1154 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscStyleL(aIndex)" ); |
|
1155 |
|
1156 return iDevTts->StyleL( aIndex ); |
|
1157 } |
|
1158 |
|
1159 // ----------------------------------------------------------------------------- |
|
1160 // CTtsControllerPluginBody::MttscSetDefaultStyleL |
|
1161 // Sets the default style |
|
1162 // ----------------------------------------------------------------------------- |
|
1163 // |
|
1164 void CTtsControllerPluginBody::MttscSetDefaultStyleL( const TTtsStyle& aStyle ) |
|
1165 { |
|
1166 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscSetDefaultStyleL" ); |
|
1167 |
|
1168 // Remove old default style from devTts |
|
1169 iDevTts->DeleteStyleL( iDefaultStyleID ); |
|
1170 |
|
1171 // Copy new default style |
|
1172 iDefaultStyle = aStyle; |
|
1173 |
|
1174 // Add new default style to devTTS |
|
1175 iDefaultStyleID = iDevTts->AddStyleL( iDefaultStyle ); |
|
1176 |
|
1177 iUserSpecifiedDefaultStyle = ETrue; |
|
1178 } |
|
1179 |
|
1180 // ----------------------------------------------------------------------------- |
|
1181 // CTtsControllerPluginBody::MttscDefaultStyleL |
|
1182 // Returns reference to the default style |
|
1183 // ----------------------------------------------------------------------------- |
|
1184 // |
|
1185 TTtsStyle& CTtsControllerPluginBody::MttscDefaultStyleL() |
|
1186 { |
|
1187 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscDefaultStyleL" ); |
|
1188 |
|
1189 return iDefaultStyle; |
|
1190 } |
|
1191 |
|
1192 // ----------------------------------------------------------------------------- |
|
1193 // CTtsControllerPluginBody::MttscSetSpeakingRateL |
|
1194 // Not supported |
|
1195 // ----------------------------------------------------------------------------- |
|
1196 // |
|
1197 void CTtsControllerPluginBody::MttscSetSpeakingRateL( TInt /*aRate*/ ) |
|
1198 { |
|
1199 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscSetSpeakingRateL" ); |
|
1200 |
|
1201 User::Leave( KErrNotSupported ); |
|
1202 } |
|
1203 |
|
1204 // ----------------------------------------------------------------------------- |
|
1205 // CTtsControllerPluginBody::MttscSpeakingRateL |
|
1206 // Not supported |
|
1207 // ----------------------------------------------------------------------------- |
|
1208 // |
|
1209 TInt CTtsControllerPluginBody::MttscSpeakingRateL() |
|
1210 { |
|
1211 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscSpeakingRateL" ); |
|
1212 |
|
1213 User::Leave( KErrNotSupported ); |
|
1214 return KErrNotSupported; |
|
1215 } |
|
1216 |
|
1217 // ----------------------------------------------------------------------------- |
|
1218 // CTtsControllerPluginBody::MttscGetSupportedLanguagesL |
|
1219 // Appends supported languages to aLanguages |
|
1220 // ----------------------------------------------------------------------------- |
|
1221 // |
|
1222 void CTtsControllerPluginBody::MttscGetSupportedLanguagesL( RArray<TLanguage>& aLanguages ) |
|
1223 { |
|
1224 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscGetSupportedLanguagesL" ); |
|
1225 |
|
1226 iTtsLoader->GetSupportedLanguagesL( aLanguages ); |
|
1227 } |
|
1228 |
|
1229 // ----------------------------------------------------------------------------- |
|
1230 // CTtsControllerPluginBody::MttscGetSupportedVoicesL |
|
1231 // Appends supported voices of given language to aVoices |
|
1232 // ----------------------------------------------------------------------------- |
|
1233 // |
|
1234 void CTtsControllerPluginBody::MttscGetSupportedVoicesL( TLanguage aLanguage, |
|
1235 RArray<TTtsStyle>& aVoices ) |
|
1236 { |
|
1237 RUBY_DEBUG_BLOCK( "CTtsControllerPluginBody::MttscGetSupportedVoicesL" ); |
|
1238 |
|
1239 if ( iDevTts->IsLanguageSupported( aLanguage ) ) |
|
1240 { |
|
1241 TTtsStyle style; |
|
1242 style.iLanguage = aLanguage; |
|
1243 style.iSamplingRate = KSamplingRate; |
|
1244 style.iRate = KErrNotSupported; |
|
1245 style.iVolume = KTtsDefaultVolume; |
|
1246 |
|
1247 style.iVoice = KDefaultVoiceNameMale; |
|
1248 aVoices.AppendL( style ); |
|
1249 |
|
1250 style.iVoice = KDefaultVoiceNameFemale; |
|
1251 aVoices.AppendL( style ); |
|
1252 } |
|
1253 } |
|
1254 |
|
1255 // ----------------------------------------------------------------------------- |
|
1256 // CTtsControllerPluginBody::DoCancel |
|
1257 // Cancel handle from CActive class. |
|
1258 // ----------------------------------------------------------------------------- |
|
1259 // |
|
1260 void CTtsControllerPluginBody::DoCancel() |
|
1261 { |
|
1262 } |
|
1263 |
|
1264 // ----------------------------------------------------------------------------- |
|
1265 // CTtsControllerPluginBody::RunL |
|
1266 // RunL from CActive class. Check which message got saved and call the |
|
1267 // appropriate handle function. |
|
1268 // ----------------------------------------------------------------------------- |
|
1269 // |
|
1270 void CTtsControllerPluginBody::RunL() |
|
1271 { |
|
1272 switch ( iRequestFunction ) |
|
1273 { |
|
1274 case KPlay: |
|
1275 HandlePlay(); |
|
1276 break; |
|
1277 default: |
|
1278 // No action |
|
1279 break; |
|
1280 } |
|
1281 } |
|
1282 |
|
1283 // ----------------------------------------------------------------------------- |
|
1284 // CTtsControllerPluginBody::Ready |
|
1285 // Activates the active object. |
|
1286 // ----------------------------------------------------------------------------- |
|
1287 // |
|
1288 void CTtsControllerPluginBody::Ready() |
|
1289 { |
|
1290 TRequestStatus* pRS = &iStatus; |
|
1291 User::RequestComplete( pRS, KErrNone ); |
|
1292 SetActive(); |
|
1293 } |
|
1294 |
|
1295 // ----------------------------------------------------------------------------- |
|
1296 // CTtsControllerPluginBody::ConstructParsedTextL |
|
1297 // Converts the descriptor to unicode & puts it to parsed text object. |
|
1298 // ----------------------------------------------------------------------------- |
|
1299 // |
|
1300 void CTtsControllerPluginBody::ConstructParsedTextL( TDes8& aBufferPtr ) |
|
1301 { |
|
1302 RUBY_DEBUG_BLOCK( "" ); |
|
1303 |
|
1304 // Check if header is there and strip it out if needed |
|
1305 TInt index = aBufferPtr.Find( KTtsContentHeader ); |
|
1306 if ( index != KErrNotFound ) |
|
1307 { |
|
1308 aBufferPtr.Replace( index, KTtsContentHeader().Length(), KNullDesC8 ); |
|
1309 } |
|
1310 |
|
1311 TInt languageId( KErrNotFound ); |
|
1312 index = aBufferPtr.Find( KTtsLanguageStartTag ); |
|
1313 if ( index != KErrNotFound ) |
|
1314 { |
|
1315 RUBY_DEBUG1( "KTtsLanguageStartTag found, index %d", index ); |
|
1316 |
|
1317 TInt relativeEndIndex( aBufferPtr.Mid( index ).Find( KTtsLanguageEndTag ) ); |
|
1318 |
|
1319 if ( relativeEndIndex != KErrNotFound ) |
|
1320 { |
|
1321 const TInt tagLength( KTtsLanguageStartTag().Length() ); |
|
1322 |
|
1323 TPtrC8 lang( aBufferPtr.Mid( index + tagLength, relativeEndIndex - tagLength ) ); |
|
1324 |
|
1325 TInt64 tmp; |
|
1326 TLex8 parser( lang ); |
|
1327 |
|
1328 if ( parser.Val( tmp, EDecimal ) == KErrNone ) |
|
1329 { |
|
1330 languageId = tmp; |
|
1331 RUBY_DEBUG1( "Detected language selection %d", languageId ); |
|
1332 } |
|
1333 |
|
1334 aBufferPtr.Replace( index, relativeEndIndex + 1, KNullDesC8 ); |
|
1335 } |
|
1336 } |
|
1337 |
|
1338 // Convert text to 16-bit unicode |
|
1339 HBufC16* unicode = HBufC16::NewL( aBufferPtr.Size() ); |
|
1340 CleanupStack::PushL( unicode ); |
|
1341 TPtr16 bufferPtr16( unicode->Des() ); |
|
1342 User::LeaveIfError( CnvUtfConverter::ConvertToUnicodeFromUtf8( bufferPtr16, aBufferPtr ) ); |
|
1343 |
|
1344 // Create new parsed text which will be filled with input data |
|
1345 delete iParsedTextPointer; |
|
1346 iParsedTextPointer = NULL; |
|
1347 iParsedTextPointer = CTtsParsedText::NewL( bufferPtr16 ); |
|
1348 |
|
1349 // CTtsParsedText makes a copy of data |
|
1350 CleanupStack::PopAndDestroy( unicode ); |
|
1351 |
|
1352 // Construct segment & add it to the parsed text |
|
1353 TTtsSegment iSegment( iDefaultStyleID ); |
|
1354 iSegment.SetTextPtr( iParsedTextPointer->Text() ); |
|
1355 iParsedTextPointer->AddSegmentL( iSegment ); |
|
1356 |
|
1357 if ( !iUserSpecifiedDefaultStyle ) |
|
1358 { |
|
1359 // Reset style language so that UI language will be used if |
|
1360 // default default style in use |
|
1361 TTtsStyle& style = iDevTts->StyleL( iDefaultStyleID ); |
|
1362 |
|
1363 if ( languageId == KErrNotFound ) |
|
1364 { |
|
1365 style.iLanguage = User::Language(); |
|
1366 } |
|
1367 else |
|
1368 { |
|
1369 style.iLanguage = (TLanguage)languageId; |
|
1370 } |
|
1371 } |
|
1372 } |
|
1373 |
|
1374 // ----------------------------------------------------------------------------- |
|
1375 // CTtsControllerPluginBody::CopyParsedTextL |
|
1376 // Copies parsed text. |
|
1377 // ----------------------------------------------------------------------------- |
|
1378 // |
|
1379 void CTtsControllerPluginBody::CopyParsedTextL( CTtsParsedText& aText ) |
|
1380 { |
|
1381 // Delete previous object if exists |
|
1382 delete iParsedTextPointer; |
|
1383 iParsedTextPointer = NULL; |
|
1384 |
|
1385 // New instance |
|
1386 iParsedTextPointer = CTtsParsedText::NewL( aText.Text(), aText.PhonemeSequence(), |
|
1387 aText.PhonemeNotation() ); |
|
1388 |
|
1389 // Segments: |
|
1390 |
|
1391 // Indexes for starting points for segment's text and phoneme part in |
|
1392 // CTtsParsedText object's text and phoneme sequence |
|
1393 TInt textIndex( 0 ); |
|
1394 TInt phonemeIndex( 0 ); |
|
1395 |
|
1396 for ( TInt i = 0; i < aText.NumberOfSegments(); i++ ) |
|
1397 { |
|
1398 TTtsSegment segment = aText.SegmentL( i ); |
|
1399 |
|
1400 segment.SetStyleID( aText.SegmentL( i ).StyleID() ); |
|
1401 |
|
1402 TInt segTextLength = aText.SegmentL( i ).TextPtr().Length(); |
|
1403 TInt segPhonemeSeqLength = aText.SegmentL( i ) |
|
1404 .PhonemeSequencePtr().Length(); |
|
1405 |
|
1406 // Text |
|
1407 if ( textIndex + segTextLength |
|
1408 <= iParsedTextPointer->Text().Length() ) |
|
1409 { |
|
1410 segment.SetTextPtr( iParsedTextPointer->Text() |
|
1411 .Mid( textIndex, segTextLength ) ); |
|
1412 |
|
1413 textIndex += segTextLength; |
|
1414 } |
|
1415 // Segments are somehow constructed illegally. Copy the whole text. |
|
1416 else |
|
1417 { |
|
1418 segment.SetTextPtr( iParsedTextPointer->Text() ); |
|
1419 } |
|
1420 |
|
1421 // Phoneme sequence |
|
1422 if ( phonemeIndex + segPhonemeSeqLength |
|
1423 <= iParsedTextPointer->PhonemeSequence().Length() ) |
|
1424 { |
|
1425 segment.SetPhonemeSequencePtr( |
|
1426 iParsedTextPointer-> |
|
1427 PhonemeSequence().Mid( phonemeIndex, segPhonemeSeqLength ) ); |
|
1428 |
|
1429 phonemeIndex += segPhonemeSeqLength; |
|
1430 } |
|
1431 else |
|
1432 { |
|
1433 segment.SetPhonemeSequencePtr( |
|
1434 iParsedTextPointer->PhonemeSequence() ); |
|
1435 } |
|
1436 |
|
1437 // Add segment to the new instance of CTtsParsedText |
|
1438 iParsedTextPointer->AddSegmentL( segment ); |
|
1439 } |
|
1440 } |
|
1441 |
|
1442 // End of File |