Skip to content

Commit

Permalink
voicevox_core 0.15.3に更新
Browse files Browse the repository at this point in the history
  • Loading branch information
eyr1n committed Apr 29, 2024
1 parent 77c0486 commit 5707db9
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 163 deletions.
79 changes: 32 additions & 47 deletions voicevox_core_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,52 @@ find_package(ament_cmake REQUIRED)
option(WITH_CUDA "Use voicevox_core with CUDA" OFF)
option(WITH_DIRECTML "Use voicevox_core with DirectML" OFF)

set(voicevox_core_VERSION 0.14.1)
set(voicevox_core_VERSION 0.15.3)
set(voicevox_additional_libraries_VERSION 0.1.0)

# OS名を変換
set(OS_Linux linux)
set(OS_Windows windows)
set(OS_Darwin osx)
set(OS ${OS_${CMAKE_SYSTEM_NAME}})

# アーキテクチャ名を変換
set(ARCH_x86_64 x64)
set(ARCH_arm64 arm64)
set(ARCH_aarch64 arm64)
set(ARCH ${ARCH_${CMAKE_SYSTEM_PROCESSOR}})

# デバイスの選択
set(DEVICE cpu)
if(WITH_CUDA)
set(DEVICE gpu)
set(voicevox_additional_libraries_URL https://github.com/VOICEVOX/voicevox_additional_libraries/releases/download/${voicevox_additional_libraries_VERSION}/CUDA-${OS}-${ARCH}.zip)
set(DEVICE cuda)
elseif(WITH_DIRECTML)
set(DEVICE directml)
set(voicevox_additional_libraries_URL https://github.com/VOICEVOX/voicevox_additional_libraries/releases/download/${${voicevox_additional_libraries_VERSION}}/DirectML-${OS}-${ARCH}.zip)
endif()

set(voicevox_core_URL https://github.com/VOICEVOX/voicevox_core/releases/download/${voicevox_core_VERSION}/voicevox_core-${OS}-${ARCH}-${DEVICE}-${voicevox_core_VERSION}.zip)
set(open_jtalk_dict_URL https://jaist.dl.sourceforge.net/project/open-jtalk/Dictionary/open_jtalk_dic-1.11/open_jtalk_dic_utf_8-1.11.tar.gz)

# voicevox_core, open_jtalk_dictの取得, インストール
include(FetchContent)
FetchContent_Declare(voicevox_core
URL ${voicevox_core_URL}
)
FetchContent_Declare(open_jtalk_dict
URL ${open_jtalk_dict_URL}
)
FetchContent_MakeAvailable(voicevox_core open_jtalk_dict)

install(
DIRECTORY ${voicevox_core_SOURCE_DIR}/
DESTINATION lib
)
# アーキテクチャ名を変換
set(CPU_ARCH_x86_64 x64)
set(CPU_ARCH_amd64 x64)
set(CPU_ARCH_AMD64 x64)
set(CPU_ARCH_arm64 arm64)
set(CPU_ARCH_aarch64 arm64)
set(CPU_ARCH ${CPU_ARCH_${CMAKE_SYSTEM_PROCESSOR}})

install(
DIRECTORY ${open_jtalk_dict_SOURCE_DIR}/
DESTINATION lib/open_jtalk_dict
)
# OS名を変換
set(OS_Linux linux)
set(OS_Windows windows)
set(OS_Darwin osx)
set(OS ${OS_${CMAKE_SYSTEM_NAME}})

# voicevox_additional_librariesの取得, インストール
if(DEFINED voicevox_additional_libraries_URL)
FetchContent_Declare(voicevox_additional_libraries
URL ${voicevox_additional_libraries_URL}
# voicevox_coreの取得, インストール
if(${OS} STREQUAL "windows")
add_custom_target(voicevox_core ALL
COMMAND curl -sSfL https://github.com/VOICEVOX/voicevox_core/releases/latest/download/download-${OS}-${CPU_ARCH}.exe -o download.exe
COMMAND download.exe --version ${voicevox_core_VERSION} --additional-libraries-version ${voicevox_additional_libraries_VERSION} --device ${DEVICE} --cpu-arch ${CPU_ARCH} --os ${OS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
FetchContent_MakeAvailable(voicevox_additional_libraries)

install(
DIRECTORY ${voicevox_additional_libraries_SOURCE_DIR}/
DESTINATION lib
else()
add_custom_target(voicevox_core ALL
COMMAND curl -sSfL https://github.com/VOICEVOX/voicevox_core/releases/latest/download/download-${OS}-${CPU_ARCH} -o download
COMMAND chmod +x download
COMMAND ./download --version ${voicevox_core_VERSION} --additional-libraries-version ${voicevox_additional_libraries_VERSION} --device ${DEVICE} --cpu-arch ${CPU_ARCH} --os ${OS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif()

install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/voicevox_core/
DESTINATION lib
)

# ヘッダファイル生成
configure_file(
"open_jtalk_dict_dir.h.in"
Expand All @@ -76,7 +61,7 @@ configure_file(

install(
FILES
${voicevox_core_SOURCE_DIR}/voicevox_core.h
${CMAKE_CURRENT_BINARY_DIR}/voicevox_core/voicevox_core.h
${CMAKE_CURRENT_BINARY_DIR}/open_jtalk_dict_dir.h
DESTINATION include/${PROJECT_NAME}/
)
Expand Down
2 changes: 1 addition & 1 deletion voicevox_core_vendor/open_jtalk_dict_dir.h.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define OPEN_JTALK_DICT_DIR "@CMAKE_INSTALL_PREFIX@/lib/open_jtalk_dict"
#define OPEN_JTALK_DICT_DIR "@CMAKE_INSTALL_PREFIX@/lib/open_jtalk_dic_utf_8-1.11"
4 changes: 3 additions & 1 deletion voicevox_core_vendor/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>voicevox_core_vendor</name>
<version>1.1.0</version>
<version>1.2.0</version>
<description>voicevox_core_vendor</description>
<maintainer email="[email protected]">Rin Iwai</maintainer>
<license>Apache License 2.0</license>
<license>MIT</license> <!-- voicevox_core -->

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>curl</build_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down
7 changes: 6 additions & 1 deletion voicevox_ros2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ install(

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
ament_package()
65 changes: 0 additions & 65 deletions voicevox_ros2/include/voicevox_ros2/queue.hpp

This file was deleted.

76 changes: 30 additions & 46 deletions voicevox_ros2/include/voicevox_ros2/voicevox_ros2_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include <string>
#include <vector>

#include <rclcpp/rclcpp.hpp>
Expand All @@ -28,17 +29,9 @@
#include "voicevox_ros2_msgs/msg/talk.hpp"

#include "mixer.hpp"
#include "queue.hpp"

namespace tutrobo {
class VoicevoxRos2 : public rclcpp::Node {
Queue<voicevox_ros2_msgs::msg::Talk, 10> talk_queue_;
std::thread talk_thread_;
rclcpp::Subscription<voicevox_ros2_msgs::msg::Talk>::SharedPtr
voicevox_ros2_sub_;

static inline Mixer mixer;

public:
VoicevoxRos2(const rclcpp::NodeOptions &options)
: VoicevoxRos2("", options) {}
Expand Down Expand Up @@ -79,26 +72,15 @@ class VoicevoxRos2 : public rclcpp::Node {
Mix_OpenAudio(24000, AUDIO_S16LSB, 1, 4096);
Mix_ChannelFinished([](int channel) { mixer.stop(channel); });

// スレッド立ち上げ
talk_thread_ = std::thread{&VoicevoxRos2::voicevox_talk, this};

// サブスクライバ
voicevox_ros2_sub_ =
this->create_subscription<voicevox_ros2_msgs::msg::Talk>(
"voicevox_ros2", rclcpp::QoS(10),
[this](const voicevox_ros2_msgs::msg::Talk::SharedPtr msg) {
if (msg->queuing) {
talk_queue_.push_back(*msg);
} else {
talk_queue_.push_front(*msg);
}
});
std::bind(&VoicevoxRos2::voicevox_ros2_callback, this,
std::placeholders::_1));
}

~VoicevoxRos2() {
talk_queue_.abort();
talk_thread_.join();

// 音声をすべて停止
mixer.stop_all();

Expand All @@ -110,33 +92,35 @@ class VoicevoxRos2 : public rclcpp::Node {
}

private:
void voicevox_talk() {
voicevox_ros2_msgs::msg::Talk msg;

while (this->talk_queue_.pop(msg)) {
if (!voicevox_is_model_loaded(msg.speaker_id)) {
RCLCPP_ERROR(this->get_logger(), "Model id %d is not loaded.",
msg.speaker_id);
continue;
}
rclcpp::Subscription<voicevox_ros2_msgs::msg::Talk>::SharedPtr
voicevox_ros2_sub_;

RCLCPP_INFO(this->get_logger(), "Synthesizing \"%s\"...",
msg.text.c_str());
[[maybe_unused]] size_t wav_size = 0;
uint8_t *wav = nullptr;
VoicevoxResultCode voicevox_result =
voicevox_tts(msg.text.c_str(), msg.speaker_id,
voicevox_make_default_tts_options(), &wav_size, &wav);
if (voicevox_result != VOICEVOX_RESULT_OK) {
RCLCPP_ERROR(this->get_logger(), "%s",
voicevox_error_result_to_message(voicevox_result));
}
static inline Mixer mixer;

if (msg.queuing) {
mixer.enqueue(Mix_QuickLoad_WAV(wav));
} else {
mixer.play(Mix_QuickLoad_WAV(wav));
}
void
voicevox_ros2_callback(const voicevox_ros2_msgs::msg::Talk::SharedPtr msg) {
if (!voicevox_is_model_loaded(msg->speaker_id)) {
RCLCPP_ERROR(this->get_logger(), "Model id %d is not loaded.",
msg->speaker_id);
return;
}

RCLCPP_INFO(this->get_logger(), "Synthesizing \"%s\"...",
msg->text.c_str());
[[maybe_unused]] size_t wav_size = 0;
uint8_t *wav = nullptr;
VoicevoxResultCode voicevox_result =
voicevox_tts(msg->text.c_str(), msg->speaker_id,
voicevox_make_default_tts_options(), &wav_size, &wav);
if (voicevox_result != VOICEVOX_RESULT_OK) {
RCLCPP_ERROR(this->get_logger(), "%s",
voicevox_error_result_to_message(voicevox_result));
}

if (msg->queuing) {
mixer.enqueue(Mix_QuickLoad_WAV(wav));
} else {
mixer.play(Mix_QuickLoad_WAV(wav));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion voicevox_ros2/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>voicevox_ros2</name>
<version>1.1.0</version>
<version>1.2.0</version>
<description>voicevox_ros2</description>
<maintainer email="[email protected]">Rin Iwai</maintainer>
<license>Apache License 2.0</license>
Expand Down
18 changes: 18 additions & 0 deletions voicevox_ros2_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
cmake_minimum_required(VERSION 3.8)
project(voicevox_ros2_msgs)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME} msg/Talk.msg)

ament_export_dependencies(rosidl_default_runtime)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
6 changes: 5 additions & 1 deletion voicevox_ros2_msgs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>voicevox_ros2_msgs</name>
<version>1.0.0</version>
<version>1.1.0</version>
<description>voicevox_ros2_msgs</description>
<maintainer email="[email protected]">Rin Iwai</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down

0 comments on commit 5707db9

Please sign in to comment.