Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add play audio file service #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set(
src/services/robot_config.cpp
src/services/set_language.cpp
src/services/get_language.cpp
src/services/play_audio_file.cpp
)

set(
Expand Down
1 change: 1 addition & 0 deletions CMakeLists_catkin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(catkin COMPONENTS
image_transport
kdl_parser
naoqi_bridge_msgs
nao_interaction_msgs
naoqi_libqi
naoqi_libqicore
robot_state_publisher
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<build_depend>image_transport</build_depend>
<build_depend>kdl_parser</build_depend>
<build_depend version_gte="0.0.4">naoqi_bridge_msgs</build_depend>
<build_depend>nao_interaction_msgs</build_depend>
<build_depend>naoqi_libqi</build_depend>
<build_depend>naoqi_libqicore</build_depend>
<build_depend>orocos_kdl</build_depend>
Expand All @@ -27,6 +28,7 @@
<build_depend>rosconsole</build_depend>
<build_depend>rosgraph_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>tf2_geometry_msgs</build_depend>
<build_depend>tf2_msgs</build_depend>
<build_depend>tf2_ros</build_depend>
Expand Down
14 changes: 14 additions & 0 deletions src/helpers/driver_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ std::string& getLanguage( const qi::SessionPtr& session )
return language;
}

/** Function that plays audio file
*/
std_msgs::Empty& playAudioFile( const qi::SessionPtr& session, nao_interaction_msgs::AudioPlaybackRequest req)
{
std::cout << "Receiving service call of playing audio file" << std::endl;
try{
qi::AnyObject p_audio_player = session->service("ALAudioPlayer");
p_audio_player.call<void>("playFile", "/home/nao/" + req.file_path.data);
}
catch(const std::exception& e){
std::cout << "Error in executing service of playing audio file" << std::endl;
}
}

} // driver
} // helpers
} // naoqi
7 changes: 7 additions & 0 deletions src/helpers/driver_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@

#include <naoqi_bridge_msgs/RobotInfo.h>

#include <std_msgs/Empty.h>

#include <naoqi_bridge_msgs/SetString.h>

#include <nao_interaction_msgs/AudioPlayback.h>

#include <qi/applicationsession.hpp>


namespace naoqi
{
namespace helpers
Expand All @@ -42,6 +47,8 @@ bool& setLanguage( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRe

std::string& getLanguage( const qi::SessionPtr& session );

std_msgs::Empty& playAudioFile( const qi::SessionPtr& session, nao_interaction_msgs::AudioPlaybackRequest req);

} // driver
} // helpers
} // naoqi
Expand Down
2 changes: 2 additions & 0 deletions src/naoqi_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "services/robot_config.hpp"
#include "services/set_language.hpp"
#include "services/get_language.hpp"
#include "services/play_audio_file.hpp"

/*
* RECORDERS
Expand Down Expand Up @@ -893,6 +894,7 @@ void Driver::registerDefaultServices()
registerService( boost::make_shared<service::RobotConfigService>("get_robot_config", "/naoqi_driver/get_robot_config", sessionPtr_) );
registerService( boost::make_shared<service::SetLanguageService>("set_language", "/naoqi_driver/set_language", sessionPtr_) );
registerService( boost::make_shared<service::GetLanguageService>("get_language", "/naoqi_driver/get_language", sessionPtr_) );
registerService( boost::make_shared<service::PlayAudioFileService>("play audio file", "/naoqi_driver/play_audio_file", sessionPtr_) );
}

std::vector<std::string> Driver::getAvailableConverters()
Expand Down
28 changes: 28 additions & 0 deletions src/services/play_audio_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "play_audio_file.hpp"
#include "../helpers/driver_helpers.hpp"

namespace naoqi
{
namespace service
{

PlayAudioFileService::PlayAudioFileService( const std::string& name, const std::string& topic, const qi::SessionPtr& session )
: name_(name),
topic_(topic),
session_(session)
{}

void PlayAudioFileService::reset( ros::NodeHandle& nh )
{
service_ = nh.advertiseService(topic_, &PlayAudioFileService::callback, this);
}

bool PlayAudioFileService::callback( nao_interaction_msgs::AudioPlaybackRequest& req, nao_interaction_msgs::AudioPlaybackResponse& resp )
{
helpers::driver::playAudioFile(session_, req);
return true;
}


}
}
49 changes: 49 additions & 0 deletions src/services/play_audio_file.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef PLAY_AUDIO_FILE_SERVICE_HPP
#define PLAY_AUDIO_FILE_SERVICE_HPP

#include <iostream>

#include <ros/node_handle.h>
#include <ros/service_server.h>

#include <nao_interaction_msgs/AudioPlayback.h>
#include <qi/session.hpp>

namespace naoqi
{
namespace service
{

class PlayAudioFileService
{
public:
PlayAudioFileService( const std::string& name, const std::string& topic, const qi::SessionPtr& session );

~PlayAudioFileService(){};

std::string name() const
{
return name_;
}

std::string topic() const
{
return topic_;
}

void reset( ros::NodeHandle& nh );

bool callback( nao_interaction_msgs::AudioPlaybackRequest& req, nao_interaction_msgs::AudioPlaybackResponse& resp );


private:
const std::string name_;
const std::string topic_;

const qi::SessionPtr& session_;
ros::ServiceServer service_;
};

} // service
} // naoqi
#endif