Revision 482adb6d
| client/cpp/include/MiddlewareROS.h | ||
|---|---|---|
| 43 | 43 |
#include <hlrc_server/speechAction.h> |
| 44 | 44 |
#include <actionlib/client/simple_action_client.h> |
| 45 | 45 |
#include <actionlib/client/terminal_state.h> |
| 46 |
#include <boost/shared_ptr.hpp>
|
|
| 46 |
#include <memory>
|
|
| 47 | 47 |
#endif |
| 48 | 48 |
|
| 49 | 49 |
#define ROS_ACTION_CALL_TIMEOUT 30.0 |
| client/cpp/include/MiddlewareRSB.h | ||
|---|---|---|
| 82 | 82 |
rsb::ListenerPtr hack_listener; |
| 83 | 83 |
|
| 84 | 84 |
std::mutex pending_tasks_mutex; |
| 85 |
std::vector<boost::shared_ptr<rst::communicationpatterns::TaskState> > pending_tasks;
|
|
| 85 |
std::vector<std::shared_ptr<rst::communicationpatterns::TaskState> > pending_tasks;
|
|
| 86 | 86 |
unsigned int say_task_active; |
| 87 | 87 |
unsigned int say_task_done; |
| 88 | 88 |
|
| ... | ... | |
| 92 | 92 |
void set_current_saytask(std::string text); |
| 93 | 93 |
|
| 94 | 94 |
void check_for_inprotk(); |
| 95 |
void incoming_hack(boost::shared_ptr<std::string> finished_task);
|
|
| 95 |
void incoming_hack(std::shared_ptr<std::string> finished_task);
|
|
| 96 | 96 |
#endif |
| 97 | 97 |
#endif |
| 98 | 98 |
}; |
| client/cpp/src/MiddlewareROS.cpp | ||
|---|---|---|
| 70 | 70 |
|
| 71 | 71 |
// create node handle |
| 72 | 72 |
// ros_node_handle = new ros::NodeHandle(); |
| 73 |
// node_handle = boost::shared_ptr<ros::NodeHandle>(new ros::NodeHandle());
|
|
| 73 |
// node_handle = std::shared_ptr<ros::NodeHandle>(new ros::NodeHandle());
|
|
| 74 | 74 |
|
| 75 | 75 |
printf("> setting up ROS action clients...\n");
|
| 76 | 76 |
animation_ac = create_action_client<hlrc_server::animationAction>(scope + "/animation"); |
| client/cpp/src/MiddlewareRSB.cpp | ||
|---|---|---|
| 93 | 93 |
} |
| 94 | 94 |
|
| 95 | 95 |
void MiddlewareRSB::publish_emotion(string scope_target, RobotEmotion e, bool blocking) {
|
| 96 |
boost::shared_ptr<rst::animation::EmotionExpression> request(new rst::animation::EmotionExpression());
|
|
| 96 |
std::shared_ptr<rst::animation::EmotionExpression> request(new rst::animation::EmotionExpression());
|
|
| 97 | 97 |
|
| 98 | 98 |
switch (e.value) {
|
| 99 | 99 |
default: |
| ... | ... | |
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 | 140 |
void MiddlewareRSB::publish_gaze_target(RobotGaze incoming_target, bool blocking) {
|
| 141 |
boost::shared_ptr<rst::animation::BinocularHeadGaze> request(new rst::animation::BinocularHeadGaze());
|
|
| 141 |
std::shared_ptr<rst::animation::BinocularHeadGaze> request(new rst::animation::BinocularHeadGaze());
|
|
| 142 | 142 |
|
| 143 |
boost::shared_ptr<rst::geometry::SphericalDirectionFloat> target(new rst::geometry::SphericalDirectionFloat());
|
|
| 143 |
std::shared_ptr<rst::geometry::SphericalDirectionFloat> target(new rst::geometry::SphericalDirectionFloat());
|
|
| 144 | 144 |
target->set_azimuth(incoming_target.pan); |
| 145 | 145 |
target->set_elevation(incoming_target.tilt); |
| 146 | 146 |
request->set_allocated_target(target.get()); |
| 147 | 147 |
|
| 148 | 148 |
request->set_eye_vergence(incoming_target.vergence); |
| 149 | 149 |
|
| 150 |
boost::shared_ptr<rst::geometry::SphericalDirectionFloat> offset(new rst::geometry::SphericalDirectionFloat());
|
|
| 150 |
std::shared_ptr<rst::geometry::SphericalDirectionFloat> offset(new rst::geometry::SphericalDirectionFloat());
|
|
| 151 | 151 |
offset->set_azimuth(incoming_target.pan_offset); |
| 152 | 152 |
offset->set_elevation(incoming_target.tilt_offset); |
| 153 | 153 |
request->set_allocated_offset(offset.get()); |
| ... | ... | |
| 166 | 166 |
|
| 167 | 167 |
void MiddlewareRSB::publish_mouth_target(RobotMouth target, bool blocking) {
|
| 168 | 168 |
/* |
| 169 |
boost::shared_ptr<rst::robot::MouthTarget> request(new rst::robot::MouthTarget());
|
|
| 169 |
std::shared_ptr<rst::robot::MouthTarget> request(new rst::robot::MouthTarget());
|
|
| 170 | 170 |
|
| 171 | 171 |
request->set_position_left( target.position_left); |
| 172 | 172 |
request->set_position_center(target.position_center); |
| ... | ... | |
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 | 188 |
void MiddlewareRSB::publish_head_animation(RobotHeadAnimation a, bool blocking) {
|
| 189 |
boost::shared_ptr<rst::animation::HeadAnimation> request(new rst::animation::HeadAnimation());
|
|
| 189 |
std::shared_ptr<rst::animation::HeadAnimation> request(new rst::animation::HeadAnimation());
|
|
| 190 | 190 |
|
| 191 | 191 |
switch (a.value) {
|
| 192 | 192 |
default: |
| ... | ... | |
| 238 | 238 |
|
| 239 | 239 |
void MiddlewareRSB::publish_speech(string text, bool blocking) {
|
| 240 | 240 |
// say it |
| 241 |
boost::shared_ptr<std::string> request(new string(text));
|
|
| 241 |
std::shared_ptr<std::string> request(new string(text));
|
|
| 242 | 242 |
|
| 243 | 243 |
if (blocking) {
|
| 244 | 244 |
hlrc_server->call<std::string>("speech", request);
|
| server/include/Arbiter.h | ||
|---|---|---|
| 29 | 29 |
#pragma once |
| 30 | 30 |
#include <string> |
| 31 | 31 |
#include <vector> |
| 32 |
#include <boost/shared_ptr.hpp>
|
|
| 32 |
#include <memory>
|
|
| 33 | 33 |
#include <mutex> |
| 34 | 34 |
#include <humotion/client/client.h> |
| 35 | 35 |
#include "EmotionState.h" |
| ... | ... | |
| 49 | 49 |
void set_default_emotion(EmotionState e); |
| 50 | 50 |
void set_current_emotion(EmotionState e); |
| 51 | 51 |
void set_mouth_config(MouthConfig m); |
| 52 |
void speak(boost::shared_ptr<Utterance> u);
|
|
| 52 |
void speak(std::shared_ptr<Utterance> u);
|
|
| 53 | 53 |
bool speak_active(); |
| 54 | 54 |
|
| 55 | 55 |
void set_gaze_target(humotion::GazeState g); |
| 56 | 56 |
void set_mouth_target(humotion::MouthState target); |
| 57 |
void play_animation(boost::shared_ptr<Animation> ani);
|
|
| 57 |
void play_animation(std::shared_ptr<Animation> ani);
|
|
| 58 | 58 |
|
| 59 | 59 |
humotion::GazeState get_gaze_state(); |
| 60 | 60 |
humotion::MouthState get_mouth_state(); |
| ... | ... | |
| 83 | 83 |
|
| 84 | 84 |
MouthConfig mouth_config; |
| 85 | 85 |
|
| 86 |
boost::shared_ptr<Utterance> utterance;
|
|
| 86 |
std::shared_ptr<Utterance> utterance;
|
|
| 87 | 87 |
|
| 88 | 88 |
humotion::GazeState requested_gaze_state; |
| 89 | 89 |
humotion::MouthState requested_mouth_state; |
| ... | ... | |
| 99 | 99 |
std::mutex animation_mutex; |
| 100 | 100 |
Animation active_animation; |
| 101 | 101 |
|
| 102 |
typedef std::vector<boost::shared_ptr<Animation>> active_animation_vector_t;
|
|
| 102 |
typedef std::vector<std::shared_ptr<Animation>> active_animation_vector_t;
|
|
| 103 | 103 |
std::mutex active_animation_vector_mutex; |
| 104 | 104 |
active_animation_vector_t active_animation_vector; |
| 105 | 105 |
|
| server/include/AudioPlayer.h | ||
|---|---|---|
| 28 | 28 |
|
| 29 | 29 |
#pragma once |
| 30 | 30 |
#include <string> |
| 31 |
#include <boost/shared_ptr.hpp>
|
|
| 31 |
#include <memory>
|
|
| 32 | 32 |
#include "AudioData.h" |
| 33 | 33 |
|
| 34 | 34 |
class AudioPlayer {
|
| ... | ... | |
| 47 | 47 |
CLOSED |
| 48 | 48 |
} PLAYBACKSTATE_T; |
| 49 | 49 |
|
| 50 |
virtual void play(boost::shared_ptr<AudioData> audio) = 0;
|
|
| 50 |
virtual void play(std::shared_ptr<AudioData> audio) = 0;
|
|
| 51 | 51 |
bool is_playing(); |
| 52 | 52 |
|
| 53 | 53 |
protected: |
| 54 |
boost::shared_ptr<AudioData> audio_data;
|
|
| 54 |
std::shared_ptr<AudioData> audio_data;
|
|
| 55 | 55 |
PLAYBACKSTATE_T playback_state; |
| 56 | 56 |
std::string audio_driver; |
| 57 | 57 |
bool playback_requested; |
| server/include/AudioPlayerLibAO.h | ||
|---|---|---|
| 37 | 37 |
~AudioPlayerLibAO(); |
| 38 | 38 |
|
| 39 | 39 |
void playback_thread(); |
| 40 |
void play(boost::shared_ptr<AudioData> audio);
|
|
| 40 |
void play(std::shared_ptr<AudioData> audio);
|
|
| 41 | 41 |
bool is_playing(); |
| 42 | 42 |
|
| 43 | 43 |
private: |
| 44 |
ao_sample_format extract_ao_format(boost::shared_ptr<AudioData> audio);
|
|
| 44 |
ao_sample_format extract_ao_format(std::shared_ptr<AudioData> audio);
|
|
| 45 | 45 |
boost::thread* playback_thread_ptr; |
| 46 | 46 |
|
| 47 | 47 |
// std::vector<char> audio_data; |
| server/include/AudioPlayerRSB.h | ||
|---|---|---|
| 41 | 41 |
~AudioPlayerRSB(); |
| 42 | 42 |
|
| 43 | 43 |
void playback_thread(); |
| 44 |
void play(boost::shared_ptr<AudioData> audio);
|
|
| 44 |
void play(std::shared_ptr<AudioData> audio);
|
|
| 45 | 45 |
bool is_playing(); |
| 46 | 46 |
|
| 47 | 47 |
private: |
| server/include/Middleware.h | ||
|---|---|---|
| 41 | 41 |
virtual void tick() = 0; |
| 42 | 42 |
|
| 43 | 43 |
void speak_callback(std::string text); |
| 44 |
void utterance_callback(boost::shared_ptr<Utterance> u);
|
|
| 44 |
void utterance_callback(std::shared_ptr<Utterance> u);
|
|
| 45 | 45 |
void gaze_callback(humotion::GazeState gaze); |
| 46 | 46 |
void mouth_callback(humotion::MouthState mouth); |
| 47 | 47 |
void default_emotion_callback(EmotionState emotion_state); |
| 48 | 48 |
void current_emotion_callback(EmotionState emotion_state); |
| 49 |
void animation_callback(boost::shared_ptr<Animation> ani);
|
|
| 49 |
void animation_callback(std::shared_ptr<Animation> ani);
|
|
| 50 | 50 |
|
| 51 |
virtual boost::shared_ptr<Utterance> tts_call(std::string text) = 0;
|
|
| 51 |
virtual std::shared_ptr<Utterance> tts_call(std::string text) = 0;
|
|
| 52 | 52 |
|
| 53 | 53 |
protected: |
| 54 | 54 |
Arbiter* arbiter; |
| server/include/MiddlewareROS.h | ||
|---|---|---|
| 50 | 50 |
#include "ROS/AnimationCallbackWrapperROS.h" |
| 51 | 51 |
#include "ROS/SpeechCallbackWrapperROS.h" |
| 52 | 52 |
#endif |
| 53 |
#include <boost/shared_ptr.hpp>
|
|
| 53 |
#include <memory>
|
|
| 54 | 54 |
|
| 55 | 55 |
#define ROS_ACTION_CALL_TIMEOUT 30.0 |
| 56 | 56 |
|
| ... | ... | |
| 67 | 67 |
void init(){};
|
| 68 | 68 |
void tick(){};
|
| 69 | 69 |
|
| 70 |
boost::shared_ptr<Utterance> tts_call(std::string text) {
|
|
| 71 |
return boost::shared_ptr<Utterance>(new Utterance());
|
|
| 70 |
std::shared_ptr<Utterance> tts_call(std::string text) {
|
|
| 71 |
return std::shared_ptr<Utterance>(new Utterance());
|
|
| 72 | 72 |
} |
| 73 | 73 |
|
| 74 | 74 |
#else |
| ... | ... | |
| 77 | 77 |
~MiddlewareROS(); |
| 78 | 78 |
void init(); |
| 79 | 79 |
void tick(); |
| 80 |
boost::shared_ptr<Utterance> tts_call(std::string text);
|
|
| 80 |
std::shared_ptr<Utterance> tts_call(std::string text);
|
|
| 81 | 81 |
|
| 82 | 82 |
private: |
| 83 |
// boost::shared_ptr<ros::NodeHandle> node_handle;
|
|
| 83 |
// std::shared_ptr<ros::NodeHandle> node_handle;
|
|
| 84 | 84 |
ros::NodeHandle* ros_node_handle; |
| 85 | 85 |
bool tick_necessary; |
| 86 | 86 |
// listen to tf tree |
| 87 | 87 |
tf2_ros::Buffer tfBuffer; |
| 88 |
boost::shared_ptr<tf2_ros::TransformListener> tfListener;
|
|
| 88 |
std::shared_ptr<tf2_ros::TransformListener> tfListener;
|
|
| 89 | 89 |
|
| 90 | 90 |
// FIXME: These pointers are never destroyed. Shouldn't they be shared_ptrs? |
| 91 | 91 |
AnimationCallbackWrapper* animation_action_server; |
| server/include/MiddlewareRSB.h | ||
|---|---|---|
| 47 | 47 |
} |
| 48 | 48 |
void init(){};
|
| 49 | 49 |
void tick(){};
|
| 50 |
boost::shared_ptr<Utterance> tts_call(std::string text) {
|
|
| 51 |
return boost::shared_ptr<Utterance>(new Utterance());
|
|
| 50 |
std::shared_ptr<Utterance> tts_call(std::string text) {
|
|
| 51 |
return std::shared_ptr<Utterance>(new Utterance());
|
|
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 | 54 |
#else |
| ... | ... | |
| 57 | 57 |
~MiddlewareRSB(); |
| 58 | 58 |
void init(); |
| 59 | 59 |
void tick(); |
| 60 |
boost::shared_ptr<Utterance> tts_call(std::string text);
|
|
| 60 |
std::shared_ptr<Utterance> tts_call(std::string text);
|
|
| 61 | 61 |
|
| 62 | 62 |
private: |
| 63 | 63 |
void init_callbacks(); |
| server/include/ROS/AnimationCallbackWrapperROS.h | ||
|---|---|---|
| 47 | 47 |
hlrc_server::animationGoalConstPtr request = goal; |
| 48 | 48 |
printf("> incoming animation (%d)\n", (int)request->target);
|
| 49 | 49 |
|
| 50 |
boost::shared_ptr<Animation> ani(new Animation());
|
|
| 50 |
std::shared_ptr<Animation> ani(new Animation());
|
|
| 51 | 51 |
|
| 52 | 52 |
// everything is ok, will be cleared on failures |
| 53 | 53 |
feedback.result = 1; |
| server/include/ROS/UtteranceCallbackWrapperROS.h | ||
|---|---|---|
| 53 | 53 |
// everything is ok, will be cleared on failures |
| 54 | 54 |
feedback.result = 1; |
| 55 | 55 |
|
| 56 |
boost::shared_ptr<Utterance> utterance(new Utterance());
|
|
| 56 |
std::shared_ptr<Utterance> utterance(new Utterance());
|
|
| 57 | 57 |
|
| 58 | 58 |
// copy values: |
| 59 | 59 |
utterance->set_text(request->utterance.text); |
| 60 | 60 |
|
| 61 |
boost::shared_ptr<AudioData> audio_data(new AudioData());
|
|
| 61 |
std::shared_ptr<AudioData> audio_data(new AudioData());
|
|
| 62 | 62 |
if (!extract_audio(request->utterance.audio, audio_data)) {
|
| 63 | 63 |
feedback.result = 0; |
| 64 | 64 |
} |
| ... | ... | |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
// convert ros message audio data to our own implementation |
| 82 |
bool extract_audio(hlrc_server::soundchunk sound_chunk, boost::shared_ptr<AudioData> audio_data) {
|
|
| 82 |
bool extract_audio(hlrc_server::soundchunk sound_chunk, std::shared_ptr<AudioData> audio_data) {
|
|
| 83 | 83 |
// extract data: |
| 84 | 84 |
unsigned int audio_len = sound_chunk.data.size(); |
| 85 | 85 |
char* audio_data_char = (char*)sound_chunk.data.data(); |
| server/include/RSB/AnimationCallbackWrapper.h | ||
|---|---|---|
| 36 | 36 |
AnimationCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
|
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 |
void call(const std::string& method_name, boost::shared_ptr<rst::animation::HeadAnimation> input) {
|
|
| 39 |
void call(const std::string& method_name, std::shared_ptr<rst::animation::HeadAnimation> input) {
|
|
| 40 | 40 |
printf("> incomint animation (method = %s)\n", method_name.c_str());
|
| 41 | 41 |
|
| 42 | 42 |
// fetch animation passed by rsb: |
| 43 | 43 |
rst::animation::HeadAnimation* rst_ani = input.get(); |
| 44 |
boost::shared_ptr<Animation> ani(new Animation());
|
|
| 44 |
std::shared_ptr<Animation> ani(new Animation());
|
|
| 45 | 45 |
|
| 46 | 46 |
switch ((int)rst_ani->animation()) {
|
| 47 | 47 |
case (rst_ani->IDLE): |
| server/include/RSB/CallbackWrapper.h | ||
|---|---|---|
| 46 | 46 |
~CallbackWrapper() {
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 |
virtual void call(const std::string&, boost::shared_ptr<T> param) = 0;
|
|
| 49 |
virtual void call(const std::string&, std::shared_ptr<T> param) = 0;
|
|
| 50 | 50 |
|
| 51 | 51 |
protected: |
| 52 | 52 |
Middleware* mw; |
| server/include/RSB/EmotionCallbackWrapper.h | ||
|---|---|---|
| 35 | 35 |
EmotionCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
|
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
void call(const std::string& method_name, boost::shared_ptr<rst::animation::EmotionExpression> input) {
|
|
| 38 |
void call(const std::string& method_name, std::shared_ptr<rst::animation::EmotionExpression> input) {
|
|
| 39 | 39 |
printf("> incoming emotion (%s = %d)\n", method_name.c_str(), (int)input->emotion());
|
| 40 | 40 |
|
| 41 | 41 |
EmotionState emotion_state; |
| server/include/RSB/GazeCallbackWrapper.h | ||
|---|---|---|
| 34 | 34 |
public: |
| 35 | 35 |
GazeCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
|
| 36 | 36 |
} |
| 37 |
void call(const std::string& method_name, boost::shared_ptr<rst::animation::BinocularHeadGaze> input) {
|
|
| 37 |
void call(const std::string& method_name, std::shared_ptr<rst::animation::BinocularHeadGaze> input) {
|
|
| 38 | 38 |
rst::animation::BinocularHeadGaze* gaze = input.get(); |
| 39 | 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 | 40 |
|
| server/include/RSB/MouthCallbackWrapper.h | ||
|---|---|---|
| 34 | 34 |
class MouthCallbackWrapper : public CallbackWrapper<rst::robot::MouthTarget>{
|
| 35 | 35 |
public: |
| 36 | 36 |
MouthCallbackWrapper(Middleware *mw) : CallbackWrapper(mw){}
|
| 37 |
void call(const std::string& method_name, boost::shared_ptr<rst::robot::MouthTarget> input){
|
|
| 37 |
void call(const std::string& method_name, std::shared_ptr<rst::robot::MouthTarget> input){
|
|
| 38 | 38 |
rst::robot::MouthTarget *mouth = input.get(); |
| 39 | 39 |
|
| 40 | 40 |
humotion::MouthState mouth_state; |
| server/include/RSB/SpeechCallbackWrapper.h | ||
|---|---|---|
| 35 | 35 |
SpeechCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
|
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
void call(const std::string&, boost::shared_ptr<std::string> _text) {
|
|
| 38 |
void call(const std::string&, std::shared_ptr<std::string> _text) {
|
|
| 39 | 39 |
// send to application |
| 40 | 40 |
std::string text = *_text.get(); |
| 41 | 41 |
//<voice effect=\"Rate(durScale:1.5) + TractScaler(durScale:1.1)\">" + |
| server/include/RSB/UtteranceCallbackWrapper.h | ||
|---|---|---|
| 35 | 35 |
public: |
| 36 | 36 |
UtteranceCallbackWrapper(Middleware* mw) : CallbackWrapper(mw) {
|
| 37 | 37 |
} |
| 38 |
void call(const std::string&, boost::shared_ptr<rst::audition::Utterance> param) {
|
|
| 38 |
void call(const std::string&, std::shared_ptr<rst::audition::Utterance> param) {
|
|
| 39 | 39 |
// convert rsb utterance to out own: |
| 40 | 40 |
rst::audition::Utterance* rst_utterance = param.get(); |
| 41 | 41 |
printf("> incoming utterance '%s' (%d phone symbols)\n", param->textual_representation().c_str(),
|
| 42 | 42 |
(int)rst_utterance->phonemes().element().size()); |
| 43 | 43 |
|
| 44 |
boost::shared_ptr<Utterance> utterance(new UtteranceRSB(*rst_utterance));
|
|
| 44 |
std::shared_ptr<Utterance> utterance(new UtteranceRSB(*rst_utterance));
|
|
| 45 | 45 |
|
| 46 | 46 |
// send to application; |
| 47 | 47 |
mw->utterance_callback(utterance); |
| server/include/Utterance.h | ||
|---|---|---|
| 30 | 30 |
#include <string> |
| 31 | 31 |
#include <vector> |
| 32 | 32 |
#include <chrono> |
| 33 |
#include <boost/shared_ptr.hpp>
|
|
| 33 |
#include <memory>
|
|
| 34 | 34 |
#include "AudioData.h" |
| 35 | 35 |
|
| 36 | 36 |
class Utterance {
|
| ... | ... | |
| 43 | 43 |
|
| 44 | 44 |
void set_phoneme_vector(phonemes_vector_t p); |
| 45 | 45 |
void set_text(std::string t); |
| 46 |
void set_audio_data(boost::shared_ptr<AudioData> a);
|
|
| 46 |
void set_audio_data(std::shared_ptr<AudioData> a);
|
|
| 47 | 47 |
|
| 48 | 48 |
void start_playback(); |
| 49 | 49 |
bool is_playing(); |
| 50 | 50 |
std::string currently_active_phoneme(); |
| 51 |
boost::shared_ptr<AudioData> get_audio_data();
|
|
| 51 |
std::shared_ptr<AudioData> get_audio_data();
|
|
| 52 | 52 |
std::string get_text(); |
| 53 | 53 |
|
| 54 | 54 |
protected: |
| 55 |
boost::shared_ptr<AudioData> audio_data;
|
|
| 55 |
std::shared_ptr<AudioData> audio_data;
|
|
| 56 | 56 |
std::string text; |
| 57 | 57 |
phonemes_vector_t phonemes_vector; |
| 58 | 58 |
|
| server/src/Arbiter.cpp | ||
|---|---|---|
| 64 | 64 |
gaze_state_animation_restart = true; |
| 65 | 65 |
emotion_target = &emotion_config_default; |
| 66 | 66 |
|
| 67 |
utterance = boost::shared_ptr<Utterance>(new Utterance());
|
|
| 67 |
utterance = std::shared_ptr<Utterance>(new Utterance());
|
|
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
Arbiter::~Arbiter() {
|
| ... | ... | |
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 | 122 |
//! note: this is blocking! |
| 123 |
void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation) {
|
|
| 123 |
void Arbiter::play_animation(std::shared_ptr<Animation> incoming_animation) {
|
|
| 124 | 124 |
// incoming animation, check if this would conflict with any pending animations: |
| 125 | 125 |
// lock access & iterate over vector: |
| 126 | 126 |
std::unique_lock<std::mutex> lock_av(active_animation_vector_mutex); |
| 127 | 127 |
active_animation_vector_t::iterator it; |
| 128 | 128 |
for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
|
| 129 |
boost::shared_ptr<Animation> current_ani = *it;
|
|
| 129 |
std::shared_ptr<Animation> current_ani = *it;
|
|
| 130 | 130 |
// check if the running animation collides with the incoming animation: |
| 131 | 131 |
if (current_ani->collides_with(incoming_animation.get())) {
|
| 132 | 132 |
// this would fail, we can not play this animation right now! |
| ... | ... | |
| 153 | 153 |
// ok, it finished. we can safely remove it now: |
| 154 | 154 |
lock_av.lock(); |
| 155 | 155 |
for (it = active_animation_vector.begin(); it < active_animation_vector.end();) {
|
| 156 |
boost::shared_ptr<Animation> current_ani = *it;
|
|
| 156 |
std::shared_ptr<Animation> current_ani = *it;
|
|
| 157 | 157 |
if (*it == incoming_animation) {
|
| 158 | 158 |
// printf(">match -> remove incoming ani again\n");
|
| 159 | 159 |
it = active_animation_vector.erase(it); |
| ... | ... | |
| 165 | 165 |
} |
| 166 | 166 |
|
| 167 | 167 |
void Arbiter::speak( |
| 168 |
boost::shared_ptr<Utterance> u) { //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
|
|
| 168 |
std::shared_ptr<Utterance> u) { //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
|
|
| 169 | 169 |
// lock audio playback as such: |
| 170 | 170 |
const std::lock_guard<std::mutex> lock_audio(audio_player_mutex); |
| 171 | 171 |
|
| ... | ... | |
| 355 | 355 |
const std::lock_guard<std::mutex> lock_av(active_animation_vector_mutex); |
| 356 | 356 |
active_animation_vector_t::iterator it; |
| 357 | 357 |
for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
|
| 358 |
boost::shared_ptr<Animation> current_ani = *it;
|
|
| 358 |
std::shared_ptr<Animation> current_ani = *it;
|
|
| 359 | 359 |
|
| 360 | 360 |
// gaze_state.dump(); |
| 361 | 361 |
current_ani->apply_on_gazestate(&gaze_state); |
| server/src/AudioPlayerLibAO.cpp | ||
|---|---|---|
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
// this will return once we start playing |
| 56 |
void AudioPlayerLibAO::play(boost::shared_ptr<AudioData> audio) {
|
|
| 56 |
void AudioPlayerLibAO::play(std::shared_ptr<AudioData> audio) {
|
|
| 57 | 57 |
audio_data = audio; |
| 58 | 58 |
|
| 59 | 59 |
printf("> AudioPlayerLibAO: play() %d samples requested\n", (int)audio_data->samples.size());
|
| ... | ... | |
| 82 | 82 |
printf("> playback running.\n");
|
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 |
ao_sample_format AudioPlayerLibAO::extract_ao_format(boost::shared_ptr<AudioData> audio) {
|
|
| 85 |
ao_sample_format AudioPlayerLibAO::extract_ao_format(std::shared_ptr<AudioData> audio) {
|
|
| 86 | 86 |
ao_sample_format ao_format; |
| 87 | 87 |
|
| 88 | 88 |
// get bits per sample |
| server/src/AudioPlayerRSB.cpp | ||
|---|---|---|
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 | 63 |
// this will return once we start playing |
| 64 |
void AudioPlayerRSB::play(boost::shared_ptr<AudioData> _audio_data) {
|
|
| 64 |
void AudioPlayerRSB::play(std::shared_ptr<AudioData> _audio_data) {
|
|
| 65 | 65 |
audio_data = _audio_data; |
| 66 | 66 |
|
| 67 | 67 |
printf("> AudioPlayerRSB: play() %d samples requested\n", (int)audio_data->samples.size());
|
| ... | ... | |
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 | 75 |
// ok, we can play the audio. copy/setup data: |
| 76 |
// audio_data_ptr = boost::shared_ptr<rst::audition::SoundChunk>(boost::make_shared<rst::audition::SoundChunk>(*audio_chunk));
|
|
| 76 |
// audio_data_ptr = std::shared_ptr<rst::audition::SoundChunk>(boost::make_shared<rst::audition::SoundChunk>(*audio_chunk));
|
|
| 77 | 77 |
playback_requested = true; |
| 78 | 78 |
} |
| 79 | 79 |
|
| ... | ... | |
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 | 157 |
void AudioPlayerRSB::publish_audio_data() {
|
| 158 |
boost::shared_ptr<rst::audition::SoundChunk> request(new rst::audition::SoundChunk());
|
|
| 158 |
std::shared_ptr<rst::audition::SoundChunk> request(new rst::audition::SoundChunk());
|
|
| 159 | 159 |
|
| 160 | 160 |
request->set_channels(audio_data->sample_channels); |
| 161 | 161 |
request->set_data(audio_data->samples.data()); |
| server/src/Middleware.cpp | ||
|---|---|---|
| 43 | 43 |
printf("> %s(%s) called\n", __FUNCTION__, text.c_str());
|
| 44 | 44 |
|
| 45 | 45 |
// call a tts system to convert the text to an utterance: |
| 46 |
boost::shared_ptr<Utterance> utterance = tts_call(text);
|
|
| 46 |
std::shared_ptr<Utterance> utterance = tts_call(text);
|
|
| 47 | 47 |
|
| 48 | 48 |
// and then process it |
| 49 | 49 |
utterance_callback(utterance); |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
void Middleware::utterance_callback(boost::shared_ptr<Utterance> utterance) {
|
|
| 52 |
void Middleware::utterance_callback(std::shared_ptr<Utterance> utterance) {
|
|
| 53 | 53 |
printf("> %s(text=%s) called\n", __FUNCTION__, utterance->get_text().c_str());
|
| 54 | 54 |
|
| 55 | 55 |
// can we speak this now? |
| ... | ... | |
| 82 | 82 |
arbiter->set_current_emotion(emotion_state); |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 |
void Middleware::animation_callback(boost::shared_ptr<Animation> ani) {
|
|
| 85 |
void Middleware::animation_callback(std::shared_ptr<Animation> ani) {
|
|
| 86 | 86 |
arbiter->play_animation(ani); |
| 87 | 87 |
} |
| server/src/MiddlewareROS.cpp | ||
|---|---|---|
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 | 120 |
// call a tts system to convert a string to an utterance |
| 121 |
boost::shared_ptr<Utterance> MiddlewareROS::tts_call(string text) {
|
|
| 122 |
boost::shared_ptr<Utterance> utterance(new Utterance());
|
|
| 121 |
std::shared_ptr<Utterance> MiddlewareROS::tts_call(string text) {
|
|
| 122 |
std::shared_ptr<Utterance> utterance(new Utterance());
|
|
| 123 | 123 |
|
| 124 | 124 |
// double tts_timeout = 1.0; //seconds. DO NOT CHANGE THIS! |
| 125 | 125 |
if (tts_ac == NULL) {
|
| ... | ... | |
| 143 | 143 |
else {
|
| 144 | 144 |
// done, return utterance ptr |
| 145 | 145 |
ttsResultConstPtr tts_res = tts_ac->getResult(); |
| 146 |
boost::shared_ptr<Utterance> utterance(new UtteranceROS(tts_res));
|
|
| 146 |
std::shared_ptr<Utterance> utterance(new UtteranceROS(tts_res));
|
|
| 147 | 147 |
printf("> done. got utterance (text=%s)\n", utterance->get_text().c_str());
|
| 148 | 148 |
return utterance; |
| 149 | 149 |
} |
| server/src/MiddlewareRSB.cpp | ||
|---|---|---|
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 | 162 |
// call a tts system to convert a string to an utterance |
| 163 |
boost::shared_ptr<Utterance> MiddlewareRSB::tts_call(string text) {
|
|
| 163 |
std::shared_ptr<Utterance> MiddlewareRSB::tts_call(string text) {
|
|
| 164 | 164 |
double tts_timeout = 1.0; // seconds. DO NOT CHANGE THIS! |
| 165 | 165 |
|
| 166 | 166 |
// build request |
| 167 |
boost::shared_ptr<std::string> request(new string(text));
|
|
| 167 |
std::shared_ptr<std::string> request(new string(text));
|
|
| 168 | 168 |
|
| 169 | 169 |
// try to fetch it asynchronously: |
| 170 | 170 |
try {
|
| ... | ... | |
| 172 | 172 |
tts_server->callAsync<rst::audition::Utterance>("create_utterance", request);
|
| 173 | 173 |
|
| 174 | 174 |
// try to fetch the result |
| 175 |
boost::shared_ptr<rst::audition::Utterance> utterance_ptr = future_ptr.get(tts_timeout);
|
|
| 175 |
std::shared_ptr<rst::audition::Utterance> utterance_ptr = future_ptr.get(tts_timeout);
|
|
| 176 | 176 |
|
| 177 | 177 |
// done, return utterance ptr |
| 178 |
boost::shared_ptr<Utterance> utterance(new UtteranceRSB(*(utterance_ptr.get())));
|
|
| 178 |
std::shared_ptr<Utterance> utterance(new UtteranceRSB(*(utterance_ptr.get())));
|
|
| 179 | 179 |
printf("> done. got utterance (text=%s)\n", utterance->get_text().c_str());
|
| 180 | 180 |
return utterance; |
| 181 | 181 |
} |
| ... | ... | |
| 187 | 187 |
} |
| 188 | 188 |
|
| 189 | 189 |
printf("> failed... got no utterance\n");
|
| 190 |
boost::shared_ptr<Utterance> utterance(new Utterance());
|
|
| 190 |
std::shared_ptr<Utterance> utterance(new Utterance());
|
|
| 191 | 191 |
return utterance; |
| 192 | 192 |
} |
| 193 | 193 |
|
| server/src/Utterance.cpp | ||
|---|---|---|
| 28 | 28 |
|
| 29 | 29 |
#include "Utterance.h" |
| 30 | 30 |
using namespace std; |
| 31 |
using namespace boost; |
|
| 32 | 31 |
|
| 33 | 32 |
#define DEBUG_PRINT_PHONEMES 1 |
| 34 | 33 |
|
| 35 | 34 |
Utterance::Utterance() {
|
| 36 | 35 |
playing = false; |
| 37 | 36 |
text = "UNINITIALISED UTTERANCE"; |
| 38 |
audio_data = boost::shared_ptr<AudioData>(new AudioData());
|
|
| 37 |
audio_data = std::shared_ptr<AudioData>(new AudioData());
|
|
| 39 | 38 |
} |
| 40 | 39 |
|
| 41 | 40 |
void Utterance::set_phoneme_vector(phonemes_vector_t p) {
|
| ... | ... | |
| 46 | 45 |
text = t; |
| 47 | 46 |
} |
| 48 | 47 |
|
| 49 |
void Utterance::set_audio_data(boost::shared_ptr<AudioData> a) {
|
|
| 48 |
void Utterance::set_audio_data(std::shared_ptr<AudioData> a) {
|
|
| 50 | 49 |
audio_data = a; |
| 51 | 50 |
} |
| 52 | 51 |
|
| ... | ... | |
| 57 | 56 |
return text; |
| 58 | 57 |
} |
| 59 | 58 |
|
| 60 |
boost::shared_ptr<AudioData> Utterance::get_audio_data() {
|
|
| 59 |
std::shared_ptr<AudioData> Utterance::get_audio_data() {
|
|
| 61 | 60 |
return audio_data; |
| 62 | 61 |
} |
| 63 | 62 |
|
Also available in: Unified diff