symbian TTS 研究

本文探讨了Symbian平台下三种语音合成技术方案:利用自定义库进行英文语音播放、调用Symbian插件TTS库支持多国语言、以及采用科大讯飞语音云服务。详细介绍了每种方案的实现过程、关键代码片段,并讨论了不同方案的特点与适用场景。
摘要由CSDN通过智能技术生成

方案一: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 );

mmp中添加

LIBRARY   mediaclientaudio.lib 


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

#include <nssttsutility.h>

#include <nssttsutilityobserver.h>

#include <nssttscommon.h>

继承 MTtsClientUtilityObserver

实现纯虚函数

private:
void MapcCustomCommandEvent( TInt aEvent, TInt aError );
void MapcInitComplete( TInt aError, const TTimeIntervalMicroSeconds& aDuration );
void MapcPlayComplete( TInt aError );

调用代码

TTtsStyle iStyle;
TTtsStyleID iStyleId;
// HBufC* aDes = GetSkinMgr()->GetDescriptionLC(R_MAIN_NDATE);
// CTtsParsedText* iParsedText = CTtsParsedText::NewL(*aDes);
// CleanupStack::PopAndDestroy();
CTtsUtility* iTtsUtility = CTtsUtility::NewL( *this );
// if ( iTtsUtility->NumberOfStyles() > 0 )
//    {
//    // Delete style if exists
//    iTtsUtility->DeleteStyle( iStyleId );
//    }
//  if ( iParsedText->NumberOfSegments() > 0 )
//    {
//    // Remove existing segment from parsed text structure
//    iParsedText->DeleteSegmentL( 0 );
//    }
//  // Use high quality TTS
 iStyle.iQuality = ETtsQualityHighOnly;
 // Use language and speaker set in Speech application. 
 // Also speaking rate and volume is set according to Speech app. 
 iStyle.iLanguage = ELangPrcChinese;
 // Add style
 iStyleId = iTtsUtility->AddStyleL( iStyle );
HBufC* aDes = GetSkinMgr()->GetDescriptionLC(R_MENU_DESCRIBLE_TIPS_4);
 // Initialise with current text and settings.   
// iTtsUtility->OpenDesL(_L("hello this is test"));
iTtsUtility->OpenDesL(*aDes);


CleanupStack::PopAndDestroy();




//  iTtsUtility->OpenParsedTextL( *iParsedText );
 //The command to start playing
 iTtsUtility->Play();
 
//  TInt volume;
//  iTtsUtility->GetVolume( volume );
//  iTtsUtility->SetVolume( volume );
//  iTtsUtility->Stop();

mmp中添加

LIBRARY         nssttsutility.lib nssttscommon.lib


方案三:科大讯飞语音云,注册appid,下载SDK后根据demo制作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值