]> git.mxchange.org Git - flightgear.git/blob - src/Sound/VoiceSynthesizer.hxx
923714fb04086db62a892a5a55eae03b605672c8
[flightgear.git] / src / Sound / VoiceSynthesizer.hxx
1 /*
2  * VoiceSynthesizer.hxx
3  *
4  *  Created on: Apr 24, 2014
5  *      Author: flightgear
6  */
7
8 #ifndef VOICESYNTHESIZER_HXX_
9 #define VOICESYNTHESIZER_HXX_
10
11 #include <simgear/sound/sample_openal.hxx>
12 #include <simgear/threads/SGQueue.hxx>
13
14 #include <string>
15 struct _Flite_HTS_Engine;
16
17 /**
18  * A Voice Synthesizer Interface
19  */
20 class VoiceSynthesizer {
21 public:
22   virtual ~VoiceSynthesizer() {};
23   virtual SGSoundSample * synthesize( const std::string & text ) = 0;
24 };
25
26 class SoundSampleReadyListener {
27 public:
28   virtual ~SoundSampleReadyListener() {}
29   virtual void SoundSampleReady( SGSharedPtr<SGSoundSample> ) = 0;
30 };
31
32 struct SynthesizeRequest {
33   SynthesizeRequest() {
34     speed = volume = pitch = 1.0;
35     listener = NULL;
36   }
37   SynthesizeRequest( const SynthesizeRequest & other ) {
38     text = other.text;
39     speed = other.speed;
40     volume = other.volume;
41     pitch = other.pitch;
42     listener = other.listener;
43   }
44
45   SynthesizeRequest & operator = ( const SynthesizeRequest & other ) {
46     text = other.text;
47     speed = other.speed;
48     volume = other.volume;
49     pitch = other.pitch;
50     listener = other.listener;
51     return *this;
52   }
53
54   std::string text;
55   double speed;
56   double volume;
57   double pitch;
58   SoundSampleReadyListener * listener;
59 };
60
61 /**
62  * A Voice Synthesizer using FLITE+HTS
63  */
64 class FLITEVoiceSynthesizer : public VoiceSynthesizer {
65 public:
66   FLITEVoiceSynthesizer( const std::string & voice );
67   ~FLITEVoiceSynthesizer();
68   virtual SGSoundSample * synthesize( const std::string & text );
69
70   virtual void synthesize( SynthesizeRequest & request );
71 private:
72   struct _Flite_HTS_Engine * _engine;
73
74   class WorkerThread;
75   WorkerThread * _worker;
76
77   typedef SGBlockingQueue<SynthesizeRequest> SynthesizeRequestList;
78   SynthesizeRequestList _requests;
79
80   double _volume;
81   bool   _keepScratchFile;
82 };
83
84 #endif /* VOICESYNTHESIZER_HXX_ */