Skip to content

Commit dfbf17d

Browse files
authored
Merge pull request #395 from mqcmd196/PR/merge_vtapi_vtsdk
[voice_text] Support new ReadSpeaker API and load libraries dynamically
2 parents 2e2d08e + f2cd058 commit dfbf17d

File tree

13 files changed

+757
-346
lines changed

13 files changed

+757
-346
lines changed

3rdparty/voice_text/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

3rdparty/voice_text/CMakeLists.txt

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(voice_text)
3+
4+
# voice_text requires C++ 11
5+
if(CMAKE_VERSION VERSION_LESS "3.1")
6+
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=")
7+
include(CheckCXXCompilerFlag)
8+
check_cxx_compiler_flag("-std=c++11" HAS_CXX11_FLAG)
9+
if(HAS_CXX11_FLAG)
10+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
11+
else()
12+
check_cxx_compiler_flag("-std=gnu++11" HAS_GNUXX11_FLAG)
13+
if(HAS_GNUXX11_FLAG)
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
15+
endif()
16+
endif()
17+
endif()
18+
endif()
19+
if("$ENV{ROS_DISTRO}" STREQUAL "kinetic")
20+
add_compile_options(-std=c++11)
21+
endif()
22+
323
find_package(catkin REQUIRED COMPONENTS
424
dynamic_reconfigure
525
roscpp
@@ -20,64 +40,28 @@ generate_messages()
2040

2141
catkin_package(CATKIN_DEPENDS message_runtime)
2242

23-
file(GLOB VT_ROOT /usr/vt/*/*)
24-
if(NOT VT_ROOT)
25-
message(WARNING "VoiceText directory should be /usr/vt/*/* (e.g., /usr/vt/sayaka/M16) but is not found")
26-
set(VT_ROOT /usr/vt/sayaka/M16) # default value for following configure_file
27-
else()
28-
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
29-
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
30-
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
31-
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
32-
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
33-
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
34-
endif()
35-
if(EXISTS ${VT_LIB_PATH_OLD})
36-
set(VT_LIB_PATH ${VT_LIB_PATH_OLD})
37-
else()
38-
if(EXISTS ${VT_LIB_PATH_NEW})
39-
set(VT_LIB_PATH ${VT_LIB_PATH_NEW})
40-
endif()
41-
endif()
42-
if(VT_LIB_PATH)
43-
message(WARNING "VoiceText library is found at ${VT_LIB_PATH}")
44-
else()
45-
message(WARNING "VoiceText library is not found at ${VT_LIB_PATH_OLD} or ${VT_LIB_PATH_NEW}")
46-
endif()
47-
endif()
48-
configure_file(src/voice_text.cpp.in ${PROJECT_SOURCE_DIR}/src/voice_text.cpp)
49-
50-
include_directories(
51-
${Boost_INCLUDE_DIRS}
52-
${catkin_INCLUDE_DIRS}
53-
)
54-
add_executable(voice_text src/voice_text.cpp)
55-
add_dependencies(voice_text ${PROJECT_NAME}_generate_messages_cpp ${PROJECT_NAME}_gencfg)
56-
set_target_properties(voice_text PROPERTIES COMPILE_FLAGS -D_REENTRANT)
43+
include_directories(
44+
include
45+
${Boost_INCLUDE_DIRS}
46+
${catkin_INCLUDE_DIRS}
47+
)
5748

58-
if(NOT VT_LIB_PATH)
59-
message(WARNING "Building dummy library")
60-
add_library(vt_dummy src/dummy/vt_dummy.cpp)
61-
set_target_properties(vt_dummy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
62-
set_target_properties(vt_dummy PROPERTIES LIBRARY_OUTPUT_NAME vt_jpn)
63-
set_target_properties(voice_text PROPERTIES COMPILE_FLAGS -DUSE_DUMMY_INCLUDE)
64-
set(VT_LIB_PATH ${PROJECT_BINARY_DIR}/libvt_jpn.so)
65-
endif()
49+
add_executable(voice_text src/voice_text.cpp src/vt_handler.cpp)
50+
add_dependencies(voice_text ${PROJECT_NAME}_generate_messages_cpp ${PROJECT_NAME}_gencfg)
51+
set_target_properties(voice_text PROPERTIES COMPILE_FLAGS -D_REENTRANT)
6652

67-
target_link_libraries(voice_text
68-
${catkin_LIBRARIES}
69-
${VT_LIB_PATH} -lm -lpthread
70-
)
71-
if(NOT EXISTS ${VT_LIB_PATH})
72-
add_dependencies(voice_text vt_dummy)
73-
endif()
53+
target_link_libraries(voice_text
54+
${catkin_LIBRARIES} -lm -lpthread -ldl
55+
)
7456

7557
install(TARGETS voice_text # do not install vt_dummy target, that should be installed from voice_text library
7658
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
7759
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
7860
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
7961
)
80-
62+
catkin_install_python(PROGRAMS scripts/text2wave.py
63+
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
64+
)
8165
install(PROGRAMS bin/text2wave
8266
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/bin
8367
)

3rdparty/voice_text/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ ROS Interface for HOYA VoiceText Speech Synthesis Engine
55

66
## Installation
77

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

1223
```bash
1324
cd /path/to/catkin_workspace
@@ -55,7 +66,7 @@ Robot says "Hello!"
5566

5667
### Parameters
5768

58-
* `~db_path` (String, default: path found at build time (e.g., `"/var/vt/sayaka/M16"`))
69+
* `~db_path` (String, default: vt path (e.g., `"/var/vt/sayaka/M16"`))
5970

6071
Path to VoiceText database directory.
6172

3rdparty/voice_text/bin/text2wave

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env sh
22

3-
import argparse
4-
import sys
5-
import os
6-
import rospy
7-
from voice_text.srv import *
8-
9-
10-
def text_to_speech_client(text_path, wave_path):
11-
rospy.wait_for_service('/voice_text/text_to_speech')
12-
try:
13-
text_to_speech = rospy.ServiceProxy('/voice_text/text_to_speech', TextToSpeech)
14-
# print("Requesting %s -> %s"%(text_path, wave_path))
15-
res = text_to_speech(text_path, wave_path)
16-
return res.ok
17-
except rospy.ServiceException as e:
18-
print("Service call failed: %s"%e)
19-
20-
21-
if __name__ == '__main__':
22-
parser = argparse.ArgumentParser(description='')
23-
parser.add_argument('-eval', '--evaluate')
24-
parser.add_argument('-o', '--output')
25-
parser.add_argument('text')
26-
args = parser.parse_args()
27-
28-
input_file = args.text
29-
jptext_file = "/tmp/_voice_text_%s.txt"%os.getpid()
30-
output_file = "/tmp/_voice_text_%s.wav"%os.getpid()
31-
if args.output is not None:
32-
output_file = args.output
33-
34-
if not os.path.exists(input_file):
35-
rospy.logerr("%s not found"%input_file)
36-
sys.exit(1)
37-
38-
# convert character code to shift JIS
39-
os.system("nkf -s %s > %s"%(input_file, jptext_file))
40-
41-
text_to_speech_client(jptext_file, output_file)
42-
43-
os.remove(jptext_file)
3+
exec rosrun voice_text text2wave.py $@

0 commit comments

Comments
 (0)