Commit 697e5661 authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Adding text-to-speech signal source classes

parent 353a55e4
#include "VATextToSpeechSignalSource.h"
#include "../VAAudiostreamTracker.h"
#include "../VACoreImpl.h"
#include "../VALog.h"
#include <ITAAudiofileReader.h>
#include <ITAConstants.h>
#include <ITAException.h>
#include <ITASampleFrame.h>
#include <sstream>
#include <assert.h>
#include <math.h>
CVATextToSpeechSignalSource::CVATextToSpeechSignalSource( const CVATextToSpeechSignalSource::Config& oConfig )
: ITADatasourceRealization( 1, oConfig.pCore->GetCoreConfig()->oAudioDriverConfig.dSampleRate, oConfig.pCore->GetCoreConfig()->oAudioDriverConfig.iBuffersize )
, m_oConfig( oConfig )
, m_pAssociatedCore( NULL )
{
m_sbOut.Init( GetBlocklength(), true );
}
CVATextToSpeechSignalSource::~CVATextToSpeechSignalSource()
{
}
int CVATextToSpeechSignalSource::GetType() const
{
return IVAAudioSignalSource::VA_SS_TEXT_TO_SPEECH;
}
std::string CVATextToSpeechSignalSource::GetTypeString() const
{
return "text-to-speech";
}
std::string CVATextToSpeechSignalSource::GetDesc() const
{
return std::string( "Creates a machine that can be started and stopped" );
}
IVACore* CVATextToSpeechSignalSource::GetAssociatedCore() const
{
return m_oConfig.pCore;
}
const float* CVATextToSpeechSignalSource::GetStreamBlock( const CVAAudiostreamState* pStreamInfo )
{
m_sbOut.Zero();
// @todo: take samples from generated WAV file
return m_sbOut.data();
}
void CVATextToSpeechSignalSource::HandleRegistration( IVACore* pCore )
{
m_pAssociatedCore = pCore;
}
void CVATextToSpeechSignalSource::HandleUnregistration( IVACore* )
{
m_pAssociatedCore = NULL;
}
std::string CVATextToSpeechSignalSource::GetStateString() const
{
return "undefined";
}
void CVATextToSpeechSignalSource::Reset()
{
}
CVAStruct CVATextToSpeechSignalSource::GetParameters( const CVAStruct& oArgs ) const
{
CVAStruct oRet;
if( oArgs.IsEmpty() )
{
oRet[ "info" ] = "Parameters of TTS signal source will be delivered through this struct";
oRet[ "preparation_process" ] = 0.9;
oRet[ "ready_for_playback" ] = false;
oRet[ "prepare_speech" ] = "Halleluja!";
oRet[ "start_talking" ] = false;
}
return oRet;
}
void CVATextToSpeechSignalSource::SetParameters( const CVAStruct& oParams )
{
if( oParams.HasKey( "start_talking" ) )
{
// Do something, if possible
return;
}
if( oParams.HasKey( "prepare_speech" ) )
{
if( !oParams[ "prepare" ].IsString() )
VA_EXCEPT2( INVALID_PARAMETER, "Text of speech has be be a string" );
std::string sText = oParams[ "prepare" ];
// Prepare a WAV file or sample buffer with text-to-speech engine output
return;
}
VA_WARN( "CVATextToSpeechSignalSource", "Could not interpret parameters for text-to-speech signal source setter method, use empty getter for help" );
return;
}
#ifndef IW_VA_TEXT_TO_SPEECH_SIGNAL_SOURCE
#define IW_VA_TEXT_TO_SPEECH_SIGNAL_SOURCE
#include <VAAudioSignalSource.h>
#include <VAObject.h>
#include <ITADataSourceRealization.h>
#include <ITASampleBuffer.h>
#include <ITAAtomicPrimitives.h>
class CVACoreImpl;
/** Text-to-speech signal source
*
* The TTS signal source generates sound from text using external libraries, like TTSRelay for Windows platforms.
*/
class CVATextToSpeechSignalSource : public IVAAudioSignalSource, public ITADatasourceRealization
{
public:
class Config
{
public:
CVACoreImpl* pCore;
Config( CVACoreImpl* pCore ) : pCore( pCore )
{
SetDefaults();
};
virtual void SetDefaults()
{
}
private:
Config();
};
CVATextToSpeechSignalSource( const Config& );
virtual ~CVATextToSpeechSignalSource();
int GetType() const;
std::string GetTypeString() const;
std::string GetDesc() const;
IVACore* GetAssociatedCore() const;
const float* GetStreamBlock( const CVAAudiostreamState* );
void HandleRegistration( IVACore* );
void HandleUnregistration( IVACore* );
std::string GetStateString() const;
void SetParameters( const CVAStruct& );
CVAStruct GetParameters( const CVAStruct& ) const;
void Reset();
private:
IVACore* m_pAssociatedCore;
Config m_oConfig;
ITASampleBuffer m_sbOut;
};
#endif // IW_VA_TEXT_TO_SPEECH_SIGNAL_SOURCE
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment