FlightGear next
voice.hxx
Go to the documentation of this file.
1// speech synthesis interface subsystem
2//
3// Written by Melchior FRANZ, started February 2006.
4//
5// Copyright (C) 2006 Melchior FRANZ - mfranz@aon.at
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// $Id$
22
23#pragma once
24
25#include <vector>
26
27#include <simgear/compiler.h>
28#include <simgear/props/props.hxx>
29#include <simgear/io/sg_socket.hxx>
30#include <simgear/structure/subsystem_mgr.hxx>
31
32#include <Main/fg_props.hxx>
33
34#if defined(ENABLE_THREADS)
35# include <OpenThreads/Thread>
36# include <OpenThreads/Mutex>
37# include <OpenThreads/ScopedLock>
38# include <OpenThreads/Condition>
39# include <simgear/threads/SGQueue.hxx>
40#else
41# include <queue>
42#endif // ENABLE_THREADS
43
44
45class FGVoiceMgr : public SGSubsystem
46{
47public:
48 FGVoiceMgr();
50
51 // Subsystem API.
52 void init() override;
53 void shutdown() override;
54 void update(double dt) override;
55
56 // Subsystem identification.
57 static const char* staticSubsystemClassId() { return "voice"; }
58
59 class FGVoice;
60
61protected:
62 friend class FGFestivalVoice;
63
64#if defined(ENABLE_THREADS)
65 class FGVoiceThread;
66 FGVoiceThread *_thread;
67#endif
68
69 std::string _host;
70 std::string _port;
72 SGPropertyNode_ptr _pausedNode;
73 bool _paused;
74 std::vector<FGVoice *> _voices;
75};
76
77
78
79#if defined(ENABLE_THREADS)
80class FGVoiceMgr::FGVoiceThread : public OpenThreads::Thread
81{
82public:
83 FGVoiceThread(FGVoiceMgr *mgr) : _mgr(mgr) {}
84 void run();
85 void wake_up() { _jobs.signal(); }
86
87private:
88 void wait_for_jobs() { OpenThreads::ScopedLock<OpenThreads::Mutex> g(_mutex); _jobs.wait(&_mutex); }
89 OpenThreads::Condition _jobs;
90 OpenThreads::Mutex _mutex;
91
92protected:
93 FGVoiceMgr *_mgr;
94};
95#endif
96
97
98class FGVoiceMgr::FGVoice : public SGPropertyChangeListener
99{
100public:
101 FGVoice(FGVoiceMgr * mgr ) : _mgr(mgr) {}
102 virtual ~FGVoice() {}
103 virtual void speak( const std::string & msg ) = 0;
104 virtual void update(double dt) = 0;
105 void pushMessage( const std::string & m);
106 bool speak();
107
108protected:
109 void valueChanged(SGPropertyNode *node);
110
112
113#if defined(ENABLE_THREADS)
114 SGLockedQueue<std::string> _msg;
115#else
116 std::queue<std::string> _msg;
117#endif
118};
FGVoice(FGVoiceMgr *mgr)
Definition voice.hxx:101
std::queue< std::string > _msg
Definition voice.hxx:116
FGVoiceMgr * _mgr
Definition voice.hxx:111
virtual void update(double dt)=0
void pushMessage(const std::string &m)
Definition voice.cxx:182
virtual void speak(const std::string &msg)=0
void valueChanged(SGPropertyNode *node)
THREAD ///.
Definition voice.cxx:284
virtual ~FGVoice()
Definition voice.hxx:102
static const char * staticSubsystemClassId()
Definition voice.hxx:57
bool _enabled
Definition voice.hxx:71
friend class FGFestivalVoice
Definition voice.hxx:62
std::string _port
Definition voice.hxx:70
void update(double dt) override
Definition voice.cxx:110
~FGVoiceMgr()
Definition voice.cxx:58
std::string _host
Definition voice.hxx:69
void init() override
Definition voice.cxx:63
void shutdown() override
Definition voice.cxx:94
FGVoiceMgr()
MANAGER ///.
Definition voice.cxx:45
std::vector< FGVoice * > _voices
Definition voice.hxx:74
SGPropertyNode_ptr _pausedNode
Definition voice.hxx:72
bool _paused
Definition voice.hxx:73
const double g(9.80665)