文章目录
一.ekho安装
1.sudo apt-get install libsndfile1-dev libpulse-dev libncurses5-dev libmp3lame-dev libespeak-dev
2.https://github.com/hgneng/ekho.git (官网:http://www.eguidedog.net 或者直接./install.pl 或者下载压缩包)
$ cd ekho
$ ./configure
$ make
$ sudo make install
$ ekho "你好 世界" // 在终端测试
二.ROS_C++调用
1.创建一个ros包tts_ros
2.tts_ros/include/
(并在编译安装过后的ekho包里找到 config.h、sonic.h和 utf8/ 放到tts_ros/include 或者/usr/local/include 如果安装成功这里应该有ekho.h、utf8.h)
tts_ros/include/ros_ekho.h
#ifndef __ROS_EKHO_H_
#define __ROS_EKHO_H_
#include <ros/ros.h>
#include <std_msgs/String.h>
#include "config.h"
#include "ekho.h"
namespace ros_ekho {
class RosEkho {
public:
RosEkho(ros::NodeHandle& nh);
~RosEkho();
void voiceCallback(const std_msgs::String::ConstPtr& msg);
private:
ros::Subscriber tts_sub_;
};
} // namespace ros_ekho
#endif
3.tts_ros/src/ros_ekho.src
#include "ros_ekho.h"
namespace ros_ekho {
RosEkho::RosEkho(ros::NodeHandle& nh) {
tts_sub_ = nh.subscribe<std_msgs::String>(
"/ekho_listener/data", 2, &ros_ekho::RosEkho::voiceCallback, this);
}
RosEkho::~RosEkho() {}
void RosEkho::voiceCallback(const std_msgs::String::ConstPtr& msg) {
ekho::Ekho ekho("Mandarin");
std::string text = msg->data;
ekho.speak(text);
}
} // namespace ros_ekho
int main(int argc, char** argv) {
ros::init(argc, argv, "ekho_listener_node");
ros::NodeHandle nh("~");
const std::string node_name = ros::this_node::getName();
ROS_INFO("this node name: %s", node_name.c_str());
ros_ekho::RosEkho ekho_tts(nh);
ros::spin();
return 0;
}
4.tts_ros/lib
1.在ekho编译安装后的源码目录下找到(在arm上安装了ekho 换一下这俩个静态库就行文件 x86_64 上也一样 在那个架构使用在那个架构上编译安装ekho):
libekho.a
libmusicxml2.a
2./usr/lib/speech_tools/lib 默认安装路径里找到这三个静态库文件 不用也可以
libestbase.a
libestools.a
libeststring.a
5.tts_ros/CMakeLists.txt
cmake_minimum_required(VERSION 3.0.2)
project(ros_ekho)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
add_definitions("-Wall -g")
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
LIBRARIES ros_ekho
CATKIN_DEPENDS roscpp rospy std_msgs
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
)
link_directories(${catkin_LIB_DIRS} lib)
add_executable(ros_ekho src/ros_ekho.cpp)
target_link_libraries(ros_ekho ${catkin_LIBRARIES} -lstdc++ libekho.a libmusicxml2.a libestbase.a libestools.a libeststring.a -lpthread -lvorbisenc -lvorbis -lm -logg -lmp3lame -lsndfile -lncurses -lespeak -lsndfile -lpthread -pthread -lpulse -lpulse-simple)
三.运行
rostopic pub /ekho_listener/data std_msgs/String "data: '你好'"
然后电脑的默认声卡就会发出 你好 的声音。