symbian TTS 方案

方案一:CMdaAudioPlayerUtility播放,支持英文。

#ifndef __TTSPLAYER_H__
#define __TTSPLAYER_H__

头文件
//  Include Files
#include <MdaAudioSamplePlayer.h>
#include <e32base.h>


class CTtsPlayer : public CBase, public MMdaAudioPlayerCallback
{
public:
// construction
static CTtsPlayer* NewLC();
~CTtsPlayer();
/** Simplified call'n'forget interface.
* Synchronous function
* @leave System-wide error codes. @see MMdaAudioPlayerCallback errors
*/
void PlayTextL( TDesC& aText );
// From the observer interface
public:
virtual void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration);
virtual void MapcPlayComplete(TInt aError);
private:
void ConstructL();
private:
CMdaAudioPlayerUtility* iPlayer;
TBool iPlaybackInProgress;
CActiveSchedulerWait* iWaiter;
// Playback error code
TInt iErr;
};




#endif  // __TTSPLAYER_H__

源文件

#include <e32base.h>
#include <e32std.h>
#include <e32def.h>
#include "TtsPlayer.h"


// Prefix telling the audio utility that TTS should be used
_LIT( KTtsPrefix, "(tts)" );


CTtsPlayer* CTtsPlayer::NewLC()
{
CTtsPlayer* self = new (ELeave) CTtsPlayer;
CleanupStack::PushL( self );
self->ConstructL();
return self;
}


CTtsPlayer::~CTtsPlayer()
{
delete iWaiter;
delete iPlayer;
}


void CTtsPlayer::ConstructL()
{
iPlayer = CMdaAudioPlayerUtility::NewL( *this );
iWaiter = new (ELeave) CActiveSchedulerWait;
}


void CTtsPlayer::PlayTextL( TDesC& aText )
{
__ASSERT_ALWAYS( iPlaybackInProgress == EFalse, User::Leave( KErrNotReady ) );
HBufC8* playableText = HBufC8::NewLC( aText.Length() + KTtsPrefix().Length() );
playableText->Des().Append( KTtsPrefix );
playableText->Des().Append( aText );
iPlayer->OpenDesL( *playableText );
iPlaybackInProgress = ETrue;
iWaiter->Start();
// At this point playback is already completed or failed 
User::LeaveIfError( iErr );
CleanupStack::PopAndDestroy( playableText );
}

void CTtsPlayer::MapcInitComplete( TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/ )
{
iErr = aError;
if( aError != KErrNone ) 
{
iPlaybackInProgress = EFalse;
        // Let the paused PlayTextL complete
iWaiter->AsyncStop();
}
else
{
iPlayer->Play();
}
}


void CTtsPlayer::MapcPlayComplete( TInt aError )
{
iErr = aError;
iPlaybackInProgress = EFalse;
    // Let the paused PlayTextL complete
iWaiter->AsyncStop();
}
// End of file


调用代码

#include "TtsPlayer.h"

CTtsPlayer* player = CTtsPlayer::NewLC();
_LIT( KTextToSay, "All your voices are belong to us! we are the hero, the true hero is stack." );
TBuf<100> bTextToSay( KTextToSay );
TRAPD( err, player->PlayTextL( bTextToSay ) );
if( err != KErrNone ) 
{
// TBuf<200> message;
// message.Format( _L( "TTS playback failed with [%d]" ), err );
// iAppView->AddMessageL( message );
}
else 
{
// iAppView->AddMessageL( _L( "TTS playback completed successfully" ) );
}
CleanupStack::PopAndDestroy( player );


方案二:调用symbian 插件 tts 库 支持多国语言

#include <nssttsutility.h>

继承 MTtsClientUtilityObserver

实现纯虚函数
#include <nssttsutilityobserver.h>
#include <nssttscommon.h>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值