Commit 69a4bfb4 authored by jwendt's avatar jwendt
Browse files

Implemented first version of working TTS Signal Source

parent 8f7c2a77
#ifndef IW_VA_TEXT_TO_SPEECH_SIGNAL_SOURCE
#define IW_VA_TEXT_TO_SPEECH_SIGNAL_SOURCE
#include "VAAudiofileSignalSource.h"
#include <VAAudioSignalSource.h>
#include <VAObject.h>
......@@ -8,6 +10,7 @@
#include <ITASampleBuffer.h>
#include <ITAAtomicPrimitives.h>
class ITABufferDatasource;
class CVACoreImpl;
class CPRCEN_engine;
class CPRC_abuf;
......@@ -35,19 +38,24 @@ public:
/*
* This should be used to start a prepared TTS using a CVAStruct with:
* ["play_speech"] = identificator of created speech
* ["prepare_text"] = text to be spoken
* ["id"] = identificator that will be used for playing this speech and reference it (must be unique)
* ["voice"] = the voice to be used //if none is given or the one given cannot be found the standard voice is used (i.e. "Heather")
* ["direct_replay"] = true/false whether the audio should directly be played (in this case no id has to be given, should not be used for lipsyncing)
* This should be used to start a prepared TTS using a CVAStruct with:
* ["play_speech"] = identificator (int) of created speech
* ["free_after"] = true/false, whether the resources can be freed or this sentences should be used again
*/
void SetParameters( const CVAStruct& );
/*
* This can be used to prepare a TTS using a CVAStruct with:
* ["prepare_text"] = text to be spoken
* ["start_talking"] = true/false //whether it should be directly replayed
* ["voice"] = the voice to be used //if none is given or the one given cannot be found the standard voice is used (i.e. "Heather")
* This can be used to receive the viseme data for a created speech
* ["get_visemes_for"] = identificator as given above
* and returns a CVAStruct with:
* ["ready_for_playback"] = true, if no error occured, false otherwise
* ["id"] = identificator that will be used for replying //see above
* ["visemes"] = viseme data for facial animation as xml string
* ["visemes"] = viseme data for facial animation as xml string (empty string if something went wrong with creation)
*
* This can also be used to find the available voices using a CVAStruct with:
* ["list_voices"] = true
......@@ -63,20 +71,50 @@ public:
private:
class TTSEngine{
//This is a wrapper for the CereVoice TTS Engine, which has to be only initialized once and not for each TTSignalSource
public:
TTSEngine();
~TTSEngine();
static TTSEngine& getInstance(){
static TTSEngine instance; // Guaranteed to be destroyed.
return instance;// Instantiated on first use.
}
void SetupPhonemeMapping();
TTSEngine(TTSEngine const&) = delete; //to avoid copies being made etc.
void operator=(TTSEngine const&) = delete;
CPRCEN_engine* getEngine() const;
std::string PhonemeToViseme(std::string phoneme);
private:
/*The engine maintains the list of
loaded voices and makes them available to synthesis channels. */
CPRCEN_engine* m_pTTSEngine; //you must not delete this from outside!!!!!!
std::map<std::string, int> m_phonemeToId;
std::map<int, std::string> m_idToViseme;
};
struct UserCallbackData{
float lastEnd = 0.0f;
std::string visemes = "";
std::vector<float> floatBuffer;
};
static void VisemeProcessing(CPRC_abuf* abuf, void * userdata); //used as callback for the CereVoice engine
static std::string to_string_with_precision(float a_value, const int n = 3);
static std::string PhonemeToViseme(std::string phoneme);
void SetupPhonemeMapping();
IVACore* m_pAssociatedCore;
ITASampleBuffer m_sbOut;
std::map<std::string, ITASampleFrame*> m_AudioSampleFrames;
std::map<std::string, std::string> m_Visemes;
/*The engine maintains the list of
loaded voices and makes them available to synthesis channels. */
CPRCEN_engine* m_pTTSEngine;
IVACore* m_pAssociatedCore;
ITASampleBuffer m_sbOut;
static std::map<std::string, int> m_phonemeToId;
static std::map<int, std::string> m_idToViseme;
//this mutable keyword here is necessary since the inherited method GetParameters() is const, however we want to be able to change some parts (not very clean code, sorry)
ITAAtomicInt m_iCurrentPlayState;
ITABufferDatasource* m_pBufferDataSource;
ITASampleFrame* m_pFrameToDelete;//this is set if the sample should be freed after playback
};
......
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