【ros下ekho tts(语音合成 中文 离线) arm或者X86_64 移植 】

一.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: '你好'" 

然后电脑的默认声卡就会发出 你好 的声音。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值