2006-02-11 11:58:17 +00:00
|
|
|
// speech synthesis interface subsystem
|
|
|
|
//
|
|
|
|
// Written by Melchior FRANZ, started February 2006.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2006 Melchior FRANZ - mfranz@aon.at
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#ifndef _VOICE_HXX
|
|
|
|
#define _VOICE_HXX
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
#include <simgear/props/props.hxx>
|
|
|
|
#include <simgear/io/sg_socket.hxx>
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
|
|
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
|
|
|
|
#if defined(ENABLE_THREADS)
|
2008-06-12 08:24:39 +00:00
|
|
|
# include <OpenThreads/Thread>
|
|
|
|
# include <OpenThreads/Mutex>
|
|
|
|
# include <OpenThreads/ScopedLock>
|
|
|
|
# include <OpenThreads/Condition>
|
2006-02-11 11:58:17 +00:00
|
|
|
# include <simgear/threads/SGQueue.hxx>
|
|
|
|
#else
|
|
|
|
# include <queue>
|
|
|
|
#endif // ENABLE_THREADS
|
|
|
|
|
2008-07-27 16:25:13 +00:00
|
|
|
using std::vector;
|
2006-02-11 11:58:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FGVoiceMgr : public SGSubsystem {
|
|
|
|
public:
|
|
|
|
FGVoiceMgr();
|
|
|
|
~FGVoiceMgr();
|
|
|
|
void init(void);
|
2014-04-23 15:09:00 +00:00
|
|
|
void shutdown();
|
2006-02-11 11:58:17 +00:00
|
|
|
void update(double dt);
|
|
|
|
|
|
|
|
|
2014-04-23 15:09:00 +00:00
|
|
|
class FGVoice;
|
|
|
|
protected:
|
|
|
|
friend class FGFestivalVoice;
|
2006-02-11 11:58:17 +00:00
|
|
|
#if defined(ENABLE_THREADS)
|
|
|
|
class FGVoiceThread;
|
|
|
|
FGVoiceThread *_thread;
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 16:41:59 +00:00
|
|
|
std::string _host;
|
|
|
|
std::string _port;
|
2006-02-11 11:58:17 +00:00
|
|
|
bool _enabled;
|
|
|
|
SGPropertyNode_ptr _pausedNode;
|
|
|
|
bool _paused;
|
2011-10-17 16:41:59 +00:00
|
|
|
std::vector<FGVoice *> _voices;
|
2006-02-11 11:58:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_THREADS)
|
2008-06-12 08:24:39 +00:00
|
|
|
class FGVoiceMgr::FGVoiceThread : public OpenThreads::Thread {
|
2006-02-11 11:58:17 +00:00
|
|
|
public:
|
|
|
|
FGVoiceThread(FGVoiceMgr *mgr) : _mgr(mgr) {}
|
|
|
|
void run();
|
|
|
|
void wake_up() { _jobs.signal(); }
|
|
|
|
|
|
|
|
private:
|
2008-06-12 08:24:39 +00:00
|
|
|
void wait_for_jobs() { OpenThreads::ScopedLock<OpenThreads::Mutex> g(_mutex); _jobs.wait(&_mutex); }
|
|
|
|
OpenThreads::Condition _jobs;
|
|
|
|
OpenThreads::Mutex _mutex;
|
2014-04-23 15:09:00 +00:00
|
|
|
protected:
|
2006-02-11 11:58:17 +00:00
|
|
|
FGVoiceMgr *_mgr;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-04-23 15:09:00 +00:00
|
|
|
class FGVoiceMgr::FGVoice : public SGPropertyChangeListener {
|
2006-02-11 11:58:17 +00:00
|
|
|
public:
|
2014-04-23 15:09:00 +00:00
|
|
|
FGVoice(FGVoiceMgr * mgr ) : _mgr(mgr) {}
|
|
|
|
virtual ~FGVoice() {}
|
|
|
|
virtual void speak( const std::string & msg ) = 0;
|
2017-03-20 22:27:10 +00:00
|
|
|
virtual void update(double dt) = 0;
|
2014-04-23 15:09:00 +00:00
|
|
|
void pushMessage( const std::string & m);
|
|
|
|
bool speak();
|
2006-02-11 11:58:17 +00:00
|
|
|
|
2014-04-23 15:09:00 +00:00
|
|
|
protected:
|
|
|
|
void valueChanged(SGPropertyNode *node);
|
2006-02-11 11:58:17 +00:00
|
|
|
|
2014-04-23 15:09:00 +00:00
|
|
|
FGVoiceMgr *_mgr;
|
|
|
|
|
|
|
|
#if defined(ENABLE_THREADS)
|
|
|
|
SGLockedQueue<std::string> _msg;
|
2006-02-11 11:58:17 +00:00
|
|
|
#else
|
2011-10-17 16:41:59 +00:00
|
|
|
std::queue<std::string> _msg;
|
2006-02-11 11:58:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _VOICE_HXX
|