srsf/devtts/src/devttsalgorithmmanager.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     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 CTTSAlgorithmManager methods.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <barsc.h>
       
    21 #include <bautils.h>
       
    22 #include <barsread.h>
       
    23 #include <nssdevtts.rsg>
       
    24 #include <AudioPreference.h>
       
    25 #include <data_caging_path_literals.hrh>
       
    26 #include "devttsalgorithmmanager.h"
       
    27 #include "rubydebug.h"
       
    28 
       
    29 #ifdef _DEBUG
       
    30 #include <e32svr.h>
       
    31 #endif
       
    32 
       
    33 // CONSTANTS
       
    34 _LIT( KResourceFileName, "nssdevtts.rsc" );
       
    35 
       
    36 // Default audio priority
       
    37 const TInt KDefaultPriority = KAudioPriorityVoiceDial;
       
    38 
       
    39 #ifdef DEVTTS_AUDIOBUFFER_TO_FILE
       
    40 const TFileName KAudioBufferFileName( _L( "c:\\documents\\devttsaudio" ) );
       
    41 const TFileName KAudioBufferFileNameExtension( _L( ".raw" ) );
       
    42 #endif
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CTTSAlgorithmManager::CTTSAlgorithmManager
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CTTSAlgorithmManager::CTTSAlgorithmManager( MDevTTSObserver& aObserver ):
       
    53         iPaused( EFalse ),
       
    54         iObserver( aObserver ),
       
    55         iAudio( NULL ),
       
    56         iAudioState( ETTSAudioPlayerNotInitialized ),
       
    57         iHw( NULL ),
       
    58         iError( KErrNone ),
       
    59         iState( EDevTTSNotInitialized ),
       
    60         iMode( EDevTTSSoundDeviceMode ),
       
    61         iLastBufferFromTts( EFalse ),
       
    62         iTtpHw( NULL ), 
       
    63 #ifdef DEVTTS_3DB_HACK
       
    64 		iApplyGain( ETrue ),
       
    65 #endif
       
    66         iNlp( NULL ),
       
    67         iNlpInitialized( EFalse )
       
    68     {
       
    69     // Nothing
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CTTSAlgorithmManager::ConstructL
       
    74 // Symbian 2nd phase constructor can leave.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CTTSAlgorithmManager::ConstructL(/*CConsoleBase* console*/)
       
    78     {
       
    79     RUBY_DEBUG_BLOCK( "CTTSAlgorithmManager::ConstructL" );
       
    80     
       
    81     TBool boolStereo( EFalse );
       
    82     TUint intStereo( 0 );
       
    83     TUint bitsPerSample( 16 );
       
    84     TUint samplingRate( 16000 );
       
    85     TUint bufferSize( 4096 );
       
    86     TInt defaultPriority( 0 );
       
    87     
       
    88     // Try to find resource file first from MMC, then from C-drive and only 
       
    89     // after that from flash
       
    90     // letters for drives in search order
       
    91     const TBuf<2> KResourceDrives = _L("cz"); 
       
    92     
       
    93     // load resources
       
    94     RResourceFile resourceFile;
       
    95     RFs fs;
       
    96     User::LeaveIfError( fs.Connect() );
       
    97     CleanupClosePushL( fs );
       
    98     
       
    99     TFileName name;
       
   100     TInt i( 0 );
       
   101     // try to find from the first driver
       
   102     name.Append( KResourceDrives[i] );
       
   103     name.Append( ':' );
       
   104     name.Append( KDC_RESOURCE_FILES_DIR );
       
   105     name.Append( KResourceFileName );
       
   106 
       
   107     TBool found( EFalse );
       
   108     
       
   109     while ( !found && i < KResourceDrives.Length() )
       
   110         {
       
   111         name[0] = KResourceDrives[i++];
       
   112        
       
   113         if ( BaflUtils::FileExists(fs, name) )
       
   114             {
       
   115             // open resource
       
   116             resourceFile.OpenL( fs, name );
       
   117             CleanupClosePushL( resourceFile );
       
   118             found = ETrue;
       
   119             }
       
   120         }
       
   121             
       
   122     if ( !found )
       
   123         {
       
   124         User::Leave( KErrNotFound );
       
   125         }
       
   126 
       
   127     HBufC8* configurations = resourceFile.AllocReadLC( R_DEVTTS_CONFIGURATIONS );
       
   128     
       
   129     TResourceReader resReader;
       
   130     resReader.SetBuffer( configurations );
       
   131     
       
   132     // Sampling rate
       
   133     samplingRate = resReader.ReadUint32();
       
   134 
       
   135     // Bits per sample
       
   136     bitsPerSample = resReader.ReadUint32();
       
   137     
       
   138     // Mono / Stereo
       
   139     intStereo = resReader.ReadUint32();
       
   140 
       
   141     // Buffer size
       
   142     bufferSize = resReader.ReadUint32();
       
   143 
       
   144 #ifdef __WINS__
       
   145     // CMMFDevSound uses currently buffer size of 16384 in emulator. 
       
   146     RUBY_DEBUG0( "CTTSAlgorithmManager::ConstructL - Hard coded buffer size in use!" );
       
   147     bufferSize = 16384;
       
   148 #endif
       
   149 
       
   150     // Priority
       
   151     defaultPriority = KDefaultPriority;
       
   152     
       
   153     if ( intStereo == 0 )
       
   154         {
       
   155         boolStereo = EFalse;
       
   156         }
       
   157     else
       
   158         {
       
   159         boolStereo = ETrue;
       
   160         }
       
   161         
       
   162     // Cleanup configurations, resourceFile, fs
       
   163     CleanupStack::PopAndDestroy( configurations );    
       
   164     CleanupStack::PopAndDestroy( &resourceFile );
       
   165     CleanupStack::PopAndDestroy( &fs );
       
   166 
       
   167     // Create new TtsHwDevice instance
       
   168     iHw = CTtsHwDevice::NewL( *this, samplingRate, bufferSize );
       
   169     
       
   170     // Create audio playback instance
       
   171     iAudio = CDevTTSAudio::NewL( *this, defaultPriority );
       
   172     
       
   173     iState = EDevTTSStopped;
       
   174     
       
   175     // Start audio device initialization process
       
   176     iAudio->InitializeL();
       
   177 
       
   178     // Wait for callback only if it is asynchronous
       
   179     // (state will be something else if it is synchronous)
       
   180     if ( iAudioState == ETTSAudioPlayerNotInitialized )
       
   181         {
       
   182         if ( !iAudioWait.IsStarted() )
       
   183             {
       
   184             RUBY_DEBUG0( "CTTSAlgorithmManager::ConstructL iAudioWait.Start()" );
       
   185             iAudioWait.Start();
       
   186             }
       
   187         }
       
   188         
       
   189     iAudio->ConfigL( samplingRate, bitsPerSample, boolStereo, bufferSize);
       
   190 
       
   191     // Create & initialize TtpHwDevice
       
   192     iTtpHw = CASRSTtpHwDevice::NewL( *this );
       
   193     iTtpHw->InitializeL();
       
   194     iTtpHw->SetPhonemeNotationL( _L( "NIPA8" ) );
       
   195     
       
   196     // Create NlpHwDevice
       
   197     TRAPD( error, iNlp = CNlpHwDevice::NewL( *this ) );
       
   198     if ( error == KErrNone )
       
   199         {
       
   200         iNlp->InitializeL();
       
   201         iNlpInitialized = ETrue;
       
   202         }
       
   203     else
       
   204         {
       
   205         iNlpInitialized = EFalse;
       
   206         }
       
   207 
       
   208 #ifdef DEVTTS_AUDIOBUFFER_TO_FILE
       
   209     User::LeaveIfError( iSession.Connect() );
       
   210     iFileOpen = EFalse;
       
   211     iFileCounter = 0;
       
   212 #endif
       
   213 
       
   214     RUBY_DEBUG1( "CTTSAlgorithmManager config, sampling rate: %d", samplingRate );
       
   215     RUBY_DEBUG1( "CTTSAlgorithmManager config, bits per sample: %d", bitsPerSample);
       
   216     RUBY_DEBUG1( "CTTSAlgorithmManager config, mono/stereo: %d", intStereo);
       
   217     RUBY_DEBUG1( "CTTSAlgorithmManager config, buffer size: %d", bufferSize);
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CTTSAlgorithmManager::NewL
       
   222 // Two-phased constructor.
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 CTTSAlgorithmManager* CTTSAlgorithmManager::NewL( MDevTTSObserver& aObserver/*, CConsoleBase* console*/ )
       
   226     {
       
   227     CTTSAlgorithmManager* self = new( ELeave ) CTTSAlgorithmManager(aObserver);
       
   228     
       
   229     CleanupStack::PushL( self );
       
   230     self->ConstructL( /*console*/ );
       
   231     CleanupStack::Pop( self );
       
   232     
       
   233     return self;
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CTTSAlgorithmManager::~CTTSAlgorithmManager
       
   238 // Destructor.
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 CTTSAlgorithmManager::~CTTSAlgorithmManager()
       
   242     {
       
   243     if ( iAudio )
       
   244         {
       
   245         iAudio->Clear();
       
   246         delete iAudio;
       
   247         iAudio = NULL;
       
   248         }
       
   249     if ( iHw )
       
   250         {
       
   251         delete iHw;
       
   252         iHw = NULL;
       
   253         }
       
   254     if ( iTtpHw )
       
   255         {
       
   256         iTtpHw->Clear();
       
   257         delete iTtpHw;
       
   258         iTtpHw = NULL;
       
   259         }
       
   260     if ( iNlp )
       
   261         {
       
   262         iNlp->Clear();
       
   263         delete iNlp;
       
   264         iNlp = NULL;
       
   265         }
       
   266 #ifdef DEVTTS_AUDIOBUFFER_TO_FILE
       
   267     iSession.Close();
       
   268 #endif
       
   269     }
       
   270 
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CTTSAlgorithmManager::AddStyleL
       
   274 // Forwards call to TtsHwDevice
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TTtsStyleID CTTSAlgorithmManager::AddStyleL( const TTtsStyle& aStyle )
       
   278     {
       
   279     return iHw->AddStyleL( aStyle );
       
   280     }
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CTTSAlgorithmManager::Balance
       
   284 // Forwards call to the CDevTTSAudio.
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 TInt CTTSAlgorithmManager::Balance()
       
   288     {
       
   289     return iAudio->Balance();
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CTTSAlgorithmManager::BufferProcessed
       
   294 // Forwards call to TtsHwDevice
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CTTSAlgorithmManager::BufferProcessed( const TDesC8& aBuffer )
       
   298     {
       
   299     // Client should call this only when buffers are provided to client
       
   300     if ( iMode == EDevTTSClientMode )
       
   301         {
       
   302         iHw->BufferProcessed( aBuffer );
       
   303         }
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CTTSAlgorithmManager::CustomInterface
       
   308 // Not in use currently. Now returns NULL.
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 TAny* CTTSAlgorithmManager::CustomInterface( TUid /*aInterfaceID*/ )
       
   312     {
       
   313     return NULL;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CTTSAlgorithmManager::DeleteStyleL
       
   318 // Forwards call to the actual implementation object.
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 void CTTSAlgorithmManager::DeleteStyleL( TTtsStyleID aStyleID )
       
   322     {
       
   323     iHw->DeleteStyleL( aStyleID );
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CTTSAlgorithmManager::GetPositionL
       
   328 // Forwards call to TtsHwDevice
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CTTSAlgorithmManager::GetPositionL( TTimeIntervalMicroSeconds& aTime ) const
       
   332     {
       
   333     iHw->GetPositionL( aTime );
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CTTSAlgorithmManager::GetPositionL
       
   338 // Forwards call to TtsHwDevice
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CTTSAlgorithmManager::GetPositionL( TTtsSegment& aSegment, TInt& aWordIndex ) const
       
   342     {
       
   343     iHw->GetPositionL( aSegment, aWordIndex );
       
   344     }
       
   345 
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CTTSAlgorithmManager::IsLanguageSupported
       
   349 // Forwards call to TtsHwDevice
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 TBool CTTSAlgorithmManager::IsLanguageSupported( TLanguage aLanguage ) const
       
   353     {
       
   354     return iHw->IsLanguageSupported( aLanguage );
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CTTSAlgorithmManager::MaxVolume
       
   359 // Forwards call to the CDevTTSAudio.
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 TInt CTTSAlgorithmManager::MaxVolume()
       
   363     {
       
   364     return iAudio->MaxVolume();
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CTTSAlgorithmManager::NumberOfStyles
       
   369 // Forwards call to TtsHwDevice
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 TUint16 CTTSAlgorithmManager::NumberOfStyles() const
       
   373     {
       
   374     return iHw->NumberOfStyles();
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CTTSAlgorithmManager::Pause
       
   379 // Pauses synthesis process in TtsHwDevice and also audio playback if needed.
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 void CTTSAlgorithmManager::Pause()
       
   383     {
       
   384     // Do nothing if not synthesizing currently
       
   385     if ( iState != EDevTTSSynthesizing )
       
   386         {
       
   387         return;
       
   388         }
       
   389     
       
   390     // Stop synthesis and playback
       
   391     iHw->Pause();
       
   392 
       
   393     if( iMode == EDevTTSSoundDeviceMode )
       
   394         {
       
   395         // Do a complete stop to the audio player instead of pause.
       
   396         // Pausing and resuming after that leads to the situation where all of
       
   397         // the data won't be played...
       
   398         iAudio->Stop();
       
   399         iAudioState = ETTSAudioPlayerPaused;
       
   400         }
       
   401     
       
   402     iState = EDevTTSPrimed;
       
   403     iPaused = ETrue;
       
   404     }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // CTTSAlgorithmManager::PrimeSynthesisL
       
   408 // Prepares a synthesizing process, data will be read from client using a 
       
   409 // stream.
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CTTSAlgorithmManager::PrimeSynthesisL( MTtsSegmentStream& aStream ) 
       
   413     {
       
   414     // Not yet in use, leave every time
       
   415     // @todo: Remove this when functionality is available
       
   416     User::Leave( KErrNotSupported );
       
   417     
       
   418     // Do the state check    
       
   419     if ( iState == EDevTTSNotInitialized )
       
   420         {
       
   421         User::Leave( KErrNotReady );
       
   422         }
       
   423     
       
   424     if ( iState != EDevTTSStopped )
       
   425         {
       
   426         User::Leave( KErrInUse );
       
   427         }
       
   428     
       
   429     iHw->PrimeSynthesisL( aStream );
       
   430     
       
   431     iState = EDevTTSPrimed;
       
   432     }
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CTTSAlgorithmManager::PrimeSynthesisL
       
   436 // Prepares a synthesizing process.
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 void CTTSAlgorithmManager::PrimeSynthesisL( CTtsParsedText& aText )
       
   440     {
       
   441     RUBY_DEBUG_BLOCK( "CTTSAlgorithmManager::PrimeSynthesisL" );
       
   442 
       
   443     // Do the state check
       
   444     
       
   445     if ( iState == EDevTTSNotInitialized )
       
   446         {
       
   447         User::Leave( KErrNotReady );
       
   448         }
       
   449     
       
   450     if (iState != EDevTTSStopped)
       
   451         {
       
   452         User::Leave( KErrInUse );
       
   453         }
       
   454     
       
   455     // 1. Analyze structure if no segments in the parsed text object
       
   456     if ( aText.NumberOfSegments() == 0 )
       
   457         {
       
   458         iHw->AnalyzeStructureL( aText );
       
   459         }
       
   460 
       
   461     // 2. Call NLP if there is written text
       
   462     if ( ( aText.Text() != KNullDesC16 ) && iNlpInitialized )
       
   463         {
       
   464         
       
   465         TBool useNlp( ETrue );
       
   466         TInt counter( 0 );
       
   467         
       
   468         // Loop through content types of segments to find out if NLP should be used
       
   469         for ( counter = 0; counter < aText.NumberOfSegments(); counter++ )
       
   470             {
       
   471             TTtsSegment segment = aText.SegmentL( counter );
       
   472             TTtsStyleID styleID = segment.StyleID();
       
   473             TTtsStyle& style = StyleL( styleID );
       
   474             
       
   475             if ( !style.iNlp )
       
   476                 {
       
   477                 useNlp = EFalse;                
       
   478                 }
       
   479             }
       
   480         
       
   481         if ( useNlp )
       
   482             {
       
   483             // If language is not specified, run LID before NLP
       
   484             for ( counter = 0; counter < aText.NumberOfSegments(); counter++ )
       
   485                 {
       
   486                 TTtsSegment segment = aText.SegmentL( counter );
       
   487                 TTtsStyleID styleID = segment.StyleID();
       
   488                 TTtsStyle& style = StyleL( styleID );
       
   489 
       
   490                 if ( style.iLanguage == ELangOther )
       
   491                     {
       
   492                     RArray<TLanguage> languages;
       
   493                     RArray<TInt> scores;
       
   494                 
       
   495                     // Only one result is needed
       
   496                     iTtpHw->LanguageIdentificationL( segment.TextPtr(), 1, languages, scores );
       
   497 
       
   498                     if ( languages.Count() == 0 )
       
   499                         {
       
   500                         languages.Close();
       
   501                         scores.Close();
       
   502                         User::Leave( KErrGeneral );
       
   503                         }
       
   504 
       
   505                     style.iLanguage = languages[0];
       
   506 
       
   507                     RUBY_DEBUG1( "CTTSAlgorithmManager::PrimeSynthesisL called LID [lang id: %d] before NLP", style.iLanguage );
       
   508 
       
   509                     languages.Close();
       
   510                     scores.Close();
       
   511                     }
       
   512                 }
       
   513             }
       
   514             
       
   515         if ( useNlp )
       
   516             {
       
   517             iNlp->NormalizeTextL( aText );
       
   518             }
       
   519         }
       
   520 
       
   521     // Set the phoneme notation which is given within parsed text into TTP
       
   522     // Do this only if no phonemesequence is given and if notation is something
       
   523     // else than the default
       
   524     if ( ( aText.PhonemeNotation() != KNullDesC16 ) && ( aText.PhonemeSequence() == KNullDesC8 ) )
       
   525         {
       
   526         iTtpHw->SetPhonemeNotationL( aText.PhonemeNotation() );
       
   527         }
       
   528 
       
   529     // 3. Do the TTP if phoneme sequence not available
       
   530     if ( aText.PhonemeSequence() == KNullDesC8 )
       
   531         {
       
   532         // If also text is NULL, argument is not ok
       
   533         if ( aText.Text() == KNullDesC16 )
       
   534             {
       
   535             User::Leave( KErrArgument );
       
   536             }
       
   537         
       
   538 #ifdef __SIND_MULTIPLE_SEGMENTS
       
   539         RArray<TInt> segmentPhonemeLengths;
       
   540         CleanupClosePushL(segmentPhonemeLengths);
       
   541 #endif // __SIND_MULTIPLE_SEGMENTS
       
   542         // Find the style attached to each segment
       
   543         for ( TInt i = 0; i < aText.NumberOfSegments(); i++ )
       
   544             {
       
   545             TTtsSegment segment = aText.SegmentL( i );
       
   546             TTtsStyleID styleID = segment.StyleID();
       
   547             TTtsStyle& style = StyleL( styleID );
       
   548             
       
   549             RUBY_DEBUG1( "CTTSAlgorithmManager::PrimeSynthesisL calling TTP with lang id [%d]", style.iLanguage );
       
   550 
       
   551             HBufC8* phonemeBuffer = iTtpHw->ConvertTextL( segment.TextPtr(), style.iLanguage );
       
   552             
       
   553             if ( phonemeBuffer == NULL )
       
   554                 {
       
   555                 RUBY_DEBUG0( "CTTSAlgorithmManager::PrimeSynthesisL TTP returned NULL, calling again with ELangOther" );
       
   556 
       
   557                 // Try with another approach, use ELangOther as language and let
       
   558                 // the LID to do the job
       
   559                 if ( style.iLanguage != ELangOther )
       
   560                     {
       
   561                     style.iLanguage = ELangOther;
       
   562                     phonemeBuffer = iTtpHw->ConvertTextL( segment.TextPtr(), style.iLanguage );
       
   563                     RUBY_DEBUG1( "CTTSAlgorithmManager::PrimeSynthesisL LID returned lang id [%d]", style.iLanguage );
       
   564                     if ( phonemeBuffer == NULL )
       
   565                         {
       
   566                         User::Leave( KErrGeneral );
       
   567                         }
       
   568                     }
       
   569                 else
       
   570                     {
       
   571                     User::Leave( KErrGeneral );
       
   572                     }
       
   573                 }
       
   574 
       
   575             CleanupStack::PushL( phonemeBuffer );
       
   576 
       
   577 #ifdef __SIND_MULTIPLE_SEGMENTS
       
   578             // Append segment's phone sequence to CTtsparsedText's phoneme sequence
       
   579             HBufC8*  phonemeSeq = HBufC8::NewLC( aText.PhonemeSequence().Length() + phonemeBuffer->Des().Length() );
       
   580             phonemeSeq->Des().Append( aText.PhonemeSequence() );
       
   581             phonemeSeq->Des().Append( phonemeBuffer->Des() );
       
   582             // Set new phoneme sequence
       
   583             aText.SetPhonemeSequenceL( *phonemeSeq );
       
   584             CleanupStack::PopAndDestroy( phonemeSeq );
       
   585             
       
   586             // Save the length of segment's phoneme sequence
       
   587             segmentPhonemeLengths.AppendL( phonemeBuffer->Des().Length() );
       
   588 
       
   589 #else
       
   590             aText.SetPhonemeSequenceL( phonemeBuffer->Des() );
       
   591             
       
   592             segment.SetPhonemeSequencePtr( aText.PhonemeSequence() );
       
   593             // Add modified segment to parsed text
       
   594             aText.DeleteSegmentL( i );
       
   595             aText.AddSegmentL( segment, i );
       
   596 #endif // __SIND_MULTIPLE_SEGMENTS
       
   597             
       
   598             // phonemeBuffer
       
   599             CleanupStack::PopAndDestroy( phonemeBuffer );
       
   600             }
       
   601         
       
   602 #ifdef __SIND_MULTIPLE_SEGMENTS
       
   603         // Put pointers of the whole phone sequence in CTtsParsedText
       
   604         // to their respective segments 
       
   605         TInt position( 0 );
       
   606         for ( TInt i = 0; i < aText.NumberOfSegments(); i++ )
       
   607             {
       
   608             TTtsSegment segment = aText.SegmentL( i );
       
   609             segment.SetPhonemeSequencePtr( aText.PhonemeSequence().Mid( position, segmentPhonemeLengths[i] ) );
       
   610             // Add modified segment to parsed text
       
   611             aText.DeleteSegmentL( i );
       
   612             aText.AddSegmentL( segment, i );
       
   613             // Move the position to next segments starting position
       
   614             position += segmentPhonemeLengths[i];
       
   615             }
       
   616         
       
   617         // Release resources allocated by RArray    
       
   618         CleanupStack::PopAndDestroy( &segmentPhonemeLengths );
       
   619 #endif // __SIND_MULTIPLE_SEGMENTS
       
   620         
       
   621         }
       
   622 
       
   623 #ifdef DEVTTS_3DB_HACK
       
   624 	iApplyGain = ETrue;
       
   625 #endif
       
   626 
       
   627 
       
   628     // 4. Analyze prosody
       
   629     iHw->AnalyzeProsodyL( aText );    
       
   630     
       
   631     // 5. Prime TtsHwDevice
       
   632     iHw->PrimeSynthesisL( aText );
       
   633     
       
   634     iState = EDevTTSPrimed;
       
   635     }
       
   636 
       
   637 // -----------------------------------------------------------------------------
       
   638 // CTTSAlgorithmManager::SetAudioPriority
       
   639 // Forwards call to the CDevTTSAudio
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 void CTTSAlgorithmManager::SetAudioPriority( TInt aPriority, TDevTTSAudioPreference aPref )
       
   643     {
       
   644     iAudio->SetAudioPriority( aPriority, aPref );
       
   645     }
       
   646 
       
   647 // -----------------------------------------------------------------------------
       
   648 // CTTSAlgorithmManager::SetAudioOutputL
       
   649 // Forwards call to the CDevTTSAudio
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 void CTTSAlgorithmManager::SetAudioOutputL( TInt aAudioOutput )
       
   653     {
       
   654     iAudio->SetAudioOutputL( aAudioOutput );
       
   655     }
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CTTSAlgorithmManager::SetBalance
       
   659 // Forwards call to the CDevTTSAudio
       
   660 // -----------------------------------------------------------------------------
       
   661 //
       
   662 void CTTSAlgorithmManager::SetBalance( TInt aBalance )
       
   663     {
       
   664     iAudio->SetBalance( aBalance );
       
   665     }
       
   666 
       
   667 // -----------------------------------------------------------------------------
       
   668 // CTTSAlgorithmManager::SetPositionL
       
   669 // Forwards call to TtsHwDevice
       
   670 // -----------------------------------------------------------------------------
       
   671 //
       
   672 void CTTSAlgorithmManager::SetPositionL( const TTimeIntervalMicroSeconds& aTime )
       
   673     {
       
   674     iHw->SetPositionL( aTime );
       
   675     }
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // CTTSAlgorithmManager::SetPositionL
       
   679 // Forwards call to TtsHwDevice
       
   680 // -----------------------------------------------------------------------------
       
   681 //
       
   682 void CTTSAlgorithmManager::SetPositionL( const TTtsSegment& aSegment, 
       
   683                                          TInt aWordIndex )
       
   684     {
       
   685     iHw->SetPositionL( aSegment, aWordIndex );
       
   686     }
       
   687 
       
   688 // -----------------------------------------------------------------------------
       
   689 // CTTSAlgorithmManager::SetVolume
       
   690 // Forwards call to the CDevTTSAudio
       
   691 // -----------------------------------------------------------------------------
       
   692 //
       
   693 void CTTSAlgorithmManager::SetVolume( TInt aVolume )
       
   694     {
       
   695     iAudio->SetVolume( aVolume );
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // CTTSAlgorithmManager::SetVolumeRamp
       
   700 // Forwards call to the CDevTTSAudio
       
   701 // -----------------------------------------------------------------------------
       
   702 //
       
   703 void CTTSAlgorithmManager::SetVolumeRamp( const TTimeIntervalMicroSeconds& aRampDuration )
       
   704     {
       
   705     iAudio->SetVolumeRamp( aRampDuration );
       
   706     }
       
   707 
       
   708 // -----------------------------------------------------------------------------
       
   709 // CTTSAlgorithmManager::Stop
       
   710 // Stop synthesis process as well as audio playback if running.
       
   711 // -----------------------------------------------------------------------------
       
   712 //
       
   713 void CTTSAlgorithmManager::Stop()
       
   714     {
       
   715     if ( iState == EDevTTSNotInitialized )
       
   716         {
       
   717         // Just to play it safe, do nothing if not initialized
       
   718         return;
       
   719         }
       
   720     
       
   721     if ( iAudioState == ETTSAudioPlayerPlaying )
       
   722         {
       
   723         iAudio->Stop();
       
   724         iAudioState = ETTSAudioPlayerIdle;
       
   725         }
       
   726     if ( iState == EDevTTSSynthesizing || iState == EDevTTSPrimed )
       
   727         {
       
   728         iHw->Stop();
       
   729         }
       
   730     
       
   731     iState = EDevTTSStopped;
       
   732     
       
   733     // Clear paused flag. might be that we are stopping after pausing
       
   734     iPaused = EFalse;
       
   735     }
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 // CTTSAlgorithmManager::StyleL
       
   739 // Forwards call to TtsHwDevice
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 TTtsStyle& CTTSAlgorithmManager::StyleL( TTtsStyleID aStyleID ) const
       
   743     {
       
   744     return iHw->StyleL( aStyleID );
       
   745     }
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CTTSAlgorithmManager::StyleL
       
   749 // Forwards call to TtsHwDevice
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 TTtsStyle& CTTSAlgorithmManager::StyleL( TUint16 aIndex ) const
       
   753     {
       
   754     return iHw->StyleL(  aIndex );
       
   755     }
       
   756 
       
   757 // -----------------------------------------------------------------------------
       
   758 // CTTSAlgorithmManager::SynthesizeL
       
   759 // Starts or resumes synthesis process. 
       
   760 // -----------------------------------------------------------------------------
       
   761 //
       
   762 void CTTSAlgorithmManager::SynthesizeL( TDevTTSOutputMode aOutputMode ) 
       
   763     {
       
   764     
       
   765     if ( (iState == EDevTTSNotInitialized) || (iState == EDevTTSStopped) )
       
   766         {
       
   767         User::Leave( KErrNotReady );
       
   768         }
       
   769     
       
   770     if ( iState != EDevTTSPrimed )
       
   771         {
       
   772         User::Leave( KErrInUse );
       
   773         }
       
   774     
       
   775     // If iPaused flag is set, we know that there is an
       
   776     // ongoing synthesis process and we should resume that instead of starting
       
   777     // a new one.
       
   778     if ( iPaused )
       
   779         {
       
   780         // Resume synthesis by calling hwdevice
       
   781         iHw->SynthesizeL();
       
   782         
       
   783         if ( iMode == EDevTTSSoundDeviceMode )
       
   784             {
       
   785             iAudio->PlayInitL();
       
   786             
       
   787             iAudioState = ETTSAudioPlayerPlaying;
       
   788             }
       
   789         iState = EDevTTSSynthesizing;
       
   790         iPaused = EFalse;
       
   791         return;
       
   792         }
       
   793     
       
   794     iMode = aOutputMode;
       
   795     
       
   796     // Start synthesizing by calling hwdevice
       
   797     iHw->SynthesizeL();
       
   798     iLastBufferFromTts = EFalse;
       
   799     
       
   800     if ( iMode == EDevTTSSoundDeviceMode )
       
   801         {
       
   802         // Check the audio player state
       
   803         if ( iAudioState == ETTSAudioPlayerNotInitialized || 
       
   804             iAudioState == ETTSAudioPlayerError )
       
   805             {
       
   806             User::Leave( KErrNotReady );
       
   807             }
       
   808         
       
   809         if ( iAudioState == ETTSAudioPlayerPlaying )
       
   810             {
       
   811             User::Leave( KErrInUse );
       
   812             }
       
   813         
       
   814         // Initialize audio device so that it is ready for playback
       
   815         iAudio->PlayInitL();
       
   816         
       
   817         iAudioState = ETTSAudioPlayerPlaying;
       
   818         }
       
   819     
       
   820     iState = EDevTTSSynthesizing;
       
   821 
       
   822     RUBY_DEBUG0( "CTTSAlgorithmManager::SynthesizeL started" );
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CTTSAlgorithmManager::Volume
       
   827 // Forwards call to the CDevTTSAudio.
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 TInt CTTSAlgorithmManager::Volume()
       
   831     {
       
   832     return iAudio->Volume();
       
   833     }
       
   834 
       
   835 
       
   836 // ========================== CALLBACKS FROM DEVTTSAUDIO =======================
       
   837 
       
   838 
       
   839 // -----------------------------------------------------------------------------
       
   840 // CTTSAlgorithmManager::InitializeComplete
       
   841 // Audio has been initialized.
       
   842 // -----------------------------------------------------------------------------
       
   843 //
       
   844 void CTTSAlgorithmManager::MdtaoInitializeComplete(TInt aError) 
       
   845     {
       
   846     if ( aError == KErrNone )
       
   847         {
       
   848         iAudioState = ETTSAudioPlayerIdle;
       
   849         RUBY_DEBUG0( "CTTSAlgorithmManager::InitializeComplete ok" );
       
   850         }
       
   851     else
       
   852         {
       
   853         iAudioState = ETTSAudioPlayerError;
       
   854         RUBY_DEBUG0( "CTTSAlgorithmManager::InitializeComplete ERROR" );
       
   855         }
       
   856         
       
   857     if ( iAudioWait.IsStarted() )
       
   858         {
       
   859         RUBY_DEBUG0( "DEVTTS iAudioWait.AsyncStop()" );                	
       
   860         iAudioWait.AsyncStop();
       
   861         }                   
       
   862     }
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 // CTTSAlgorithmManager::MdtaoBufferToBeFilled
       
   866 // Audio player wants a new buffer so that it can be played.
       
   867 // -----------------------------------------------------------------------------
       
   868 //
       
   869 void CTTSAlgorithmManager::MdtaoBufferToBeFilled( TDes8& aBuffer, 
       
   870                                                   TInt aSizeRequested )
       
   871     {
       
   872     RUBY_DEBUG1( "CTTSAlgorithmManager::MdtaoBufferToBeFilled size of wanted audio buffer: %d bytes", aSizeRequested );
       
   873     
       
   874     // Sometimes it might happen that we get still one callback even though
       
   875     // DevSound is not anymore playing
       
   876     if ( iAudioState != ETTSAudioPlayerPlaying )
       
   877         {
       
   878         RUBY_DEBUG0( "CTTSAlgorithmManager::MdtaoBufferToBeFilled called even though iAudioState != ETTSAudioPlayerPlaying" );
       
   879         return;
       
   880         }
       
   881 
       
   882     const TUint8* buffer = iPlaybackBuffer.Ptr();
       
   883     
       
   884     if ( iStartPoint >= iStopPoint )
       
   885         {
       
   886         // Underflow, nothing to be sent to audio out
       
   887         aBuffer.FillZ( aSizeRequested );
       
   888         aBuffer.SetLength( aSizeRequested );
       
   889         
       
   890         iAudio->PlayData( iLastBufferFromTts );
       
   891         return;
       
   892         }
       
   893     
       
   894     TInt copyLength = 0;
       
   895     // Tells if the whole buffer given by TtsHwDevice has been played
       
   896     TBool last = EFalse;
       
   897     
       
   898     if ( ( iStartPoint + aSizeRequested ) >= iStopPoint )
       
   899         {
       
   900         // We get to the end of the data that needs to be played
       
   901         last = ETrue;
       
   902         copyLength = iStopPoint - iStartPoint + 1;
       
   903         
       
   904         // Empty buffer
       
   905         aBuffer.FillZ();
       
   906         }
       
   907     else
       
   908         {
       
   909         // Fill the whole requested size
       
   910         copyLength = aSizeRequested;
       
   911         }
       
   912     
       
   913     // Copy data to audio out buffer
       
   914     aBuffer.Copy( &buffer[iStartPoint], copyLength);
       
   915 
       
   916 #ifdef DEVTTS_3DB_HACK
       
   917 	if( iApplyGain ) 
       
   918 	{
       
   919 		const TInt32 KSqrt2FXP = 0x00002d41L;
       
   920 		const TInt32 KSqrt2Shift = 13;
       
   921 		TPtr16 audioData((TUint16*)(aBuffer.Ptr()), copyLength/2, copyLength/2);
       
   922 		for( int i=0; i<copyLength/2; ++i )
       
   923 		{
       
   924 			TInt16 sample = audioData[i];
       
   925 			TInt32 newvalue = (sample * KSqrt2FXP) >> KSqrt2Shift; 
       
   926 			if(newvalue > 0x7fffL | newvalue < -0x8000L) 
       
   927 			{
       
   928 				
       
   929 				iApplyGain = EFalse;
       
   930 				break;
       
   931 			}
       
   932 			audioData[i] = newvalue;
       
   933 		}
       
   934 	}
       
   935 #endif
       
   936     
       
   937     // Notify TtsHwDevice
       
   938     if ( last )
       
   939         {
       
   940         iHw->BufferProcessed( iPlaybackBuffer );
       
   941         }
       
   942     
       
   943     RUBY_DEBUG1( "CTTSAlgorithmManager::MdtaoBufferToBeFilled Audio buffer size filled: %d bytes\n", aBuffer.Length() );
       
   944     
       
   945     iStartPoint = iStartPoint + copyLength;
       
   946     
       
   947     iAudio->PlayData( iLastBufferFromTts );
       
   948     }
       
   949 
       
   950 // -----------------------------------------------------------------------------
       
   951 // CTTSAlgorithmManager::PlayFinished
       
   952 // Checks the incoming error code and sets the audio state accordingly.
       
   953 // -----------------------------------------------------------------------------
       
   954 //
       
   955 void CTTSAlgorithmManager::MdtaoPlayFinished( TInt aError )
       
   956     {
       
   957     iAudioState = ETTSAudioPlayerIdle;
       
   958     
       
   959     if ( aError == KErrNone ) 
       
   960         {
       
   961         // Don't put error code to aError since MthdTtsCompleted can
       
   962         // be called with error code before this function is called
       
   963         RUBY_DEBUG0( "CTTSAlgorithmManager::MdtaoPlayFinished ok" );
       
   964         }
       
   965     else
       
   966         {
       
   967         // Audio is interrupted by something with higher priority.
       
   968         // Keep idle state for audio player since application might
       
   969         // try again with better luck. (When there is no other apps trying
       
   970         // to access audio out.)
       
   971         iError = aError;
       
   972         
       
   973         // Stop TTS Hw device too
       
   974         iHw->Stop();
       
   975         
       
   976         RUBY_DEBUG0( "CTTSAlgorithmManager::MdtaoPlayFinished audio interrupted" );
       
   977         }
       
   978  
       
   979     // Move automatically to stopped state
       
   980     iState = EDevTTSStopped;
       
   981     
       
   982     // Call the client
       
   983     iObserver.MdtoEvent( EDevTTSEventComplete, iError );
       
   984     }
       
   985 
       
   986 
       
   987 
       
   988 // ========================== CALLBACKS FROM TtsHwDevice =======================
       
   989 
       
   990 
       
   991 // -----------------------------------------------------------------------------
       
   992 // CTTSAlgorithmManager::MthdTtsCompleted
       
   993 // Called by TtsHwDevice when synthesis has completed
       
   994 // -----------------------------------------------------------------------------
       
   995 //
       
   996 void CTTSAlgorithmManager::MthdTtsCompleted( TInt aStatus )
       
   997     {
       
   998     iState = EDevTTSStopped;
       
   999     
       
  1000     // Mark that previous received buffer is the last one
       
  1001     iLastBufferFromTts = ETrue;
       
  1002     
       
  1003     iError = aStatus;
       
  1004     
       
  1005     // Do the callback to client, handled by MdtaoPlayFinished if in sound device mode
       
  1006     if ( iMode == EDevTTSClientMode )
       
  1007         {
       
  1008         iObserver.MdtoEvent( EDevTTSEventComplete, aStatus );
       
  1009         }
       
  1010 
       
  1011 #ifdef DEVTTS_AUDIOBUFFER_TO_FILE
       
  1012     iFile.Close();
       
  1013     iFileOpen = EFalse;
       
  1014 #endif
       
  1015     }
       
  1016 
       
  1017 // -----------------------------------------------------------------------------
       
  1018 // CTTSAlgorithmManager::MthdCustomEvent
       
  1019 // Custom event from TtsHwDevice
       
  1020 // -----------------------------------------------------------------------------
       
  1021 //
       
  1022 void CTTSAlgorithmManager::MthdCustomEvent( TInt /*aEvent*/, TInt /*aStatus*/, 
       
  1023                                            const TDesC8& /*aParameter*/ )
       
  1024     {
       
  1025     }
       
  1026 
       
  1027 // -----------------------------------------------------------------------------
       
  1028 // CTTSAlgorithmManager::MthdProcessBuffer
       
  1029 // Prepares buffer for playback or forwards callback to client, depends on the
       
  1030 // operation mode.
       
  1031 // -----------------------------------------------------------------------------
       
  1032 //
       
  1033 void CTTSAlgorithmManager::MthdProcessBuffer( const TDesC8& aBuffer )
       
  1034     {
       
  1035     RUBY_DEBUG0( "CTTSAlgorithmManager::MthdProcessBuffer" );
       
  1036     
       
  1037 #ifdef DEVTTS_AUDIOBUFFER_TO_FILE
       
  1038     if ( iFileOpen == EFalse )
       
  1039         {
       
  1040         TFileName filename;
       
  1041         filename.Append( KAudioBufferFileName );
       
  1042         filename.AppendNum( iFileCounter );
       
  1043         filename.Append( KAudioBufferFileNameExtension );
       
  1044 
       
  1045         iFile.Replace( iSession, filename, EFileWrite );
       
  1046         iFileOpen = ETrue;
       
  1047         iFileCounter++;
       
  1048         }
       
  1049     TInt size( 0 );
       
  1050     iFile.Size( size );
       
  1051     iFile.Seek( ESeekEnd, size );
       
  1052     iFile.Write( aBuffer );
       
  1053 #endif
       
  1054 
       
  1055     // Handle buffer internally if in sound device mode, otherwise just 
       
  1056     // forward the callback to client
       
  1057     if ( iMode == EDevTTSSoundDeviceMode )
       
  1058         {
       
  1059         // Store pointer to buffer
       
  1060         iPlaybackBuffer.Set( aBuffer );
       
  1061         // Mark start and stop points for the audio playback
       
  1062         iStartPoint = 0;
       
  1063         iStopPoint = aBuffer.Size() - 1;
       
  1064         }
       
  1065     else
       
  1066         {
       
  1067         iObserver.MdtoProcessBuffer( aBuffer );
       
  1068         }
       
  1069     }
       
  1070 
       
  1071 // -----------------------------------------------------------------------------
       
  1072 // CTTSAlgorithmManager::MthdoConfigurationData
       
  1073 // Forwards callback to client.
       
  1074 // -----------------------------------------------------------------------------
       
  1075 //
       
  1076 HBufC8* CTTSAlgorithmManager::MthdoConfigurationData( TUint32 aPackageType, 
       
  1077                                                       TUint32 aPackageID,
       
  1078                                                       TUint32 aStartPosition,
       
  1079                                                       TUint32 aEndPosition )
       
  1080     {
       
  1081     return iObserver.MdtoConfigurationData( aPackageType, aPackageID, 
       
  1082                                             aStartPosition, aEndPosition );
       
  1083     }
       
  1084 
       
  1085 
       
  1086 // ====================== CALLBACKS FROM MASRSTtpHwDeviceObserver ==============
       
  1087 
       
  1088 // -----------------------------------------------------------------------------
       
  1089 // CTTSAlgorithmManager::MathdoConfigurationData
       
  1090 // Forwards callback to client.
       
  1091 // -----------------------------------------------------------------------------
       
  1092 //
       
  1093 HBufC8* CTTSAlgorithmManager::MathdoConfigurationData( TUint32 aPackageType, 
       
  1094                                                        TUint32 aPackageID,
       
  1095                                                        TUint32 aStartPosition,
       
  1096                                                        TUint32 aEndPosition )
       
  1097     {
       
  1098     return iObserver.MdtoConfigurationData( aPackageType, aPackageID, 
       
  1099                                             aStartPosition, aEndPosition );
       
  1100     }
       
  1101 
       
  1102 // -----------------------------------------------------------------------------
       
  1103 // CTTSAlgorithmManager::MathdoWordListReady
       
  1104 // Should not be called since we always use synchrnous TTP.
       
  1105 // -----------------------------------------------------------------------------
       
  1106 //
       
  1107 void CTTSAlgorithmManager::MathdoWordListReady( const TInt /*aError*/ )
       
  1108     {
       
  1109     // Do nothing
       
  1110     }
       
  1111 
       
  1112 
       
  1113 
       
  1114 // ====================== CALLBACKS FROM MNlpHwDeviceObserver ==================
       
  1115 
       
  1116 
       
  1117 // -----------------------------------------------------------------------------
       
  1118 // MNlpHwDeviceObserver::MnhdNlpCompleted
       
  1119 // Called when asynchronous NLP processing has been completed
       
  1120 // -----------------------------------------------------------------------------
       
  1121 //
       
  1122 void CTTSAlgorithmManager::MnhdoNlpCompleted( TInt /*aStatus*/ )
       
  1123     {
       
  1124     // Should not be called currently since NLP is handled synchronously
       
  1125     }
       
  1126 
       
  1127 // -----------------------------------------------------------------------------
       
  1128 // CTTSAlgorithmManager::MnhdoConfigurationData
       
  1129 // NLP calls when it needs its configuration data to be loaded
       
  1130 // -----------------------------------------------------------------------------
       
  1131 //
       
  1132 HBufC8* CTTSAlgorithmManager::MnhdoConfigurationData( TUint32 aPackageType, 
       
  1133                                                       TUint32 aPackageID, 
       
  1134                                                       TUint32 aStartPosition, 
       
  1135                                                       TUint32 aEndPosition )
       
  1136     {
       
  1137     return iObserver.MdtoConfigurationData( aPackageType, aPackageID, 
       
  1138                                             aStartPosition, aEndPosition );
       
  1139     }
       
  1140 
       
  1141 // -----------------------------------------------------------------------------
       
  1142 // CTTSAlgorithmManager::MnhdoStyleL
       
  1143 // Called when NLP needs style information
       
  1144 // -----------------------------------------------------------------------------
       
  1145 //
       
  1146 const TTtsStyle& CTTSAlgorithmManager::MnhdoStyleL( TTtsStyleID styleID )
       
  1147     {
       
  1148     // Call TtsHwDevice to get the wanted style
       
  1149     return iHw->StyleL( styleID );
       
  1150     }
       
  1151 
       
  1152 
       
  1153 // ====================== New additions for SIND inc3 ==========================
       
  1154 
       
  1155 
       
  1156 // -----------------------------------------------------------------------------
       
  1157 // CTTSAlgorithmManager::LanguageIdentificationL
       
  1158 // Does language identification.
       
  1159 // -----------------------------------------------------------------------------
       
  1160 //
       
  1161 void CTTSAlgorithmManager::LanguageIdentificationL( CTtsParsedText& aText, 
       
  1162                                                     TInt aNumberOfGuesses, 
       
  1163                                                     RArray<TLanguage>& aLanguages,
       
  1164                                                     RArray<TInt>& aScores )
       
  1165     {
       
  1166     CheckStateL();
       
  1167 
       
  1168     // Check that at least some text is given
       
  1169     if ( aText.Text() == KNullDesC16 )
       
  1170         {
       
  1171         User::Leave( KErrArgument);
       
  1172         }
       
  1173  
       
  1174     // Call TtpHwDevice
       
  1175     iTtpHw->LanguageIdentificationL( aText.Text(), aNumberOfGuesses, aLanguages, aScores );
       
  1176     }
       
  1177 
       
  1178 // -----------------------------------------------------------------------------
       
  1179 // CTTSAlgorithmManager::NormalizeTextL
       
  1180 // Normalizes text using NLPHwDevice
       
  1181 // -----------------------------------------------------------------------------
       
  1182 //
       
  1183 void CTTSAlgorithmManager::NormalizeTextL( CTtsParsedText& aText )
       
  1184     {
       
  1185     if ( iNlp == NULL || !iNlpInitialized )
       
  1186         {
       
  1187         User::Leave( KErrNotSupported );
       
  1188         }
       
  1189 
       
  1190     CheckStateL();
       
  1191 
       
  1192     iNlp->NormalizeTextL( aText );
       
  1193     }
       
  1194 
       
  1195 // -----------------------------------------------------------------------------
       
  1196 // CTTSAlgorithmManager::NormalizeAndSegmentTextL
       
  1197 // Normalizes and segments the text using NLPHwDevice
       
  1198 // -----------------------------------------------------------------------------
       
  1199 //
       
  1200 void CTTSAlgorithmManager::NormalizeAndSegmentTextL( CTtsParsedText& aText )
       
  1201     {
       
  1202     if ( iNlp == NULL || !iNlpInitialized )
       
  1203         {
       
  1204         User::Leave( KErrNotSupported );
       
  1205         }
       
  1206 
       
  1207     CheckStateL();
       
  1208 
       
  1209     iNlp->NormalizeAndSegmentTextL( aText );
       
  1210     }
       
  1211 
       
  1212 
       
  1213 // ========================== PRIVATE FUNCTIONS ================================
       
  1214 
       
  1215 
       
  1216 // -----------------------------------------------------------------------------
       
  1217 // CTTSAlgorithmManager::CheckStateL
       
  1218 // Checks that state of DevTTS is idle.
       
  1219 // -----------------------------------------------------------------------------
       
  1220 //
       
  1221 void CTTSAlgorithmManager::CheckStateL()
       
  1222     {
       
  1223     if ( iState == EDevTTSNotInitialized )
       
  1224         {
       
  1225         User::Leave( KErrNotReady );
       
  1226         }
       
  1227     
       
  1228     if ( iState != EDevTTSStopped )
       
  1229         {
       
  1230         User::Leave( KErrInUse );
       
  1231         }
       
  1232     }
       
  1233 
       
  1234 
       
  1235 // End of File