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" #include "VoiceSynthesizer.hxx"
FGFLITEVoice::FGFLITEVoice(FGVoiceMgr * mgr, const SGPropertyNode_ptr node, const char * sampleGroupRefName) 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()); _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(); SGSharedPtr<SGSoundSample> sample = _sampleQueue.pop();
if (sample.valid()) { if (sample.valid()) {
_sgr->remove(_sampleName); _sgr->remove(_sampleName);
_sgr->add(sample, _sampleName); _sgr->add(sample, _sampleName);
_sgr->resume(); _sgr->resume();
_sgr->play(_sampleName, false); _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"); FGFLITEVoice(FGVoiceMgr *, const SGPropertyNode_ptr, const char * sampleGroupRefName = "flite-voice");
virtual ~FGFLITEVoice(); virtual ~FGFLITEVoice();
virtual void speak(const std::string & msg); virtual void speak(const std::string & msg);
virtual void update(); virtual void update(double dt);
private: private:
FGFLITEVoice(const FGFLITEVoice & other); FGFLITEVoice(const FGFLITEVoice & other);
@ -45,6 +45,7 @@ private:
VoiceSynthesizer * _synthesizer; VoiceSynthesizer * _synthesizer;
SGLockedQueue<SGSharedPtr<SGSoundSample> > _sampleQueue; SGLockedQueue<SGSharedPtr<SGSoundSample> > _sampleQueue;
std::string _sampleName; std::string _sampleName;
double _seconds_to_run;
}; };
#endif // _FLITEVOICE_HXX #endif // _FLITEVOICE_HXX

View file

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

View file

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