Revision ff49ed31

View differences:

server/CMakeLists.txt
132 132
# declare library
133 133
add_executable(${PROJECT_NAME}
134 134
    src/main.cpp
135
    src/MiddlewareRSB.cpp
136 135
    src/MiddlewareROS.cpp
137 136
    src/Arbiter.cpp
138 137
    src/Utterance.cpp
139 138
    src/Animation.cpp
140 139
    src/AudioPlayer.cpp
141
    src/AudioPlayerRSB.cpp
142 140
    src/AudioPlayerLibAO.cpp
143 141
    src/MouthConfig.cpp
144 142
    src/EmotionState.cpp
server/include/AudioPlayerRSB.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "AudioPlayer.h"
31

  
32
#ifdef RSB_SUPPORT
33

  
34
#define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1
35
#include <rsb/Informer.h>
36
#include <rst/audition/SoundChunk.pb.h>
37

  
38
class AudioPlayerRSB : public AudioPlayer {
39
public:
40
	AudioPlayerRSB(std::string driver);
41
	~AudioPlayerRSB();
42

  
43
	void playback_thread();
44
	void play(std::shared_ptr<AudioData> audio);
45
	bool is_playing();
46

  
47
private:
48
	boost::thread* playback_thread_ptr;
49
	void publish_audio_data();
50
	rsb::Informer<rst::audition::SoundChunk>::DataPtr audio_data_ptr;
51
	rsb::Informer<rst::audition::SoundChunk>::Ptr informer;
52
};
53

  
54
#endif
server/include/MiddlewareROS.h
58 58
#ifndef ROS_SUPPORT
59 59
public:
60 60
	MiddlewareROS(Arbiter* a, std::string _base_scope) : Middleware(a, _base_scope) {
61
		printf("> ERROR: hlrc was compiled without ROS middleware support. Please use MiddlewareRSB() instead!\n\n");
61
		printf("> ERROR: hlrc was compiled without ROS middleware support.");
62 62
		exit(EXIT_FAILURE);
63 63
	}
64 64

  
server/include/MiddlewareRSB.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "Middleware.h"
31
#ifdef RSB_SUPPORT
32
#define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1
33
#include <rsb/Listener.h>
34
#include <rsb/patterns/LocalServer.h>
35
#include <rsb/patterns/RemoteServer.h>
36
#endif
37

  
38
class MiddlewareRSB : public Middleware {
39
#ifndef RSB_SUPPORT
40
public:
41
	MiddlewareRSB(Arbiter* a, std::string _base_scope) : Middleware(a, _base_scope) {
42
		printf("> ERROR: hlrc was compiled without RSB middleware support. Please use MiddlewareROS() instead!\n\n");
43
		exit(EXIT_FAILURE);
44
	}
45

  
46
	~MiddlewareRSB() {
47
	}
48
	void init(){};
49
	void tick(){};
50
	std::shared_ptr<Utterance> tts_call(std::string text) {
51
		return std::shared_ptr<Utterance>(new Utterance());
52
	}
53

  
54
#else
55
public:
56
	MiddlewareRSB(Arbiter* a, std::string _base_scope);
57
	~MiddlewareRSB();
58
	void init();
59
	void tick();
60
	std::shared_ptr<Utterance> tts_call(std::string text);
61

  
62
private:
63
	void init_callbacks();
64
	void init_callback(std::string name, rsb::patterns::LocalServer::CallbackPtr callback_ptr);
65

  
66
	rsb::patterns::LocalServerPtr server;
67
	rsb::patterns::LocalServerPtr server_parallel;
68
	rsb::patterns::RemoteServerPtr tts_server;
69
	rsb::ListenerPtr speak_listener;
70
#endif
71
};
server/include/ROS/MouthCallbackWrapperROS.h
50 50
		humotion::MouthState mouth_state;
51 51

  
52 52
		// fill in mouth
53
		//#include "RSB/SpeechCallbackWrapper.h".opening_left   = request->opening_left;
54 53
		mouth_state.opening_center = request->opening_center;
55 54
		mouth_state.opening_right = request->opening_right;
56 55

  
server/include/ROS/UtteranceCallbackWrapperROS.h
114 114
			default:
115 115
				printf("> invalid sample type %d in SoundChunk! ignoring request!\n", sound_chunk.sample_type);
116 116
				return false;
117
				// throw runtime_error("UtteranceRSB::convert_audio_data() unsupported sample type in soundchunk");
118
		}
