Hi there,
Recently, I'm developing a Symbian App using Qt.
There is big problem driving me crazy :
I'm Using Qt 4.7 and I wanna Use Text-to-Speech API of S60.
Here is the code :
ttsplayer.h :
#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__
// End of file
#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__
// End of file
To copy to clipboard, switch view to plain text mode
ttsplayer.cpp :
// Include Files
#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 Files
#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
To copy to clipboard, switch view to plain text mode
and in the mainwindow.cpp I use this like this :
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 )
{
qDebug
() <<
QString("TTS playback failed with [%1]").
arg(err
);
}
else
{
qDebug() << "TTS playback completed successfully" ;
}
CleanupStack::PopAndDestroy( player );
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 )
{
qDebug() << QString("TTS playback failed with [%1]").arg(err);
}
else
{
qDebug() << "TTS playback completed successfully" ;
}
CleanupStack::PopAndDestroy( player );
To copy to clipboard, switch view to plain text mode
and I also added these files(ttsplayer.cpp,ttsplayer.h) to symbian in .pro file.
But Now my problem is errors below :
:-1: error: Recipe compile failed with exit code 1.
:-1: error: The make-engine exited with errors.
Please Help.
Thanks in advance.
Bookmarks