]> git.mxchange.org Git - flightgear.git/blob - src/Sound/flitevoice.cxx
Interim windows build fix
[flightgear.git] / src / Sound / flitevoice.cxx
1 // speech synthesis interface subsystem
2 //
3 // Written by Torsten Dreyer, started April 2014
4 //
5 // Copyright (C) 2014  Torsten Dreyer - torsten (at) t3r (dot) de
6 //
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.
11 //
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.
16 //
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.
20 //
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #endif
25
26 #include "flitevoice.hxx"
27 #include <Main/fg_props.hxx>
28 #include <simgear/sound/sample_group.hxx>
29 #include <flite_hts_engine.h>
30
31 using std::string;
32
33 #include "VoiceSynthesizer.hxx"
34
35 FGFLITEVoice::FGFLITEVoice(FGVoiceMgr * mgr, const SGPropertyNode_ptr node, const char * sampleGroupRefName)
36     : FGVoice(mgr), _synthesizer( NULL)
37 {
38
39   _sampleName = node->getStringValue("desc", node->getPath().c_str());
40
41   string voice = globals->get_fg_root() + "/ATC/" +
42       node->getStringValue("htsvoice", "cmu_us_arctic_slt.htsvoice");
43
44   _synthesizer = new FLITEVoiceSynthesizer(voice.c_str());
45
46   SGSoundMgr *smgr = globals->get_soundmgr();
47   _sgr = smgr->find(sampleGroupRefName, true);
48   _sgr->tie_to_listener();
49
50   node->getNode("text", true)->addChangeListener(this);
51
52   SG_LOG(SG_SOUND, SG_INFO, "FLITEVoice initialized for sample-group '" << sampleGroupRefName
53       << "'. Samples will be named '" << _sampleName << "' "
54       << "voice is '" << voice << "'");
55 }
56
57 FGFLITEVoice::~FGFLITEVoice()
58 {
59   delete _synthesizer;
60 }
61
62 void FGFLITEVoice::speak(const string & msg)
63 {
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));
68   }
69 }
70
71 void FGFLITEVoice::update()
72 {
73   SGSharedPtr<SGSoundSample> sample = _sampleQueue.pop();
74   if (sample.valid()) {
75     _sgr->remove(_sampleName);
76     _sgr->add(sample, _sampleName);
77     _sgr->resume();
78     _sgr->play(_sampleName, false);
79   }
80 }
81