]> git.mxchange.org Git - flightgear.git/commitdiff
VoiceSynthesizer: add some test/debug properties
authorTorsten Dreyer <torsten@t3r.de>
Sun, 27 Apr 2014 20:53:59 +0000 (22:53 +0200)
committerTorsten Dreyer <torsten@t3r.de>
Sun, 27 Apr 2014 20:53:59 +0000 (22:53 +0200)
/sim/sound/voice-synthesizer/volume to set the volume of the generated wav (in dB)
/sim/sound/voice-synthesizer/keep-scratch-file do not remove the scratch file if true

src/Sound/VoiceSynthesizer.cxx
src/Sound/VoiceSynthesizer.hxx

index 7a8d7ed1406085523e2acc757166bdcd771195cc..b91c90214270b11f1393db4d9b275b8c20a3b4be 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "VoiceSynthesizer.hxx"
 #include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/sound/readwav.hxx>
 #include <simgear/misc/sg_path.hxx>
 
 class ScopedTempfile {
 public:
-  ScopedTempfile()
+  ScopedTempfile( bool keep = false ) : _keep(keep)
   {
     _name = ::tempnam(globals->get_fg_home().c_str(), "fgvox");
 
   }
   ~ScopedTempfile()
   {
-    if (_name) ::unlink(_name);
+    if (_name && !_keep) ::unlink(_name);
     ::free(_name);
   }
 
@@ -36,6 +37,7 @@ public:
   }
 private:
   char * _name;
+  bool _keep;
 };
 
 class FLITEVoiceSynthesizer::WorkerThread: public OpenThreads::Thread {
@@ -66,8 +68,10 @@ void FLITEVoiceSynthesizer::synthesize( SynthesizeRequest & request)
 }
 
 FLITEVoiceSynthesizer::FLITEVoiceSynthesizer(const std::string & voice)
-    : _engine(new Flite_HTS_Engine), _worker(new FLITEVoiceSynthesizer::WorkerThread(this))
+    : _engine(new Flite_HTS_Engine), _worker(new FLITEVoiceSynthesizer::WorkerThread(this)), _volume(6.0), _keepScratchFile(false)
 {
+  _volume = fgGetDouble("/sim/sound/voice-synthesizer/volume", _volume );
+  _keepScratchFile = fgGetBool("/sim/sound/voice-synthesizer/keep-scratch-file", _keepScratchFile);
   Flite_HTS_Engine_initialize(_engine);
   Flite_HTS_Engine_load(_engine, voice.c_str());
   _worker->start();
@@ -82,7 +86,9 @@ FLITEVoiceSynthesizer::~FLITEVoiceSynthesizer()
 
 SGSoundSample * FLITEVoiceSynthesizer::synthesize(const std::string & text)
 {
-  ScopedTempfile scratch;
+  ScopedTempfile scratch(_keepScratchFile);
+  HTS_Engine_set_volume( &_engine->engine, _volume );
+
   if ( FALSE == Flite_HTS_Engine_synthesize(_engine, text.c_str(), scratch.getName())) return NULL;
 
   SG_LOG(SG_SOUND, SG_ALERT, "created wav at " << scratch.getPath());
index 4e49a38bf1cbe8dbe511e37c7b43cf979239fe10..923714fb04086db62a892a5a55eae03b605672c8 100644 (file)
@@ -76,6 +76,9 @@ private:
 
   typedef SGBlockingQueue<SynthesizeRequest> SynthesizeRequestList;
   SynthesizeRequestList _requests;
+
+  double _volume;
+  bool   _keepScratchFile;
 };
 
 #endif /* VOICESYNTHESIZER_HXX_ */