117
            // throw runtime_error("UtteranceROS::convert_audio_data() unsupported sample type in soundchunk");
118
      }
119 119

  
120 120
		// bitrate
121 121
		audio_data->sample_rate = sound_chunk.rate;
......
129 129
		}
130 130
		else {
131 131
			printf("> invalid SoundChunk byte_format");
132
			throw std::runtime_error("UtteranceRSB::convert_audio_data() unsupported byte_format in soundchunk");
132
			throw std::runtime_error("UtteranceROS::convert_audio_data() unsupported byte_format in soundchunk");
133 133
		}
134 134

  
135 135
		// number of channels
server/include/RSB/AnimationCallbackWrapper.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "CallbackWrapper.h"
31
#include "Animation.h"
32

  
33
// callback handler incoming animation requests:
34
class AnimationCallbackWrapper : public CallbackWrapper<rst::animation::HeadAnimation> {
35
public:
36
	AnimationCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
37
	}
38

  
39
	void call(const std::string& method_name, std::shared_ptr<rst::animation::HeadAnimation> input) {
40
		printf("> incomint animation (method = %s)\n", method_name.c_str());
41

  
42
		// fetch animation passed by rsb:
43
		rst::animation::HeadAnimation* rst_ani = input.get();
44
		std::shared_ptr<Animation> ani(new Animation());
45

  
46
		switch ((int)rst_ani->animation()) {
47
			case (rst_ani->IDLE):
48
				ani->target = Animation::IDLE;
49
				break;
50
			case (rst_ani->HEAD_NOD):
51
				ani->target = Animation::HEAD_NOD;
52
				break;
53
			case (rst_ani->HEAD_SHAKE):
54
				ani->target = Animation::HEAD_SHAKE;
55
				break;
56
			case (rst_ani->EYEBLINK_LEFT):
57
				ani->target = Animation::EYEBLINK_L;
58
				break;
59
			case (rst_ani->EYEBLINK_RIGHT):
60
				ani->target = Animation::EYEBLINK_R;
61
				break;
62
			case (rst_ani->EYEBLINK_BOTH):
63
				ani->target = Animation::EYEBLINK_BOTH;
64
				break;
65
			case (rst_ani->EYEBROWS_RAISE):
66
				ani->target = Animation::EYEBROWS_RAISE;
67
				break;
68
			case (rst_ani->EYEBROWS_LOWER):
69
				ani->target = Animation::EYEBROWS_LOWER;
70
				break;
71
			case (rst_ani->ENGAGEMENT_LEFT):
72
				ani->target = Animation::ENGAGEMENT_LEFT;
73
				break;
74
			case (rst_ani->ENGAGEMENT_RIGHT):
75
				ani->target = Animation::ENGAGEMENT_RIGHT;
76
				break;
77
			default:
78
				ani->target = Animation::IDLE;
79
				printf("> unhandled animatin target %d\n", (int)rst_ani->animation());
80
				throw std::runtime_error("AnimationCallback: invalid animation id");
81
				return;
82
		}
83
		ani->repetitions = rst_ani->repetitions();
84
		ani->duration_each = rst_ani->duration_each();
85
		ani->scale = rst_ani->emphasis_scale();
86

  
87
		printf("> new Animation: %s\n", ani->as_string().c_str());
88

  
89
		// send to application
90
		mw->animation_callback(ani);
91
	}
92
};
server/include/RSB/CallbackWrapper.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "Middleware.h"
31
//#include <rst/robot/MouthTarget.pb.h>
32
#include <rst/animation/EmotionExpression.pb.h>
33
#include <rst/animation/BinocularHeadGaze.pb.h>
34
#include <rst/animation/HeadAnimation.pb.h>
35
#include <rst/audition/Utterance.pb.h>
36
#include <rst/audition/SoundChunk.pb.h>
37
#include <rsb/Factory.h>
38

  
39
template <typename T>
40
class CallbackWrapper : public rsb::patterns::LocalServer::Callback<T, void> {
41
public:
42
	CallbackWrapper(Middleware* _mw) {
43
		mw = _mw;
44
	}
45

  
46
	~CallbackWrapper() {
47
	}
48

  
49
	virtual void call(const std::string&, std::shared_ptr<T> param) = 0;
50

  
51
protected:
52
	Middleware* mw;
53
};
server/include/RSB/EmotionCallbackWrapper.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "CallbackWrapper.h"
31

  
32
// callback handler incoming emotion requests:
33
class EmotionCallbackWrapper : public CallbackWrapper<rst::animation::EmotionExpression> {
34
public:
35
	EmotionCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
36
	}
