diff --git a/src/Sound/flitevoice.cxx b/src/Sound/flitevoice.cxx index c38e96154..9cf0e4687 100644 --- a/src/Sound/flitevoice.cxx +++ b/src/Sound/flitevoice.cxx @@ -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) { - SGSharedPtr sample = _sampleQueue.pop(); - if (sample.valid()) { - _sgr->remove(_sampleName); - _sgr->add(sample, _sampleName); - _sgr->resume(); - _sgr->play(_sampleName, false); + _seconds_to_run -= dt; + + if (_seconds_to_run < 0.0) { + SGSharedPtr 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()); + } } } - diff --git a/src/Sound/flitevoice.hxx b/src/Sound/flitevoice.hxx index 18ed0de27..7891458fa 100644 --- a/src/Sound/flitevoice.hxx +++ b/src/Sound/flitevoice.hxx @@ -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 > _sampleQueue; std::string _sampleName; + double _seconds_to_run; }; #endif // _FLITEVOICE_HXX diff --git a/src/Sound/voice.cxx b/src/Sound/voice.cxx index 8817efe81..a3362c9ba 100644 --- a/src/Sound/voice.cxx +++ b/src/Sound/voice.cxx @@ -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); } - - diff --git a/src/Sound/voice.hxx b/src/Sound/voice.hxx index eabd00a40..5625a9784 100644 --- a/src/Sound/voice.hxx +++ b/src/Sound/voice.hxx @@ -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();