2014-04-24 20:59:08 +02:00
|
|
|
// speech synthesis interface subsystem
|
|
|
|
//
|
|
|
|
// Written by Torsten Dreyer, started April 2014
|
|
|
|
//
|
|
|
|
// Copyright (C) 2014 Torsten Dreyer - torsten (at) t3r (dot) de
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "flitevoice.hxx"
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
#include <simgear/sound/sample_group.hxx>
|
|
|
|
#include <flite_hts_engine.h>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
#include "VoiceSynthesizer.hxx"
|
|
|
|
|
2014-05-07 22:12:23 +02:00
|
|
|
FGFLITEVoice::FGFLITEVoice(FGVoiceMgr * mgr, const SGPropertyNode_ptr node, const char * sampleGroupRefName)
|
2017-03-20 22:27:10 +00:00
|
|
|
: FGVoice(mgr), _synthesizer( NULL), _seconds_to_run(0.0)
|
2014-04-24 20:59:08 +02:00
|
|
|
{
|
2014-05-07 22:12:23 +02:00
|
|
|
|
|
|
|
_sampleName = node->getStringValue("desc", node->getPath().c_str());
|
|
|
|
|
2016-06-21 12:29:04 +01:00
|
|
|
SGPath voice = globals->get_fg_root() / "ATC" /
|
2014-05-07 22:12:23 +02:00
|
|
|
node->getStringValue("htsvoice", "cmu_us_arctic_slt.htsvoice");
|
|
|
|
|
2016-06-21 12:29:04 +01:00
|
|
|
_synthesizer = new FLITEVoiceSynthesizer(voice.local8BitStr());
|
2014-04-24 20:59:08 +02:00
|
|
|
|
2015-12-30 23:11:54 -06:00
|
|
|
SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>();
|
2014-05-07 22:12:23 +02:00
|
|
|
_sgr = smgr->find(sampleGroupRefName, true);
|
2014-04-24 20:59:08 +02:00
|
|
|
_sgr->tie_to_listener();
|
|
|
|
|
|
|
|
node->getNode("text", true)->addChangeListener(this);
|
|
|
|
|
2014-05-20 23:06:02 +02:00
|
|
|
SG_LOG(SG_SOUND, SG_INFO, "FLITEVoice initialized for sample-group '" << sampleGroupRefName
|
2014-05-07 22:12:23 +02:00
|
|
|
<< "'. Samples will be named '" << _sampleName << "' "
|
|
|
|
<< "voice is '" << voice << "'");
|
2014-04-24 20:59:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FGFLITEVoice::~FGFLITEVoice()
|
|
|
|
{
|
|
|
|
delete _synthesizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGFLITEVoice::speak(const string & msg)
|
|
|
|
{
|
2014-05-07 22:12:23 +02:00
|
|
|
// this is called from voice.cxx:FGVoiceMgr::FGVoiceThread::run
|
|
|
|
string s = simgear::strutils::strip(msg);
|
|
|
|
if (false == s.empty()) {
|
|
|
|
_sampleQueue.push(_synthesizer->synthesize(msg, 1.0, 0.5, 0.5));
|
2014-04-24 20:59:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 22:27:10 +00:00
|
|
|
void FGFLITEVoice::update(double dt)
|
2014-04-24 20:59:08 +02:00
|
|
|
{
|
2017-03-20 22:27:10 +00:00
|
|
|
_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());
|
|
|
|
}
|
2014-05-07 22:12:23 +02:00
|
|
|
}
|
2014-04-24 20:59:08 +02:00
|
|
|
}
|