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

[voice_text] Support new ReadSpeaker API and load libraries dynamically #395

Open
wants to merge 8 commits 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: 0 additions & 1 deletion 3rdparty/voice_text/.gitignore

This file was deleted.

69 changes: 18 additions & 51 deletions 3rdparty/voice_text/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5.1)
project(voice_text)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings")

find_package(catkin REQUIRED COMPONENTS
dynamic_reconfigure
roscpp
message_generation)

find_package(Boost REQUIRED COMPONENTS filesystem)
find_package(Boost REQUIRED COMPONENTS
filesystem)

generate_dynamic_reconfigure_options(
cfg/VoiceText.cfg
Expand All @@ -20,57 +25,19 @@ generate_messages()

catkin_package(CATKIN_DEPENDS message_runtime)

file(GLOB VT_ROOT /usr/vt/*/*)
if(NOT VT_ROOT)
message(WARNING "VoiceText directory should be /usr/vt/*/* (e.g., /usr/vt/sayaka/M16) but is not found")
set(VT_ROOT /usr/vt/sayaka/M16) # default value for following configure_file
else()
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
set(VT_LIB_PATH_OLD ${VT_ROOT}/bin/x86_32/RAMIO/libvt_jpn.so) # e.g., /usr/vt/sayaka/M16/bin/x86_32/RAMIO/libvt_jpn.so
set(VT_LIB_PATH_NEW ${VT_ROOT}/bin/LINUX32_GLIBC3/RAMIO/libvt_jpn.so) # e.g., /usr/vt/risa/H16/bin/LINUX32_GLIBC3/RAMIO/libvt_jpn.so
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(VT_LIB_PATH_OLD ${VT_ROOT}/bin/x86_64/RAMIO/libvt_jpn.so) # e.g., /usr/vt/sayaka/M16/bin/x86_64/RAMIO/libvt_jpn.so
set(VT_LIB_PATH_NEW ${VT_ROOT}/bin/LINUX64_GLIBC3/RAMIO/libvt_jpn.so) # e.g., /usr/vt/risa/H16/bin/LINUX64_GLIBC3/RAMIO/libvt_jpn.so
endif()
if(EXISTS ${VT_LIB_PATH_OLD})
set(VT_LIB_PATH ${VT_LIB_PATH_OLD})
else()
if(EXISTS ${VT_LIB_PATH_NEW})
set(VT_LIB_PATH ${VT_LIB_PATH_NEW})
endif()
endif()
if(VT_LIB_PATH)
message(WARNING "VoiceText library is found at ${VT_LIB_PATH}")
else()
message(WARNING "VoiceText library is not found at ${VT_LIB_PATH_OLD} or ${VT_LIB_PATH_NEW}")
endif()
endif()
configure_file(src/voice_text.cpp.in ${PROJECT_SOURCE_DIR}/src/voice_text.cpp)

include_directories(
${Boost_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)
add_executable(voice_text src/voice_text.cpp)
add_dependencies(voice_text ${PROJECT_NAME}_generate_messages_cpp ${PROJECT_NAME}_gencfg)
set_target_properties(voice_text PROPERTIES COMPILE_FLAGS -D_REENTRANT)
include_directories(
include
${Boost_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)

if(NOT VT_LIB_PATH)
message(WARNING "Building dummy library")
add_library(vt_dummy src/dummy/vt_dummy.cpp)
set_target_properties(vt_dummy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set_target_properties(vt_dummy PROPERTIES LIBRARY_OUTPUT_NAME vt_jpn)
set_target_properties(voice_text PROPERTIES COMPILE_FLAGS -DUSE_DUMMY_INCLUDE)
set(VT_LIB_PATH ${PROJECT_BINARY_DIR}/libvt_jpn.so)
endif()
add_executable(voice_text src/voice_text.cpp src/vt_handler.cpp)
add_dependencies(voice_text ${PROJECT_NAME}_generate_messages_cpp ${PROJECT_NAME}_gencfg)
set_target_properties(voice_text PROPERTIES COMPILE_FLAGS -D_REENTRANT)

target_link_libraries(voice_text
${catkin_LIBRARIES}
${VT_LIB_PATH} -lm -lpthread
)
if(NOT EXISTS ${VT_LIB_PATH})
add_dependencies(voice_text vt_dummy)
endif()
target_link_libraries(voice_text
${catkin_LIBRARIES} -lm -lpthread -ldl
)

install(TARGETS voice_text # do not install vt_dummy target, that should be installed from voice_text library
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
Expand Down
17 changes: 14 additions & 3 deletions 3rdparty/voice_text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ ROS Interface for HOYA VoiceText Speech Synthesis Engine

## Installation

1. Install VoiceText SDK
2. Put license file
3. Build this package
### 1. Install VoiceText SDK
#### If you have voicetext sdk install binary, please follow the official guide and install both engine and SDK
#### If you don't have the sdk install binary but have ReadSpeaker API binary, please follow the guide below.
1. Install VoiceText Engine by official guide
2. Copy VoiceText API binaries to VoiceText binary directory
VoiceText API package includes binary libraries and header file. You have to copy those of them to specific directory by executing following commands.
```bash
cd /path_to_api_package_directory # e.g. cd ~/Downloads/RS_VTAPI_SDK_Linux_4.3.0.2/20201113_VTAPI4.3.0.2_LINUX
cd bin/x64 # You have to cd x86 if your system is x86 architecture
# Assuming VoiceText engine's talker is hikari, type is D16. If it is different, please set appropriate directory.
sudo cp -a * /usr/vt/hikari/D16/bin # Don't forget to add -a not to break symbolic link.
```
### 2. Put license file
### 3. Build this package

```bash
cd /path/to/catkin_workspace
Expand Down
105 changes: 105 additions & 0 deletions 3rdparty/voice_text/include/vt_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* vt_handler.h
* Author: Yoshiki Obinata <obinata@jsk.imi.i.u-tokyo.ac.jp>
*/

#ifndef VT_HANDLER_H_
#define VT_HANDLER_H_

#include <cstdlib>
#include <dlfcn.h>
#include <glob.h>
#include <string>
#include <boost/filesystem.hpp>

// logging
#include <ros/ros.h>

#include "vt_jpn.h"
#include "vtapi.h"

#if __x86_64__ || __ppc64__
#define ENV64
#else
#define ENV32
#endif

typedef enum VT_TYPE{
NO_VT,
VT_SDK,
VT_API
} VT_Types;

namespace fs = boost::filesystem;

class VTHandler{
public:
VTHandler(const std::string license_path, const std::string db_path);
~VTHandler();
bool VTH_TextToFile(const int pitch, const int speed, const int volume, const int pause,
const std::string text, const std::string wave_path);

private:
void* dl_handle;
VT_Types vt_type;

// define handle
bool LoadSym();

// Load symbols
// Related to VoiceText SDK
std::vector<char*> VTSDK_func_ = {
"VT_LOADTTS_JPN",
"VT_UNLOADTTS_JPN",
"VT_GetTTSInfo_JPN",
"VT_TextToFile_JPN"
};

// Related to ReadSpeaker API
std::vector<char*> VTAPI_func_ = {
"VTAPI_Init",
"VTAPI_CreateHandle",
"VTAPI_SetLicenseFolder",
"VTAPI_GetEngine",
"VTAPI_SetEngineHandle",
"VTAPI_SetAttr",
"VTAPI_SetOutputFile",
"VTAPI_TextToFile",
"VTAPI_GetLastErrorInfo",
"VTAPI_ReleaseHandle",
"VTAPI_UnloadEngine",
"VTAPI_Exit"
};

// symbol map
std::map<char*, void*> VTSDK_s_map_;
std::map<char*, void*> VTAPI_s_map_;

// Load Functions
// Related to VoiceText SDK
short (*VT_LOADTTS_JPN)(HWND, int, char*, char*);
void (*VT_UNLOADTTS_JPN)(int);
int (*VT_GetTTSInfo_JPN)(int, char*, void*, int);
short (*VT_TextToFile_JPN)(int, char*, char*, int, int, int, int, int, int, int);

// Related to ReadSpeaker API
int (*VTAPI_Init)(char*);
VTAPI_HANDLE (*VTAPI_CreateHandle)();
void (*VTAPI_SetLicenseFolder)(char*);
VTAPI_ENGINE_HANDLE (*VTAPI_GetEngine)(char*, char*);
int (*VTAPI_SetEngineHandle)(VTAPI_HANDLE, VTAPI_ENGINE_HANDLE);
int (*VTAPI_SetAttr)(VTAPI_HANDLE, int, int);
int (*VTAPI_SetOutputFile)(VTAPI_HANDLE, char*, int);
int (*VTAPI_TextToFile)(VTAPI_HANDLE, void*, int, int);
VTAPI_ERRS_INFO* (*VTAPI_GetLastErrorInfo)(VTAPI_HANDLE);
void (*VTAPI_ReleaseHandle)(VTAPI_HANDLE);
int (*VTAPI_UnloadEngine)(VTAPI_ENGINE_HANDLE);
void (*VTAPI_Exit)();

// ReadSpeaker API handler
VTAPI_HANDLE hVTAPI;
VTAPI_ENGINE_HANDLE hEngine;
};


#endif // VT_HANDLER_H_
Loading