37

  
38
	void call(const std::string& method_name, std::shared_ptr<rst::animation::EmotionExpression> input) {
39
		printf("> incoming emotion (%s = %d)\n", method_name.c_str(), (int)input->emotion());
40

  
41
		EmotionState emotion_state;
42
		rst::animation::EmotionExpression* emotion = input.get();
43

  
44
		// extract data & copy it to our datatype (might be good when we allow multiple middlewares in the feature)
45
		switch ((int)emotion->emotion()) {
46
			case (rst::animation::EmotionExpression_Emotion_NEUTRAL):
47
				emotion_state.value = EmotionConfig::NEUTRAL;
48
				break;
49
			case (rst::animation::EmotionExpression_Emotion_HAPPY):
50
				emotion_state.value = EmotionConfig::HAPPY;
51
				break;
52
			case (rst::animation::EmotionExpression_Emotion_SAD):
53
				emotion_state.value = EmotionConfig::SAD;
54
				break;
55
			case (rst::animation::EmotionExpression_Emotion_ANGRY):
56
				emotion_state.value = EmotionConfig::ANGRY;
57
				break;
58
			case (rst::animation::EmotionExpression_Emotion_SURPRISED):
59
				emotion_state.value = EmotionConfig::SURPRISED;
60
				break;
61
			case (rst::animation::EmotionExpression_Emotion_FEAR):
62
				emotion_state.value = EmotionConfig::FEAR;
63
				break;
64
			default:
65
				printf("> invalid EmotionExpression emotion value. exiting\n");
66
				exit(EXIT_FAILURE);
67
		}
68

  
69
		emotion_state.duration = emotion->duration();
70

  
71
		// send to application
72
		if (method_name == "defaultEmotion") {
73
			// set default emotion:
74
			mw->default_emotion_callback(emotion_state);
75
		}
76
		else if (method_name == "currentEmotion") {
77
			// set current emotion:
78
			mw->current_emotion_callback(emotion_state);
79
		}
80
		else {
81
			printf("> invalid method called '%s'\n", method_name.c_str());
82
			exit(EXIT_FAILURE);
83
		}
84
	}
85
};
server/include/RSB/GazeCallbackWrapper.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "CallbackWrapper.h"
31

  
32
// callback handler incoming gaze requests:
33
class GazeCallbackWrapper : public CallbackWrapper<rst::animation::BinocularHeadGaze> {
34
public:
35
	GazeCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
36
	}
37
	void call(const std::string& method_name, std::shared_ptr<rst::animation::BinocularHeadGaze> input) {
38
		rst::animation::BinocularHeadGaze* gaze = input.get();
39
		// printf("> incoming gaze (p=%3.1f t=%3.1f r=%3.1f / v=%3.1f)\n", gaze->pan(), gaze->tilt(), gaze->roll(), gaze->vergence());
40

  
41
		humotion::GazeState gaze_state;
42

  
43
		// fill in gaze
44
		gaze_state.pan = gaze->target().azimuth();
45
		gaze_state.tilt = gaze->target().elevation();
46
		gaze_state.roll = 0.0;
47

  
48
		// RSB supports only absolute targets for now...
49
		gaze_state.timestamp = 123.45; // FIXME!!
50
		gaze_state.gaze_type = humotion::GazeState::GAZETYPE_ABSOLUTE;
51

  
52
		// vergence
53
		gaze_state.vergence = (gaze->has_eye_vergence()) ? gaze->eye_vergence() : 0.0;
54

  
55
		// offsets
56
		gaze_state.pan_offset = (gaze->has_offset()) ? gaze->offset().azimuth() : 0.0;
57
		gaze_state.tilt_offset = (gaze->has_offset()) ? gaze->offset().elevation() : 0.0;
58

  
59
		// send to application:
60
		mw->gaze_callback(gaze_state);
61
	}
