SpeechNode.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_SpeechNode_h_
00003 #define INCLUDED_SpeechNode_h_
00004
00005 #include <sstream>
00006
00007 #include "Behaviors/StateNode.h"
00008 #include "Sound/SoundManager.h"
00009
00010
00011
00012
00013
00014
00015
00016 class SpeechNode : public StateNode {
00017 public:
00018
00019 SpeechNode(const std::string& nodename, const std::string& text="")
00020 : StateNode(nodename), storedText(text), textstream(),
00021 showText(true), curplay_id(SoundManager::invalid_Play_ID), autostop(false),
00022 savedText(), pos() {}
00023
00024
00025 virtual void preStart() {
00026 StateNode::preStart();
00027
00028
00029
00030 textstream.str(storedText);
00031 if ( event!=NULL ) {
00032 const DataEvent<std::string> *datev = dynamic_cast<const DataEvent<std::string>*>(event);
00033 if ( datev != NULL )
00034 textstream << (!storedText.empty() ? " " : "") << datev->getData();
00035 }
00036 savedText = textstream.str();
00037 textstream << (textstream.str().empty() ? "" : " ");
00038 pos = textstream.tellp();
00039 }
00040
00041 virtual void postStart() {
00042 StateNode::postStart();
00043 if ( textstream.tellp() == pos )
00044 textstream.str(savedText);
00045 curplay_id = sndman->speak(textstream.str(), showText);
00046 if ( curplay_id == SoundManager::invalid_Play_ID )
00047 postStateCompletion();
00048 else
00049 erouter->addListener(this, EventBase::audioEGID, curplay_id);
00050 }
00051
00052
00053 virtual void stop() {
00054 if(autostop)
00055 stopPlay();
00056 StateNode::stop();
00057 }
00058
00059
00060 virtual void doEvent() {
00061 curplay_id = SoundManager::invalid_Play_ID;
00062 postStateCompletion();
00063 }
00064
00065
00066 void stopPlay() {
00067 sndman->stopPlay(curplay_id);
00068 curplay_id = SoundManager::invalid_Play_ID;
00069 }
00070
00071
00072 const std::string getText() const { return storedText; }
00073
00074
00075 void setText(const std::string &text) { storedText = text; }
00076
00077
00078 void setShowText(bool s) { showText = s; }
00079
00080
00081 bool getAutoStop() { return autostop; }
00082
00083
00084 void setAutoStop(bool astop) { autostop=astop; }
00085
00086 protected:
00087 std::string storedText;
00088 std::ostringstream textstream;
00089 bool showText;
00090 SoundManager::Play_ID curplay_id;
00091 bool autostop;
00092
00093 private:
00094 std::string savedText;
00095 std::streampos pos;
00096 };
00097
00098
00099
00100
00101
00102
00103 #endif