1 // speech synthesis interface subsystem
3 // Written by Torsten Dreyer, started April 2014
5 // Copyright (C) 2014 Torsten Dreyer - torsten (at) t3r (dot) de
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "flitevoice.hxx"
27 #include <Main/fg_props.hxx>
28 #include <simgear/sound/sample_group.hxx>
29 #include <flite_hts_engine.h>
33 #include "VoiceSynthesizer.hxx"
35 FGFLITEVoice::FGFLITEVoice(FGVoiceMgr * mgr, const SGPropertyNode_ptr node, const char * sampleGroupRefName)
36 : FGVoice(mgr), _synthesizer( NULL)
39 _sampleName = node->getStringValue("desc", node->getPath().c_str());
41 string voice = globals->get_fg_root() + "/ATC/" +
42 node->getStringValue("htsvoice", "cmu_us_arctic_slt.htsvoice");
44 _synthesizer = new FLITEVoiceSynthesizer(voice.c_str());
46 SGSoundMgr *smgr = globals->get_soundmgr();
47 _sgr = smgr->find(sampleGroupRefName, true);
48 _sgr->tie_to_listener();
50 node->getNode("text", true)->addChangeListener(this);
52 SG_LOG(SG_SOUND, SG_INFO, "FLITEVoice initialized for sample-group '" << sampleGroupRefName
53 << "'. Samples will be named '" << _sampleName << "' "
54 << "voice is '" << voice << "'");
57 FGFLITEVoice::~FGFLITEVoice()
62 void FGFLITEVoice::speak(const string & msg)
64 // this is called from voice.cxx:FGVoiceMgr::FGVoiceThread::run
65 string s = simgear::strutils::strip(msg);
66 if (false == s.empty()) {
67 _sampleQueue.push(_synthesizer->synthesize(msg, 1.0, 0.5, 0.5));
71 void FGFLITEVoice::update()
73 SGSharedPtr<SGSoundSample> sample = _sampleQueue.pop();
75 _sgr->remove(_sampleName);
76 _sgr->add(sample, _sampleName);
78 _sgr->play(_sampleName, false);