]> git.mxchange.org Git - flightgear.git/blob - src/Sound/flitevoice.cxx
use flite+hts for metar
[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)
36     : FGVoice(mgr), _synthesizer( NULL )
37 {
38   string voice = globals->get_fg_root() + "/ATC/cmu_us_arctic_slt.htsvoice";
39   _synthesizer = new FLITEVoiceSynthesizer( voice.c_str() );
40
41   SGSoundMgr *smgr = globals->get_soundmgr();
42   _sgr = smgr->find("atc", true);
43   _sgr->tie_to_listener();
44
45   node->getNode("text", true)->addChangeListener(this);
46
47   SG_LOG(SG_ALL, SG_ALERT, "FLITEVoice initialized");
48 }
49
50 FGFLITEVoice::~FGFLITEVoice()
51 {
52   delete _synthesizer;
53   SG_LOG(SG_ALL, SG_ALERT, "FLITEVoice dtor()");
54 }
55
56 void FGFLITEVoice::speak(const string & msg)
57 {
58   SG_LOG(SG_ALL, SG_ALERT, "FLITEVoice speak(" << msg << ")");
59
60   _sgr->remove("flite");
61
62   string s = simgear::strutils::strip( msg );
63   if( false == s.empty() ) {
64     SGSoundSample * sample = _synthesizer->synthesize( msg );
65     _sgr->add(sample, "flite");
66     _sgr->set_volume(1.0);
67     _sgr->resume();
68     _sgr->play("flite", true);
69   }
70 }
71
72 void FGFLITEVoice::update()
73 {
74
75 }
76