//
// $Id$
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <Main/globals.hxx>
#include <sstream>
#include <simgear/compiler.h>
#define VOICE "/sim/sound/voices"
+using std::string;
/// MANAGER ///
_host(fgGetString(VOICE "/host", "localhost")),
_port(fgGetString(VOICE "/port", "1314")),
_enabled(fgGetBool(VOICE "/enabled", false)),
- _pausedNode(fgGetNode("/sim/sound/pause", true))
+ _pausedNode(fgGetNode("/sim/sound/working", true))
{
#if defined(ENABLE_THREADS)
if (!_enabled)
return;
_thread->cancel();
_thread->join();
+ delete _thread;
#endif
}
try {
for (unsigned int i = 0; i < voices.size(); i++)
_voices.push_back(new FGVoice(this, voices[i]));
- } catch (const string& s) {
- SG_LOG(SG_IO, SG_ALERT, "VOICE: " << s);
+ } catch (const std::string& s) {
+ SG_LOG(SG_SOUND, SG_ALERT, "VOICE: " << s);
}
#if defined(ENABLE_THREADS)
- _thread->start(1);
+ _thread->setProcessorAffinity(1);
+ _thread->start();
#endif
}
if (!_enabled)
return;
- _paused = _pausedNode->getBoolValue();
+ _paused = !_pausedNode->getBoolValue();
for (unsigned int i = 0; i < _voices.size(); i++) {
_voices[i]->update();
#if !defined(ENABLE_THREADS)
_festival(node->getBoolValue("festival", true)),
_mgr(mgr)
{
- SG_LOG(SG_IO, SG_INFO, "VOICE: adding `" << node->getStringValue("desc", "<unnamed>")
+ SG_LOG(SG_SOUND, SG_INFO, "VOICE: adding `" << node->getStringValue("desc", "<unnamed>")
<< "' voice");
const string &host = _mgr->_host;
const string &port = _mgr->_port;
+ "'. Either it's not\n Festival listening,"
" or Festival couldn't open a sound device.";
- SG_LOG(SG_IO, SG_INFO, "VOICE: connection to Festival server on `"
+ SG_LOG(SG_SOUND, SG_INFO, "VOICE: connection to Festival server on `"
<< host << ':' << port << "' established");
setVolume(_volume = _volumeNode->getDoubleValue());
bool FGVoiceMgr::FGVoice::speak(void)
{
- if (_msg.empty()) {
-// cerr << "<nothing to say>" << endl;
+ if (_msg.empty())
return false;
- }
const string s = _msg.front();
_msg.pop();
-// cerr << "POP " << s;
_sock->writestring(s.c_str());
return !_msg.empty();
}
return;
const string s = node->getStringValue();
-// cerr << "PUSH " << s << endl;
+ //cerr << "\033[31;1mBEFORE [" << s << "]\033[m" << endl;
string m;
for (unsigned int i = 0; i < s.size(); i++) {
char c = s[i];
- if (!isprint(c))
+ if (c == '\n' || c == '\r' || c == '\t')
+ m += ' ';
+ else if (!isprint(c))
continue;
- else if (c == '"' || c == '\\')
- m += '\\' + c;
+ else if (c == '\\' || c == '"')
+ m += '\\', m += c;
else if (c == '|' || c == '_')
m += ' '; // don't say "vertical bar" or "underscore"
else if (c == '&')
m += " and ";
+ else if (c == '{') {
+ while (i < s.size())
+ if (s[++i] == '|')
+ break;
+ } else if (c == '}')
+ ;
else
m += c;
}
+ //cerr << "\033[31;1mAFTER [" << m << "]\033[m" << endl;
if (_voice->_festival)
m = string("(SayText \"") + m + "\")";