62
};
server/include/RSB/MouthCallbackWrapper.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "CallbackWrapper.h"
31
#if 0
32
DISABLED MOUTH TARGET IN RSB FOR NOW
33
//callback handler incoming gaze requests:
34
class MouthCallbackWrapper : public CallbackWrapper<rst::robot::MouthTarget>{
35
    public:
36
        MouthCallbackWrapper(Middleware *mw) : CallbackWrapper(mw){}
37
        void call(const std::string& method_name, std::shared_ptr<rst::robot::MouthTarget> input){
38
            rst::robot::MouthTarget *mouth = input.get();
39

  
40
            humotion::MouthState mouth_state;
41

  
42
            //fill in mouth
43
            mouth_state.opening_left   = mouth->opening_left();
44
            mouth_state.opening_center = mouth->opening_center();
45
            mouth_state.opening_right  = mouth->opening_right();
46

  
47
            mouth_state.position_left   = mouth->position_left();
48
            mouth_state.position_center = mouth->position_center();
49
            mouth_state.position_right  = mouth->position_right();
50

  
51
            //send to application:
52
            mw->mouth_callback(mouth_state);
53
        }
54
};
55
#endif
server/include/RSB/SpeechCallbackWrapper.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "CallbackWrapper.h"
31

  
32
// callback handler incoming speech requests:
33
class SpeechCallbackWrapper : public CallbackWrapper<std::string> {
34
public:
35
	SpeechCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
36
	}
37

  
38
	void call(const std::string&, std::shared_ptr<std::string> _text) {
39
		// send to application
40
		std::string text = *_text.get();
41
		//<voice effect=\"Rate(durScale:1.5) + TractScaler(durScale:1.1)\">" +
42

  
43
		text = "<maryxml version=\"0.4\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
44
		       "xmlns=\"http://mary.dfki.de/2002/MaryXML\" xml:lang=\"en_US\">" +
45
		       text + "</maryxml>";
46
		mw->speak_callback(text);
47
	}
48
};
server/include/RSB/UtteranceCallbackWrapper.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "CallbackWrapper.h"
31
#include "UtteranceRSB.h"
32

  
33
// callback handler incoming Utterance requests:
34
class UtteranceCallbackWrapper : public CallbackWrapper<rst::audition::Utterance> {
35
public:
36
	UtteranceCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
37
	}
38
	void call(const std::string&, std::shared_ptr<rst::audition::Utterance> param) {
39
		// convert rsb utterance to out own:
40
		rst::audition::Utterance* rst_utterance = param.get();
41
		printf("> incoming utterance '%s' (%d phone symbols)\n", param->textual_representation().c_str(),
42
		       (int)rst_utterance->phonemes().element().size());
43

  
44
		std::shared_ptr<Utterance> utterance(new UtteranceRSB(*rst_utterance));
45

  
46
		// send to application;
47
		mw->utterance_callback(utterance);
48
	}
