⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 texttospeechexample.cpp

📁 了解 Symbian Operation Symtem C++ S60 的基本开发
💻 CPP
字号:
/*
* ============================================================================
*  Name     : TextToSpeechExample.cpp
*  Part of  : TextToSpeech example
*  Created  : 05.07.2006 by Artem Marchenko
*  Description:
*     TextToSpeechExample.cpp - source file
*  Version  : 1.0
*  Copyright: Artem Marchenko 2006, http://symbianexample.com
* ============================================================================
*/


//  Include Files  

#include "TextToSpeechExample.h"
#include <e32base.h>
#include <e32std.h>
// Console
#include <e32cons.h>            

#include "TtsPlayer.h"

//  Constants

_LIT( KTextConsoleTitle, "Console" );
_LIT( KTextFailed, " failed, leave code = %d" );
_LIT( KTextPressAnyKey, " [press any key]\n" );


//  Global Variables

LOCAL_D CConsoleBase* console;  // write all messages to this


//  Local Functions

// Command line arguments are instantly available in S60 2nd
// while in S60 3rd getting them is a bit more complex and
// is out of scope of this example
#ifndef EKA2
LOCAL_C void MainL( const TDesC&/* aArgs*/ )
#else
LOCAL_C void MainL()
#endif
    {

    //
    // add your program code here, example code below
    //
	CTtsPlayer* player = CTtsPlayer::NewLC();
	_LIT( KTextToSay, "All your voices are belong to us!" );
	TBuf<100> bTextToSay( KTextToSay );

	TRAPD( err, player->PlayTextL( bTextToSay ) );
	if( err != KErrNone ) 
		{
		TBuf<200> message;
		message.Format( _L( "TTS playback failed with [%d]" ), err );
		RDebug::Print( message );
		console->Write( message );
		}
	else 
		{
		RDebug::Print( _L( "TTS playback completed successfully" ) );
		console->Write( _L( "TTS playback completed successfully" ) );
		}
	CleanupStack::PopAndDestroy( player );
    }


LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler();
    CleanupStack::PushL( scheduler );
    CActiveScheduler::Install( scheduler );

    // Call main function ( in EKA1 - with command line)
	// Command line arguments are instantly available in S60 2nd
	// while in S60 3rd getting them is a bit more complex and
	// is out of scope of this example
#ifdef EKA2
	MainL();
#else
    TBuf<256> cmdLine;
	RProcess().CommandLine( cmdLine );
    MainL( cmdLine );
#endif
    // Delete active scheduler
    CleanupStack::PopAndDestroy(scheduler);
    }


//  Global Functions

GLDEF_C TInt Start()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    // Create output console
    TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
    if (createError)
        return createError;

    // Run application code inside TRAP harness, wait keypress when terminated
    TRAPD(mainError, DoStartL());
    if (mainError)
        console->Printf(KTextFailed, mainError);
    console->Printf(KTextPressAnyKey);
    console->Getch();
    
    delete console;
    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }


//  Exported Functions

#if ( defined( __WINS__ ) && !defined( EKA2 ) )
EXPORT_C TInt WinsMain(TAny* /*aParam*/)
    {
    return Start();
    }
#else
GLDEF_C TInt E32Main()
    {
    return Start();
    }
#endif

#if ( defined(__WINS__) && !defined(EKA2) )
TInt E32Dll(TDllReason /*aReason*/)
    {
    return KErrNone;
    }
#endif


// End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -