1
0
Fork 0

Stop TTS from playing over itself.

Simple blocking of the SGSubsystem until the current
TTS sample has finished playing, allowing a 0.5s
gap between transmissions.  Good radio comms!
This commit is contained in:
Stuart Buchanan 2017-03-20 22:27:10 +00:00
parent 63d8c2fd83
commit 3135d87218
4 changed files with 23 additions and 17 deletions

View file

@ -33,7 +33,7 @@ using std::string;
#include "VoiceSynthesizer.hxx"
FGFLITEVoice::FGFLITEVoice(FGVoiceMgr * mgr, const SGPropertyNode_ptr node, const char * sampleGroupRefName)
: FGVoice(mgr), _synthesizer( NULL)
: FGVoice(mgr), _synthesizer( NULL), _seconds_to_run(0.0)
{
_sampleName = node->getStringValue("desc", node->getPath().c_str());
@ -68,14 +68,21 @@ void FGFLITEVoice::speak(const string & msg)
}
}
void FGFLITEVoice::update()
void FGFLITEVoice::update(double dt)
{
_seconds_to_run -= dt;
if (_seconds_to_run < 0.0) {
SGSharedPtr<SGSoundSample> sample = _sampleQueue.pop();
if (sample.valid()) {
_sgr->remove(_sampleName);
_sgr->add(sample, _sampleName);
_sgr->resume();
_sgr->play(_sampleName, false);
// Don't play any further TTS until we've finished playing this sample,
// allowing 500ms for a gap between transmissions. Good radio comms!
_seconds_to_run = 0.5 + ((float) sample->get_no_samples()) / ((float) sample->get_frequency());
}
}
}

View file

@ -35,7 +35,7 @@ public:
FGFLITEVoice(FGVoiceMgr *, const SGPropertyNode_ptr, const char * sampleGroupRefName = "flite-voice");
virtual ~FGFLITEVoice();
virtual void speak(const std::string & msg);
virtual void update();
virtual void update(double dt);
private:
FGFLITEVoice(const FGFLITEVoice & other);
@ -45,6 +45,7 @@ private:
VoiceSynthesizer * _synthesizer;
SGLockedQueue<SGSharedPtr<SGSoundSample> > _sampleQueue;
std::string _sampleName;
double _seconds_to_run;
};
#endif // _FLITEVOICE_HXX

View file

@ -43,7 +43,7 @@ public:
FGFestivalVoice(FGVoiceMgr *, const SGPropertyNode_ptr);
virtual ~FGFestivalVoice();
virtual void speak( const string & msg );
virtual void update();
virtual void update(double);
void setVolume(double);
void setPitch(double);
void setSpeed(double);
@ -129,14 +129,14 @@ void FGVoiceMgr::shutdown()
}
void FGVoiceMgr::update(double)
void FGVoiceMgr::update(double dt)
{
if (!_enabled)
return;
_paused = !_pausedNode->getBoolValue();
for (unsigned int i = 0; i < _voices.size(); i++) {
_voices[i]->update();
_voices[i]->update(dt);
#if !defined(ENABLE_THREADS)
_voices[i]->speak();
#endif
@ -235,7 +235,7 @@ void FGFestivalVoice::speak( const string & msg )
}
void FGFestivalVoice::update(void)
void FGFestivalVoice::update(double dt)
{
double d;
d = _volumeNode->getDoubleValue();
@ -333,5 +333,3 @@ void FGVoiceMgr::FGVoice::valueChanged(SGPropertyNode *node)
pushMessage(m);
}

View file

@ -99,7 +99,7 @@ public:
FGVoice(FGVoiceMgr * mgr ) : _mgr(mgr) {}
virtual ~FGVoice() {}
virtual void speak( const std::string & msg ) = 0;
virtual void update() = 0;
virtual void update(double dt) = 0;
void pushMessage( const std::string & m);
bool speak();