49

  
50
private:
51
};
server/include/RSB/UtteranceRSB.h
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#pragma once
30
#include "AudioData.h"
31
#include <rst/audition/SoundChunk.pb.h>
32
#include <rst/audition/Utterance.pb.h>
33
using namespace std;
34

  
35
// converter from rsb utterance
36
class UtteranceRSB : public Utterance {
37
public:
38
	UtteranceRSB(rst::audition::Utterance rst_utterance) {
39
		// set text:
40
		set_text(rst_utterance.textual_representation());
41

  
42
		// convert soundchunk to audio data:
43
		extract_audio_data(rst_utterance.audio());
44

  
45
		// convert phonemes:
46
		extract_phonemes(rst_utterance);
47
	}
48

  
49
	~UtteranceRSB(){};
50

  
51
	void extract_audio_data(rst::audition::SoundChunk sound_chunk) {
52
		// cout << sound_chunk.DebugString();
53

  
54
		// extract data:
55
		unsigned int audio_len = sound_chunk.data().length();
56
		char* audio_data_char = (char*)sound_chunk.data().c_str();
57

  
58
		// audio.samples = vector<char>(audio_data_char, audio_data_char+audio_len);
59
		audio_data->samples.resize(audio_len);
60
		audio_data->samples.assign(audio_data_char, audio_data_char + audio_len);
61

  
62
		printf("audio samplesize is %d bytes\n", (unsigned int)audio_data->samples.size());
63

  
64
		// extract format:
65
		audio_data->sample_signed = true;
66
		switch (sound_chunk.sample_type()) {
67
			case (rst::audition::SoundChunk::SAMPLE_U8):
68
				audio_data->sample_signed = false; // and fall through:
69
			case (rst::audition::SoundChunk::SAMPLE_S8):
70
				audio_data->sample_bit = 8;
71
				break;
72

  
73
			case (rst::audition::SoundChunk::SAMPLE_U16):
74
				audio_data->sample_signed = false; // and fall through:
75
			case (rst::audition::SoundChunk::SAMPLE_S16):
76
				audio_data->sample_bit = 16;
77
				break;
78

  
79
			case (rst::audition::SoundChunk::SAMPLE_U24):
80
				audio_data->sample_signed = false; // and fall through:
81
			case (rst::audition::SoundChunk::SAMPLE_S24):
82
				audio_data->sample_bit = 24;
83
				break;
84

  
85
			default:
86
				printf("> invalid sample type %d in RST SoundChunk! ignoring request!\n", sound_chunk.sample_type());
87
				throw runtime_error("UtteranceRSB::convert_audio_data() unsupported sample type in rst::audition::SoundChunk");
88
		}
89

  
90
		// bitrate
91
		audio_data->sample_rate = sound_chunk.rate();
92

  
93
		// endianness
94
		if (sound_chunk.endianness() == rst::audition::SoundChunk::ENDIAN_LITTLE) {
95
			audio_data->sample_big_endian = false;
96
		}
97
		else if (sound_chunk.endianness() == rst::audition::SoundChunk::ENDIAN_BIG) {
98
			audio_data->sample_big_endian = true;
99
		}
100
		else {
101
			printf("> invalid SoundChunk byte_format");
102
			throw runtime_error("UtteranceRSB::convert_audio_data() unsupported byte_format in rst::audition::SoundChunk");
103
		}
104

  
105
		// number of channels
106
		audio_data->sample_channels = sound_chunk.channels();
107

  
108
		printf("> new AudioData: %s\n", audio_data->to_string().c_str());
109
	}
110

  
111
	void extract_phonemes(rst::audition::Utterance rst_utterance) {
112
		// extract phoneme vector
113
		phonemes_vector.clear();
114
		for (int i = 0; i < rst_utterance.phonemes().element().size(); i++) {
115
			rst::audition::Phoneme rst_phoneme = rst_utterance.phonemes().element().Get(i);
116
			Utterance::symbol_duration_pair_t phoneme = make_pair(rst_phoneme.symbol(), rst_phoneme.duration());
117
			phonemes_vector.push_back(phoneme);
118
		}
119
	}
120
};
server/src/Arbiter.cpp
43 43
		// allow none for no sound output
44 44
		audio_player = NULL;
45 45
	}
46
	else if (iequals(audio_output.substr(0, 3), "rsb")) {
47
#ifdef RSB_SUPPORT
48
		audio_player = new AudioPlayerRSB(audio_output);
49
#else
50
		printf("> ERROR: hlc is compiled without RSB support, RSB audio transport not available, defaulting to libao (default "
51
		       "output!)\n");
52
		audio_player = new AudioPlayerLibAO("");
53
#endif
54
	}
46
   else if (iequals(audio_output.substr(0, 3), "rsb")) {
47
      printf("> ERROR: hlc is compiled without RSB support, RSB audio transport not available, defaulting to libao (default "
48
             "output!)\n");
49
      audio_player = new AudioPlayerLibAO("");
50
   }
55 51
	else {
56 52
		audio_player = new AudioPlayerLibAO(audio_output);
57 53
	}
