srsf/speechsynthesis/tsrc/testapplication/src/testappengine.cpp
branchRCL_3
changeset 23 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "testappengine.h"
       
    22 
       
    23 #include "rubydebug.h"
       
    24 
       
    25 
       
    26 _LIT( KText, "This is a text sample for TTS test. 1 2 3 45 End :) :-) :-(");
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ----------------------------------------------------------
       
    31 // CTestAppEngine::NewL()
       
    32 // 
       
    33 // ----------------------------------------------------------
       
    34 //
       
    35 CTestAppEngine* CTestAppEngine::NewL( CTestAppAppUi& aAppUi )
       
    36     {
       
    37     RUBY_DEBUG_BLOCK( "CTestAppEngine::NewL" );
       
    38     
       
    39     CTestAppEngine* self = new( ELeave ) CTestAppEngine( aAppUi );
       
    40     
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop( self );
       
    44     
       
    45     return self;    
       
    46     }
       
    47     
       
    48 // ----------------------------------------------------------
       
    49 // CTestAppEngine::ConstructL()
       
    50 // 
       
    51 // ----------------------------------------------------------
       
    52 //
       
    53 void CTestAppEngine::ConstructL() 
       
    54     {
       
    55     // Add ourselves to active scheduler
       
    56     CActiveScheduler::Add( this );
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------
       
    60 // CTestAppEngine::CTestAppEngine()
       
    61 // 
       
    62 // ----------------------------------------------------
       
    63 //
       
    64 CTestAppEngine::CTestAppEngine( CTestAppAppUi& aAppUi ) :
       
    65     CActive( EPriorityStandard ),
       
    66     iAppUi( aAppUi ),
       
    67     iVoiceIndex( -1 ),
       
    68     iRate( -1 )
       
    69     {
       
    70     }
       
    71     
       
    72 // ----------------------------------------------------
       
    73 // CTestAppEngine::~CTestAppEngine()
       
    74 // Destructor
       
    75 // Frees reserved resources
       
    76 // ----------------------------------------------------
       
    77 //
       
    78 CTestAppEngine::~CTestAppEngine()
       
    79     {
       
    80     Cancel();
       
    81     
       
    82     iServer.Close();    
       
    83     iVoices.Close();
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------
       
    87 // CTestAppEngine::RunL
       
    88 // 
       
    89 // ----------------------------------------------------
       
    90 //
       
    91 void CTestAppEngine::RunL()
       
    92     {
       
    93     RUBY_DEBUG_BLOCK( "CTestAppEngine::RunL" );
       
    94     
       
    95     switch ( iState )
       
    96         {
       
    97         case EPriming:
       
    98         
       
    99             if ( iStatus == KErrNone ) 
       
   100                 {
       
   101                 TRAP_IGNORE(
       
   102                     TTimeIntervalMicroSeconds duration = iServer.DurationL();
       
   103                     iAppUi.ChangeTextL( 4, _L("Duration (ms)"), 
       
   104                                         duration.Int64() / 1000 );
       
   105                      );
       
   106                 
       
   107                 PlayL();
       
   108                 }
       
   109             else
       
   110                 {
       
   111                 User::Leave( iStatus.Int() );
       
   112                 }
       
   113                 
       
   114             break;
       
   115         
       
   116         case ESpeaking:
       
   117         
       
   118             if ( iStatus == KErrNone )
       
   119                 {
       
   120                 iAppUi.ChangeTextL( 0, _L("Server: Connected") );
       
   121                 iAppUi.ChangeTextL( 4, _L("Duration (ms)"), 0 );
       
   122                 }
       
   123             else if ( iStatus == KErrCancel )
       
   124                 {
       
   125                 iAppUi.ChangeTextL( 0, _L("Server: Paused") );
       
   126                 }
       
   127             else if ( iStatus == KErrAbort )
       
   128                 {
       
   129                 iAppUi.ChangeTextL( 0, _L("Server: Stopped") );
       
   130                 }
       
   131             else
       
   132                 {
       
   133                 User::Leave( iStatus.Int() );
       
   134                 }
       
   135             
       
   136             iState = EIdle;
       
   137             
       
   138             break;
       
   139             
       
   140         default:
       
   141             
       
   142             break;
       
   143             
       
   144         }
       
   145     }
       
   146     
       
   147 // ----------------------------------------------------
       
   148 // CTestAppEngine::DoCancel
       
   149 // 
       
   150 // ----------------------------------------------------
       
   151 //
       
   152 void CTestAppEngine::DoCancel()
       
   153     {
       
   154     RUBY_DEBUG0( "CTestAppEngine::DoCancel" );
       
   155     
       
   156     TRAP_IGNORE( iServer.StopL() );
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------
       
   160 // Connect to the server
       
   161 // 
       
   162 // ----------------------------------------------------
       
   163 //
       
   164 void CTestAppEngine::ConnectL()
       
   165     {
       
   166     User::LeaveIfError( iServer.Open() );
       
   167 
       
   168     iVoice = iServer.VoiceL();
       
   169     iVolume = iServer.VolumeL();
       
   170     iRate = iServer.SpeakingRateL();
       
   171     
       
   172     iAppUi.ChangeTextL( 1, iVoice.iVoiceName, iVoice.iLanguage );
       
   173     iAppUi.ChangeTextL( 2, _L("Volume"), iVolume );
       
   174     iAppUi.ChangeTextL( 3, _L("Speking Rate"), iRate );
       
   175     }
       
   176 
       
   177 // ----------------------------------------------------
       
   178 // Disconnect from server    
       
   179 // 
       
   180 // ----------------------------------------------------
       
   181 //
       
   182 void CTestAppEngine::DisconnectL()
       
   183     {
       
   184     Cancel();
       
   185     
       
   186     iServer.Close();
       
   187     }
       
   188 
       
   189 // ----------------------------------------------------
       
   190 // CTestAppEngine::InitTextL
       
   191 // 
       
   192 // ----------------------------------------------------
       
   193 //
       
   194 void CTestAppEngine::InitTextL()
       
   195     {
       
   196     iAppUi.ChangeTextL( 0, _L("Server: Initializing") ); 
       
   197     
       
   198     iServer.SetVolumeL( iVolume );
       
   199     
       
   200     if ( iRate > 0 && iRate <= 100 )
       
   201         {
       
   202         iServer.SetSpeakingRateL( iRate );
       
   203         }
       
   204         
       
   205     Cancel();
       
   206     SetActive();
       
   207     iState = EPriming;
       
   208     
       
   209     iServer.InitialiseSynthesis( KText, iStatus );
       
   210     }
       
   211 
       
   212 // ----------------------------------------------------
       
   213 // CTestAppEngine::InitToTextFileL
       
   214 // 
       
   215 // ----------------------------------------------------
       
   216 //
       
   217 void CTestAppEngine::InitTextToFileL()
       
   218     {
       
   219     iFileName = _L("C:\\test.raw");
       
   220     
       
   221     iAppUi.ChangeTextL( 0, _L("Server: Initializing") ); 
       
   222         
       
   223     iServer.SetVolumeL( iVolume );
       
   224     iServer.SetSpeakingRateL( iRate );
       
   225     
       
   226     Cancel();
       
   227     SetActive();
       
   228     iState = EPriming;
       
   229     
       
   230     iServer.InitialiseSynthesis( KText, iFileName, iStatus );
       
   231     }
       
   232 
       
   233 // ----------------------------------------------------
       
   234 // CTestAppEngine::PauseL
       
   235 // 
       
   236 // ----------------------------------------------------
       
   237 //
       
   238 void CTestAppEngine::PauseL()
       
   239     {
       
   240     iAppUi.ChangeTextL( 0, _L("Server: Paused") );
       
   241     iServer.PauseL();
       
   242     }
       
   243 
       
   244 // ----------------------------------------------------
       
   245 // CTestAppEngine::PlayL
       
   246 // 
       
   247 // ----------------------------------------------------
       
   248 //
       
   249 void CTestAppEngine::PlayL()
       
   250     {
       
   251     iAppUi.ChangeTextL( 0, _L("Server: Speaking") );
       
   252     
       
   253     Cancel();
       
   254     SetActive();
       
   255     iState = ESpeaking;
       
   256         
       
   257     iServer.Synthesise( iStatus );
       
   258     }
       
   259 
       
   260 // ----------------------------------------------------
       
   261 // CTestAppEngine::StopL
       
   262 // 
       
   263 // ----------------------------------------------------
       
   264 //
       
   265 void CTestAppEngine::StopL()
       
   266     {
       
   267     iAppUi.ChangeTextL( 0, _L("Server: Stopped") );
       
   268     iServer.StopL();
       
   269     }
       
   270 
       
   271 // ----------------------------------------------------
       
   272 // CTestAppEngine::ChangeVoiceL
       
   273 // 
       
   274 // ----------------------------------------------------
       
   275 //
       
   276 TVoice CTestAppEngine::ChangeVoiceL()
       
   277     {
       
   278     if ( iVoiceIndex < 0 )
       
   279         {
       
   280         FetchSupportedLanguagesAndVoicesL();
       
   281         }
       
   282     
       
   283     iVoiceIndex++;
       
   284     
       
   285     if ( iVoiceIndex >= iVoices.Count() )
       
   286         {
       
   287         iVoiceIndex = 0;
       
   288         }
       
   289     
       
   290     iVoice = iVoices[iVoiceIndex];
       
   291     
       
   292     iServer.SetVoiceL( iVoice );
       
   293     
       
   294     return iVoice;
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------
       
   298 // CTestAppEngine::VolumeDownL
       
   299 // 
       
   300 // ----------------------------------------------------
       
   301 //
       
   302 TInt CTestAppEngine::VolumeDownL()
       
   303     {
       
   304     TInt volumeStep = iServer.MaxVolumeL() / 10;
       
   305     
       
   306     iServer.SetVolumeL( iVolume - volumeStep );
       
   307     iVolume = iServer.VolumeL();
       
   308 
       
   309     return iVolume;
       
   310     }
       
   311 
       
   312 // ----------------------------------------------------
       
   313 // CTestAppEngine::VolumeUpL  
       
   314 // 
       
   315 // ----------------------------------------------------
       
   316 //
       
   317 TInt CTestAppEngine::VolumeUpL()
       
   318     {
       
   319     TInt volumeStep = iServer.MaxVolumeL() / 10;
       
   320     
       
   321     iServer.SetVolumeL( iVolume + volumeStep );
       
   322     iVolume = iServer.VolumeL();
       
   323 
       
   324     return iVolume;
       
   325     }
       
   326 
       
   327 // ----------------------------------------------------
       
   328 // CTestAppEngine::RateUpL  
       
   329 // 
       
   330 // ----------------------------------------------------
       
   331 //
       
   332 TInt CTestAppEngine::RateUpL()
       
   333     {
       
   334     TInt newRate = iRate + 10;
       
   335     
       
   336     if ( newRate > iServer.MaxSpeakingRateL() )
       
   337         {
       
   338         newRate = 10;
       
   339         }
       
   340     
       
   341     iRate = newRate;
       
   342     
       
   343     return iRate;
       
   344     }
       
   345     
       
   346 // ----------------------------------------------------
       
   347 // CTestAppEngine::ChangeAudioOutputL
       
   348 // 
       
   349 // ----------------------------------------------------
       
   350 //
       
   351 void CTestAppEngine::ChangeAudioOutputL()    
       
   352     {
       
   353     iCurrentAudioOutput++;
       
   354     
       
   355     if ( iCurrentAudioOutput > RSpeechSynthesis::ETtsOutputPublic )
       
   356         {
       
   357         iCurrentAudioOutput = 0;
       
   358         }
       
   359     
       
   360     iServer.SetAudioOutputL( (RSpeechSynthesis::TTtsAudioOutput) iCurrentAudioOutput );
       
   361     }
       
   362     
       
   363 // ----------------------------------------------------
       
   364 // CTestAppEngine::FetchSupportedLanguagesAndVoicesL
       
   365 // 
       
   366 // ----------------------------------------------------
       
   367 //
       
   368 void CTestAppEngine::FetchSupportedLanguagesAndVoicesL()
       
   369     {
       
   370     RArray<TLanguage> languages;
       
   371     RArray<TVoice> voices;
       
   372 
       
   373     iServer.GetLanguagesL( languages );
       
   374     
       
   375     for ( TInt i( 0 ); i < languages.Count(); i++ )
       
   376         {
       
   377         if ( languages[i] > 0 )
       
   378             {
       
   379             RUBY_DEBUG1( "%d", languages[i] );
       
   380 
       
   381             voices.Reset();
       
   382             iServer.GetVoicesL( voices, languages[i] );
       
   383     
       
   384             for ( TInt j( 0 ); j < voices.Count(); j++ )
       
   385                 {            
       
   386                 RUBY_DEBUG1( "%S", &voices[j].iVoiceName );
       
   387 
       
   388                 iVoices.AppendL( voices[j] );
       
   389                 }        
       
   390             }
       
   391         }
       
   392         
       
   393     voices.Close();
       
   394     languages.Close();
       
   395     }
       
   396 
       
   397 // End of File