Skip to content

Commit

Permalink
feat!: [downloader] DownloadTargetごとにディレクトリを切るようにする (#944)
Browse files Browse the repository at this point in the history
おそらくこれからユーザーは`DownloadTarget`について強く意識することになる
ので、それに沿ってディレクトリが作られるようにすることで利便性の向上を試
みる。
  • Loading branch information
qryxip authored Jan 27, 2025
1 parent 142aa42 commit 3ab4a6c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ jobs:
cargo xtask update-c-header --verify
git diff
# TODO: "build-and-test-…"にする
build-unix-cpp-example:
strategy:
fail-fast: false
Expand All @@ -200,11 +201,11 @@ jobs:
run: cargo build -p voicevox_core_c_api --features load-onnxruntime -v
- name: 必要なfileをunix用exampleのディレクトリに移動させる
run: |
mkdir -p example/cpp/unix/voicevox_core/
mkdir -p example/cpp/unix/voicevox_core/c_api
sed 's:^//\(#define VOICEVOX_LOAD_ONNXRUNTIME\)$:\1:' \
crates/voicevox_core_c_api/include/voicevox_core.h \
> example/cpp/unix/voicevox_core/voicevox_core.h
cp -v target/debug/libvoicevox_core.{so,dylib} example/cpp/unix/voicevox_core/ || true
> example/cpp/unix/voicevox_core/c_api/voicevox_core.h
cp -v target/debug/libvoicevox_core.{so,dylib} example/cpp/unix/voicevox_core/c_api/ || true
cp -v target/debug/libonnxruntime.so.* example/cpp/unix/voicevox_core/ || true
cp -v target/debug/libonnxruntime.*.dylib example/cpp/unix/voicevox_core/ || true
Expand All @@ -221,6 +222,7 @@ jobs:
cmake -S . -B build
cmake --build build
# TODO: "build-and-test-…"にする
build-windows-cpp-example:
strategy:
fail-fast: false
Expand Down
23 changes: 8 additions & 15 deletions crates/downloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ async fn main() -> anyhow::Result<()> {
tasks.spawn(download_and_extract_from_gh(
c_api,
Stripping::FirstDir,
&output,
output.join("c_api"),
&progresses,
)?);
}
if let Some(onnxruntime) = onnxruntime {
tasks.spawn(download_and_extract_from_gh(
onnxruntime,
Stripping::FirstDir,
&output.join("onnxruntime"),
output.join("onnxruntime"),
&progresses,
)?);
}
Expand All @@ -388,23 +388,19 @@ async fn main() -> anyhow::Result<()> {
tasks.spawn(download_and_extract_from_gh(
additional_libraries,
Stripping::FirstDir,
&output,
output.join("additional_libraries"),
&progresses,
)?);
}
}
if let Some(models) = models {
tasks.spawn(download_models(
models,
&output.join("models"),
&progresses,
)?);
tasks.spawn(download_models(models, output.join("models"), &progresses)?);
}
if targets.contains(&DownloadTarget::Dict) {
tasks.spawn(download_and_extract_from_url(
&OPEN_JTALK_DIC_URL,
Stripping::None,
&output,
output.join("dict"),
&progresses,
)?);
}
Expand Down Expand Up @@ -704,10 +700,9 @@ fn download_and_extract_from_gh(
..
}: GhAsset,
stripping: Stripping,
output: &Path,
output: PathBuf,
progresses: &MultiProgress,
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>>> {
let output = output.to_owned();
let archive_kind = ArchiveKind::from_filename(&name)?;
let pb = add_progress_bar(progresses, size as _, name);

Expand All @@ -734,10 +729,9 @@ fn download_and_extract_from_gh(
fn download_and_extract_from_url(
url: &'static Url,
stripping: Stripping,
output: &Path,
output: PathBuf,
progresses: &MultiProgress,
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>>> {
let output = output.to_owned();
let name = url
.path_segments()
.and_then(|s| s.last())
Expand Down Expand Up @@ -769,10 +763,9 @@ fn download_models(
models,
..
}: ModelsWithTerms,
output: &Path,
output: PathBuf,
progresses: &MultiProgress,
) -> anyhow::Result<impl Future<Output = anyhow::Result<()>>> {
let output = output.to_owned();
let reqwest = reqwest::Client::builder().build()?;

let models = models
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/user/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ from pprint import pprint
from voicevox_core.blocking import Onnxruntime, OpenJtalk, Synthesizer, VoiceModelFile

# 1. Synthesizerの初期化
open_jtalk_dict_dir = "open_jtalk_dic_utf_8-1.11"
open_jtalk_dict_dir = "dict/open_jtalk_dic_utf_8-1.11"
synthesizer = Synthesizer(Onnxruntime.load_once(), OpenJtalk(open_jtalk_dict_dir))

# 2. 音声モデルの読み込み
Expand Down
6 changes: 3 additions & 3 deletions example/cpp/unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ project(SimpleTTS)
add_executable(simple_tts simple_tts.cpp)
set_property(TARGET simple_tts PROPERTY CXX_STANDARD 17)

file(GLOB ONNXRUNTIME_SHARED_LIB ./libonnxruntime.so.* ./libonnxruntime.*.dylib)
target_link_directories(simple_tts PRIVATE ./voicevox_core)
file(GLOB ONNXRUNTIME_SHARED_LIB ./libonnxruntime.so.* ./libonnxruntime.*.dylib) # TODO: なにこれ
target_link_directories(simple_tts PRIVATE ./voicevox_core/c_api/)


file(GLOB CORE_LIB ./voicevox_core/libvoicevox_core.so.* ./voicevox_core/libvoicevox_core.*.dylib)
file(GLOB CORE_LIB ./voicevox_core/c_api/libvoicevox_core.so.* ./voicevox_core/c_api/libvoicevox_core.*.dylib) # TODO: なにこれ
target_link_libraries(simple_tts voicevox_core)
10 changes: 7 additions & 3 deletions example/cpp/unix/simple_tts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <string>

#include "voicevox_core/voicevox_core.h"
#include "voicevox_core/c_api/voicevox_core.h"

#define STYLE_ID 0
#define OUTPUT_WAV_NAME "audio.wav"
Expand All @@ -14,14 +14,18 @@ int main(int argc, char *argv[]) {
return 0;
}

std::string open_jtalk_dict_path("voicevox_core/open_jtalk_dic_utf_8-1.11");
std::string open_jtalk_dict_path(
"voicevox_core/dict/open_jtalk_dic_utf_8-1.11");
std::string text(argv[1]);

std::cout << "coreの初期化中..." << std::endl;

auto initialize_options = voicevox_make_default_initialize_options();
const VoicevoxOnnxruntime* onnxruntime;
auto load_ort_options = voicevox_make_default_load_onnxruntime_options();
std::string ort_filename = "./voicevox_core/onnxruntime/lib/";
ort_filename += voicevox_get_onnxruntime_lib_versioned_filename();
load_ort_options.filename = ort_filename.c_str();
auto result = voicevox_onnxruntime_load_once(load_ort_options, &onnxruntime);
if (result != VOICEVOX_RESULT_OK){
std::cerr << voicevox_error_result_to_message(result) << std::endl;
Expand All @@ -42,7 +46,7 @@ int main(int argc, char *argv[]) {
voicevox_open_jtalk_rc_delete(open_jtalk);

for (auto const& entry :
std::filesystem::directory_iterator{"./voicevox_core/model"}) {
std::filesystem::directory_iterator{"./voicevox_core/models/vvms"}) {
const auto path = entry.path();
if (path.extension() != ".vvm") {
continue;
Expand Down
2 changes: 1 addition & 1 deletion example/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ optional arguments:
python ./run.py ./models/vvms/0.vvm
[INFO] __main__: Loading ONNX Runtime (args.onnxruntime='./onnxruntime/lib/libvoicevox_onnxruntime.so.1.17.3')
[DEBUG] __main__: onnxruntime.supported_devices()=SupportedDevices(cpu=True, cuda=True, dml=False)
[INFO] __main__: Initializing (args.mode=<AccelerationMode.AUTO: 'AUTO'>, args.dict_dir=PosixPath('open_jtalk_dic_utf_8-1.11'))
[INFO] __main__: Initializing (args.mode=<AccelerationMode.AUTO: 'AUTO'>, args.dict_dir=PosixPath('dict/open_jtalk_dic_utf_8-1.11'))
[INFO] voicevox_core.synthesizer: GPUをテストします:
[INFO] voicevox_core.synthesizer: * CUDA (device_id=0): OK
[INFO] voicevox_core.synthesizer: * DirectML (device_id=0): 現在ロードされているONNX Runtimeでは利用できません
Expand Down
2 changes: 1 addition & 1 deletion example/python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def parse_args() -> "Args":
)
argparser.add_argument(
"--dict-dir",
default="./open_jtalk_dic_utf_8-1.11",
default="./dict/open_jtalk_dic_utf_8-1.11",
type=Path,
help="Open JTalkの辞書ディレクトリ",
)
Expand Down

0 comments on commit 3ab4a6c

Please sign in to comment.