server/src/AudioPlayerRSB.cpp
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#include "AudioPlayerRSB.h"
30

  
31
#ifdef RSB_SUPPORT
32
#include <rsb/converter/Repository.h>
33
#include <rsb/converter/ProtocolBufferConverter.h>
34
#include <rsb/Factory.h>
35
#include <boost/make_shared.hpp>
36
using namespace std;
37
using namespace rsb;
38
using namespace boost;
39

  
40
// new audio player with gievn device type (default is pulse)
41
AudioPlayerRSB::AudioPlayerRSB(string driver) : AudioPlayer(driver) {
42
	assert(driver.length() > 3);
43

  
44
	string scope = driver.substr(3);
45

  
46
	printf("> using rsb for playback, scope = '%s'\n", scope.c_str());
47

  
48
	printf("> registering converters\n");
49
	rsb::converter::Converter<string>::Ptr soundChunkConverter(
50
	   new rsb::converter::ProtocolBufferConverter<rst::audition::SoundChunk>());
51
	rsb::converter::converterRepository<string>()->registerConverter(soundChunkConverter);
52

  
53
	// first get a factory instance that is used to create RSB domain objects
54
	Factory& factory = getFactory();
55

  
56
	// create informer
57
	informer = factory.createInformer<rst::audition::SoundChunk>(scope);
58

  
59
	// start audio playback thread:
60
	playback_thread_ptr = new boost::thread(boost::bind(&AudioPlayerRSB::playback_thread, this));
61
}
62

  
63
// this will return once we start playing
64
void AudioPlayerRSB::play(std::shared_ptr<AudioData> _audio_data) {
65
	audio_data = _audio_data;
66

  
67
	printf("> AudioPlayerRSB: play() %d samples requested\n", (int)audio_data->samples.size());
68

  
69
	// check if we can play this file:
70
	while (playback_state != IDLE) {
71
		printf("> player not ready yet, waiting for 10ms\n");
72
		std::this_thread::sleep_for(std::chrono::milliseconds(10));
73
	}
74

  
75
	// ok, we can play the audio. copy/setup data:
76
	// audio_data_ptr = std::shared_ptr<rst::audition::SoundChunk>(boost::make_shared<rst::audition::SoundChunk>(*audio_chunk));
77
	playback_requested = true;
78
}
79

  
80
void AudioPlayerRSB::playback_thread() {
81
	printf("> playback thread started\n");
82
	playback_state = IDLE;
83

  
84
	while (playback_state != EXITING) {
85
		switch (playback_state) {
86
			default:
87
			case (INITIALIZING):
88
				// waiting to be ready
89
				break;
90

  
91
			case (IDLE):
92
				// nothing to do, wait here until we are triggered to play!
93
				if (playback_requested) {
94
					printf("> AudioPlayerRSB: loading\n");
95
					playback_state = LOADING;
96
				}
97
				break;
98

  
99
			case (LOADING):
100
			{
101
				// send the data
102
				try {
103
					publish_audio_data();
104
				}
105
				catch (std::exception e) {
106
					printf(
107
					   "> AudioPlayerRSB: WARNING: failed to call informer. audio playback probably failed\n> error message = %s",
108
					   e.what());
109
					playback_active = false;
110
					playback_requested = false;
111
					playback_state = IDLE;
112
					break;
113
				}
114

  
115
				// add some delay to meet the delay until playback starts (FIXME: this should be determined!)
116
				// std::this_thread::sleep_for(std::chrono::milliseconds(100));
117

  
118
				// ok we can now play the data
119
				printf("> AudioPlayer: playback started\n");
120
				// mark request as beeing processed
121
				playback_requested = false;
122
				// enter actual playing state
123
				playback_state = PLAYING;
124
				playback_active = true;
125

  
126
				// now we have to wait until the audio playback finished....
127
				long sample_count = audio_data_ptr->sample_count();
128
				int sampling_rate = audio_data_ptr->rate();
129
				double playback_time = (double)sample_count / (double)sampling_rate;
130
				printf("> AudioPlayerRSB estimated playbacktime to %5.3lf seconds. will wait now...", playback_time);
131
				boost::this_thread::sleep(std::chrono::seconds(playback_time));
132
				printf("> AudioPlayerRSB finished waiting...\n");
133
				break;
134
			}
135

  
136
			case (PLAYING):
137
				// when we reach this case, the playback finshed
138
				playback_state = IDLE;
139
				playback_active = false;
140
				printf("> AudioPlayerRSB: finished playback");
141
				break;
142

  
143
			case (ERROR):
144
				printf("> AudioPlayerRSB ERROR! exiting\n");
145
				exit(EXIT_FAILURE);
146
				break;
147
		}
148

  
149
		// 1ms delay to safe cpu time
150
		std::this_thread::sleep_for(std::chrono::milliseconds(1));
151
	}
152

  
153
	// done
154
	playback_state = CLOSED;
155
}
156

  
157
void AudioPlayerRSB::publish_audio_data() {
158
	std::shared_ptr<rst::audition::SoundChunk> request(new rst::audition::SoundChunk());
159

  
160
	request->set_channels(audio_data->sample_channels);
161
	request->set_data(audio_data->samples.data());
162
	/*
163
	    if (audio_data.sample_big_endian){
164
	        request->set_endianness(rst::audition::SoundChunk_EndianNess_ENDIAN_BIG);
165
	    }else{
166
	        request->set_endianness(rst::audition::SoundChunk_EndianNess_ENDIAN_LITTLE);
167
	    }
168

  
169
	    request->set_rate(audio_data.sample_rate);
170
	    request->set_sample_count(audio_data.samples.size() / audio_data.sample_channels / (audio_data.sample_bit/8));
171

  
172
	    switch (audio_data.sample_bit){
173
	        case(8):
174
	            request->set_sample_type(audio_data.sample_signed?(rst::audition::SoundChunk::SAMPLE_S8):(rst::audition::SoundChunk::SAMPLE_U8));
175
	            break;
176
	        case(16):
177
	            request->set_sample_type(audio_data.sample_signed?(rst::audition::SoundChunk::SAMPLE_S16):(rst::audition::SoundChunk::SAMPLE_U16));
178
	            break;
179
	        case(24):
180
	            request->set_sample_type(audio_data.sample_signed?(rst::audition::SoundChunk::SAMPLE_S24):(rst::audition::SoundChunk::SAMPLE_U24));
181
	            break;
182
	        default:
183
	            throw runtime_error("AudioPlayerRSB::publish_audio_data() unsupported sample type bit width");
184
	    }
185
	*/
186
	informer->publish(request);
187
}
188

  
189
AudioPlayerRSB::~AudioPlayerRSB() {
190
}
191

  
192
#endif
server/src/MiddlewareRSB.cpp
1
/*
2
 * This file is part of hlrc_server
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc_server
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
9
 * or (at your option) any later version.
10
 *
11
 * Software distributed under the License is distributed
12
 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
 * express or implied. See the GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.html
18
 * or write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 * The development of this software was supported by the
22
 * Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
 * The Excellence Cluster EXC 277 is a grant of the Deutsche
24
 * Forschungsgemeinschaft (DFG) in the context of the German
25
 * Excellence Initiative.
26
 *
27
 */
28

  
29
#include "MiddlewareRSB.h"
30

  
31
#ifdef RSB_SUPPORT
32
#include <rsb/converter/Repository.h>
33
#include <rsb/converter/ProtocolBufferConverter.h>
34
#include <cstdio>
35

  
36
// CallbackWrapper:
37
#include "RSB/GazeCallbackWrapper.h"
38
#include "RSB/MouthCallbackWrapper.h"
39
#include "RSB/SpeechCallbackWrapper.h"
40
#include "RSB/UtteranceCallbackWrapper.h"
41
#include "RSB/EmotionCallbackWrapper.h"
42
#include "RSB/AnimationCallbackWrapper.h"
43
#include "RSB/UtteranceRSB.h"
44
using namespace std;
45
using namespace rsb;
46
using namespace rsb::patterns;
47

  
48
MiddlewareRSB::MiddlewareRSB(Arbiter* arbiter, std::string scope) : Middleware(arbiter, scope) {
49
	init();
50
}
51

  
52
MiddlewareRSB::~MiddlewareRSB() {
53
}
54

  
55
void MiddlewareRSB::tick() {
56
	// nothing to do
57
}
58

  
59
void MiddlewareRSB::init() {
60
	printf("> registering converters\n");
61

  
62
	// converter for EmotionState
63
	try {
64
		rsb::converter::Converter<string>::Ptr emotionStateConverter(
65
		   new rsb::converter::ProtocolBufferConverter<rst::animation::EmotionExpression>());
66
		rsb::converter::converterRepository<string>()->registerConverter(emotionStateConverter);
67
	}
68
	catch (...) {
69
	}
70

  
71
	// converter for SoundChunk
72
	try {
73
		rsb::converter::Converter<string>::Ptr SoundChunkConverter(
74
		   new rsb::converter::ProtocolBufferConverter<rst::audition::SoundChunk>());
75
		rsb::converter::converterRepository<string>()->registerConverter(SoundChunkConverter);
76
	}
77
	catch (...) {
78
	}
79

  
80
	// converter for Utterance
81
	try {
82
		rsb::converter::Converter<string>::Ptr UtteranceConverter(
83
		   new rsb::converter::ProtocolBufferConverter<rst::audition::Utterance>());
84
		rsb::converter::converterRepository<string>()->registerConverter(UtteranceConverter);
85
	}
86
	catch (...) {
87
	}
88

  
89
	// converter for GazeTarget
90
	try {
91
		rsb::converter::Converter<string>::Ptr gazeTargetConverter(
92
		   new rsb::converter::ProtocolBufferConverter<rst::animation::BinocularHeadGaze>());
93
		rsb::converter::converterRepository<string>()->registerConverter(gazeTargetConverter);
94
	}
95
	catch (...) {
96
	}
97

  
98
	// converter for MouthTarget
99
	// rsb::converter::Converter<string>::Ptr mouthTargetConverter(new
100
	// rsb::converter::ProtocolBufferConverter<rst::robot::MouthTarget>());
101
	// rsb::converter::converterRepository<string>()->registerConverter(mouthTargetConverter);
102

  
103
	// converter for Animation
104
	try {
105
		rsb::converter::Converter<string>::Ptr animationConverter(
106
		   new rsb::converter::ProtocolBufferConverter<rst::animation::HeadAnimation>());
107
		rsb::converter::converterRepository<string>()->registerConverter(animationConverter);
108
	}
109
	catch (...) {
110
	}
111

  
112
	// first get a factory instance that is used to create RSB domain objects
113
	Factory& factory = getFactory();
114

  
115
	// scope to listen on:
116
	string scope = base_scope + "/set/";
117

  
118
	// get server
119
	server = factory.createLocalServer(scope);
120

  
121
	// get tts server:
122
	string tts_scope = base_scope + "/tts_provider";
123
	printf("> registering remote server on %s\n", tts_scope.c_str());
124
	tts_server = factory.createRemoteServer(tts_scope);
125

  
126
	// create local server with parallel exec strategy (HACK!)
127
	rsb::ParticipantConfig config = factory.getDefaultParticipantConfig();
128
	rsc::runtime::Properties& properties = config.mutableEventReceivingStrategy().mutableOptions();
129
	properties.set<string>("parallelhandlercalls", "1");
130

  
131
	// now we can create a server with parallel execution:
132
	server_parallel = factory.createLocalServer(scope, config);
133

  
134
	// this server will now handle/call these methods in multiple threads:
135
	server_parallel->registerMethod("animation", LocalServer::CallbackPtr(new AnimationCallbackWrapper(this)));
136

  
137
	// initialise callbacks:
138
	init_callbacks();
139

  
140
	// informer->publish(gaze_target);
141
	printf("> MiddlewareRSB initialised\n");
142
}
143

  
144
void MiddlewareRSB::init_callback(string name, LocalServer::CallbackPtr callback_ptr) {
145
	printf("> init_callback(%s%s)\n", server->getScope()->toString().c_str(), name.c_str());
146
	server->registerMethod(name, callback_ptr);
147
}
148

  
149
void MiddlewareRSB::init_callbacks() {
150
	printf("> registering callbacks (rpc methods)\n");
151

  
152
	init_callback("speech", LocalServer::CallbackPtr(new SpeechCallbackWrapper(this)));
153
	init_callback("utterance", LocalServer::CallbackPtr(new UtteranceCallbackWrapper(this)));
154
	init_callback("gaze", LocalServer::CallbackPtr(new GazeCallbackWrapper(this)));
155
	/// init_callback("mouth",     LocalServer::CallbackPtr(new MouthCallbackWrapper(this)));
156

  
157
	EmotionCallbackWrapper* emotion_cb = new EmotionCallbackWrapper(this);
158
	init_callback("defaultEmotion", LocalServer::CallbackPtr(emotion_cb));
159
	init_callback("currentEmotion", LocalServer::CallbackPtr(emotion_cb));
160
}
161

  
162
// call a tts system to convert a string to an utterance
163
std::shared_ptr<Utterance> MiddlewareRSB::tts_call(string text) {
164
	double tts_timeout = 1.0; // seconds. DO NOT CHANGE THIS!
165

  
166
	// build request
167
	std::shared_ptr<std::string> request(new string(text));
168

  
169
	// try to fetch it asynchronously:
170
	try {
171
		RemoteServer::DataFuture<rst::audition::Utterance> future_ptr =
172
		   tts_server->callAsync<rst::audition::Utterance>("create_utterance", request);
173

  
174
		// try to fetch the result
175
		std::shared_ptr<rst::audition::Utterance> utterance_ptr = future_ptr.get(tts_timeout);
176

  
177
		// done, return utterance ptr
178
		std::shared_ptr<Utterance> utterance(new UtteranceRSB(*(utterance_ptr.get())));
179
		printf("> done. got utterance (text=%s)\n", utterance->get_text().c_str());
180
		return utterance;
181
	}
182
	catch (rsc::threading::FutureTimeoutException e) {
183
		printf("> error: tts_call timed out after %3.1f seconds.\n", tts_timeout);
184
	}
185
	catch (rsc::threading::FutureTaskExecutionException e) {
186
		printf("> error: tts_call failed: %s\n", e.what());
187
	}
188

  
189
	printf("> failed... got no utterance\n");
190
	std::shared_ptr<Utterance> utterance(new Utterance());
191
	return utterance;
192
}
193

  
194
#endif

Also available in: Unified diff