From 814d270628b6a4bf68fa009ddfa4e919d12686e4 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 17 Sep 2023 19:20:14 +0900 Subject: [PATCH 1/4] =?UTF-8?q?ANSI=20escape=20sequence=E3=81=AE=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E3=81=AE=E5=88=A4=E6=96=AD=E3=82=92=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B=20(#616)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 52 +++++++++++++++++++++++++++ crates/voicevox_core_c_api/Cargo.toml | 3 ++ crates/voicevox_core_c_api/src/lib.rs | 35 +++++++++++------- 3 files changed, 77 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 871df23ea..4503ec451 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,43 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "anyhow" version = "1.0.65" @@ -712,6 +749,12 @@ dependencies = [ "tracing-error", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "combine" version = "4.6.6" @@ -4107,6 +4150,12 @@ dependencies = [ "serde", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.4.0" @@ -4189,10 +4238,13 @@ dependencies = [ name = "voicevox_core_c_api" version = "0.0.0" dependencies = [ + "anstream", + "anstyle-query", "anyhow", "assert_cmd", "chrono", "clap 4.0.10", + "colorchoice", "cstr", "derive-getters", "duct", diff --git a/crates/voicevox_core_c_api/Cargo.toml b/crates/voicevox_core_c_api/Cargo.toml index 58db5c0ec..ae691c99b 100644 --- a/crates/voicevox_core_c_api/Cargo.toml +++ b/crates/voicevox_core_c_api/Cargo.toml @@ -16,6 +16,9 @@ name = "e2e" directml = ["voicevox_core/directml"] [dependencies] +anstream = { version = "0.5.0", default-features = false, features = ["auto"] } +anstyle-query = "1.0.0" +colorchoice = "1.0.0" cstr = "0.2.11" derive-getters.workspace = true itertools.workspace = true diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 8ca5becc8..4c692b85d 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -13,13 +13,15 @@ use self::drop_check::C_STRING_DROP_CHECKER; use self::helpers::*; use self::result_code::VoicevoxResultCode; use self::slice_owner::U8_SLICE_OWNER; +use anstream::{AutoStream, RawStream}; use chrono::SecondsFormat; +use colorchoice::ColorChoice; use derive_getters::Getters; use once_cell::sync::Lazy; use std::env; use std::ffi::{CStr, CString}; use std::fmt; -use std::io::{self, IsTerminal, Write}; +use std::io; use std::os::raw::c_char; use std::ptr::NonNull; use std::sync::{Arc, Mutex, MutexGuard}; @@ -37,6 +39,23 @@ static RUNTIME: Lazy = Lazy::new(|| { let _ = init_logger(); fn init_logger() -> std::result::Result<(), impl Sized> { + let ansi = { + // anstyle系のクレートを利用して次の2つを行う。 + // + // * ANSI escape codeを出してよいかの判定(環境変数のチェックとisatty) + // * 必要であれば`ENABLE_VIRTUAL_TERMINAL_PROCESSING`の有効化 + + assert_eq!( + ColorChoice::Auto, + ColorChoice::global(), + "`ColorChoice::write_global` should not have been called", + ); + + AutoStream::choice(&out()) != ColorChoice::Never + && anstyle_query::term_supports_ansi_color() + && anstyle_query::windows::enable_ansi_colors().unwrap_or(true) + }; + tracing_subscriber::fmt() .with_env_filter(if env::var_os(EnvFilter::DEFAULT_ENV).is_some() { EnvFilter::from_default_env() @@ -44,7 +63,7 @@ static RUNTIME: Lazy = Lazy::new(|| { "error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into() }) .with_timer(local_time as fn(&mut Writer<'_>) -> _) - .with_ansi(out().is_terminal() && env_allows_ansi()) + .with_ansi(ansi) .with_writer(out) .try_init() } @@ -55,20 +74,10 @@ static RUNTIME: Lazy = Lazy::new(|| { wtr.write_str(&chrono::Local::now().to_rfc3339_opts(SecondsFormat::Micros, false)) } - fn out() -> impl IsTerminal + Write { + fn out() -> impl RawStream { io::stderr() } - fn env_allows_ansi() -> bool { - // https://docs.rs/termcolor/1.2.0/src/termcolor/lib.rs.html#245-291 - // ただしWindowsではPowerShellっぽかったらそのまま許可する。 - // ちゃんとやるなら`ENABLE_VIRTUAL_TERMINAL_PROCESSING`をチェックするなり、そもそも - // fwdansiとかでWin32の色に変換するべきだが、面倒。 - env::var_os("TERM").map_or( - cfg!(windows) && env::var_os("PSModulePath").is_some(), - |term| term != "dumb", - ) && env::var_os("NO_COLOR").is_none() - } Runtime::new().unwrap() }); From 6a662757b8d42fc5d0902364b1d549684b50b5bc Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Mon, 18 Sep 2023 09:33:48 +0900 Subject: [PATCH 2/4] =?UTF-8?q?build=5Fand=5Fdeploy=E3=81=AE=E6=9C=80?= =?UTF-8?q?=E5=BE=8C=E3=81=ABdownload=5Ftest=E3=82=92=E5=AE=9F=E8=A1=8C=20?= =?UTF-8?q?(#609)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build_and_deploy.yml | 22 +++++++++++++++------- .github/workflows/download_test.yml | 9 ++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index cdc2d1c7a..1994a34e0 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -41,10 +41,11 @@ defaults: shell: bash jobs: - build_and_deploy_strategy_matrix: # 実行対象の条件をフィルタリングする + config: # 全 jobs で利用する定数の定義。実行対象の条件をフィルタリングする。 runs-on: ubuntu-latest outputs: includes: ${{ steps.strategy_matrix.outputs.includes }} + deploy: ${{ env.VERSION != '0.0.0' }} steps: - name: declare strategy matrix id: strategy_matrix @@ -181,11 +182,11 @@ jobs: echo "includes=${includes}" >> "$GITHUB_OUTPUT" build_and_deploy: - needs: build_and_deploy_strategy_matrix + needs: config environment: ${{ github.event.inputs.is_production == 'true' && 'production' || '' }} # 製品版のenvironment strategy: matrix: - include: ${{ fromJson(needs.build_and_deploy_strategy_matrix.outputs.includes) }} + include: ${{ fromJson(needs.config.outputs.includes) }} runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 # 製品版ではない場合 @@ -318,7 +319,7 @@ jobs: cd artifact 7z a "../${{ env.ASSET_NAME }}.zip" "${{ env.ASSET_NAME }}" - name: Upload to Release - if: env.VERSION != '0.0.0' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' && !contains(matrix.target, 'ios') + if: needs.config.outputs.deploy == 'true' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' && !contains(matrix.target, 'ios') uses: softprops/action-gh-release@v1 with: prerelease: true @@ -327,7 +328,7 @@ jobs: ${{ env.ASSET_NAME }}.zip target_commitish: ${{ github.sha }} - name: Upload Python whl to Release - if: env.VERSION != '0.0.0' && matrix.whl_local_version + if: needs.config.outputs.deploy == 'true' && matrix.whl_local_version uses: softprops/action-gh-release@v1 with: prerelease: true @@ -338,7 +339,7 @@ jobs: build_xcframework: if: ${{ !(github.event_name != 'release' && github.event_name != 'workflow_dispatch') }} # !env.IS_SIMPLE_TEST と同じ - needs: build_and_deploy + needs: [config, build_and_deploy] runs-on: macos-12 steps: - uses: actions/checkout@v3 @@ -381,7 +382,7 @@ jobs: cd artifact/${{ env.ASSET_NAME }} 7z a "../../${{ env.ASSET_NAME }}.zip" "voicevox_core.xcframework" - name: Upload to Release - if: env.VERSION != '0.0.0' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' + if: needs.config.outputs.deploy == 'true' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' uses: softprops/action-gh-release@v1 with: prerelease: true @@ -389,3 +390,10 @@ jobs: files: |- ${{ env.ASSET_NAME }}.zip target_commitish: ${{ github.sha }} + + download_test: + needs: [config, build_and_deploy] + if: needs.config.outputs.deploy == 'true' + uses: ./.github/workflows/download_test.yml + with: + version: ${{ inputs.version }} diff --git a/.github/workflows/download_test.yml b/.github/workflows/download_test.yml index b7885ba09..af42532b8 100644 --- a/.github/workflows/download_test.yml +++ b/.github/workflows/download_test.yml @@ -1,5 +1,12 @@ name: Download test workflow + on: + workflow_call: + inputs: + version: + description: "テスト対象のコアのバージョン。無指定時はprerelease込みの最新release。" + type: string + required: false push: branches: - main @@ -10,7 +17,7 @@ on: - ".github/workflows/download_test.yml" env: - VERSION: "prerelease-latest" + VERSION: ${{ inputs.version || 'prerelease-latest' }} defaults: run: From 15db87525f07eb99cc7763152cf28644704519be Mon Sep 17 00:00:00 2001 From: Nanashi Date: Tue, 19 Sep 2023 01:08:02 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Java=20API=EF=BC=9AAndroid=E7=89=88?= =?UTF-8?q?=E3=81=AE=E8=A8=AD=E8=A8=88=E3=82=92=E8=89=B2=E3=80=85=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=20(#612)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_java_api/README.md | 10 +++- .../lib/build-android.gradle | 56 +++++++++++++++++++ .../voicevox_core_java_api/lib/build.gradle | 26 +++++---- .../hiroshiba/voicevoxcore/AccentPhrase.java | 4 +- .../jp/hiroshiba/voicevoxcore/AudioQuery.java | 4 +- .../java/jp/hiroshiba/voicevoxcore/Mora.java | 4 +- .../jp/hiroshiba/voicevoxcore/OpenJtalk.java | 9 ++- .../hiroshiba/voicevoxcore/Synthesizer.java | 10 ++-- .../jp/hiroshiba/voicevoxcore/UserDict.java | 9 +-- .../jp/hiroshiba/voicevoxcore/VoiceModel.java | 9 +-- .../lib/src/main/resources/jniLibs/README.md | 5 ++ .../main/resources/jniLibs/arm64-x8a/.gitkeep | 0 .../main/resources/jniLibs/x86_64/.gitkeep | 0 crates/voicevox_core_java_api/settings.gradle | 37 ++++++++++++ 14 files changed, 146 insertions(+), 37 deletions(-) create mode 100644 crates/voicevox_core_java_api/lib/build-android.gradle create mode 100644 crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/README.md delete mode 100644 crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/arm64-x8a/.gitkeep delete mode 100644 crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/x86_64/.gitkeep diff --git a/crates/voicevox_core_java_api/README.md b/crates/voicevox_core_java_api/README.md index d1bc31938..ab5ef5064 100644 --- a/crates/voicevox_core_java_api/README.md +++ b/crates/voicevox_core_java_api/README.md @@ -44,25 +44,31 @@ Java プロジェクトを動かすには、 - `lib/src/main/resources/dll/[target]/libvoicevox_core_java_api.so` を作成する(`libvoicevox_core_java_api.so`はプラットフォームによって異なります、詳細は後述)。 必要があります。 +また、ハードウェアアクセラレーションを有効にする時は`DEVICE`環境変数を`cuda`または`directml`にし、Android 版をビルドする時は`OS`環境変数を`android`にしてください。 ```console ❯ cargo build -❯ LD_LIBRARY_PATH=$(realpath ../../target/debug) ./gradlew build +❯ LD_LIBRARY_PATH=$(realpath ../../target/debug) ./gradlew test # または ❯ cp ../../target/debug/libvoicevox_core_java_api.so lib/src/main/resources/dll/[target]/libvoicevox_core_java_api.so -❯ ./gradlew build +❯ ./gradlew test +❯ DEVICE=cuda ./gradlew test +❯ OS=android ./gradlew test ``` ## ビルド(リリース) `cargo build --release` で Rust 側を、`./gradlew build` で Java 側をビルドできます。 パッケージ化する時は lib/src/main/resources/dll 内に dll をコピーしてください。 +`DEVICE`、`OS`環境変数は開発時と同様です。 ```console ❯ cargo build --release ❯ cp ../../target/release/libvoicevox_core_java_api.so lib/src/main/resources/dll/[target]/libvoicevox_core_java_api.so ❯ ./gradlew build +❯ DEVICE=cuda ./gradlew build +❯ OS=android ./gradlew build ``` ## テスト diff --git a/crates/voicevox_core_java_api/lib/build-android.gradle b/crates/voicevox_core_java_api/lib/build-android.gradle new file mode 100644 index 000000000..f369c663c --- /dev/null +++ b/crates/voicevox_core_java_api/lib/build-android.gradle @@ -0,0 +1,56 @@ +plugins { + id 'com.android.library' version '8.1.1' + id 'org.jetbrains.kotlin.android' version '1.9.10' +} + +version = gradle.ext.version + +repositories { + google() + mavenCentral() +} + +dependencies { + // Use JUnit Jupiter for testing. + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2' + + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // https://mvnrepository.com/artifact/com.google.code.gson/gson + implementation group: 'com.google.code.gson', name: 'gson', version: gradle.ext.gsonVersion + + // https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api + implementation group: 'jakarta.validation', name: 'jakarta.validation-api', version: gradle.ext.jakartaValidationVersion + + // https://mvnrepository.com/artifact/jakarta.annotation/jakarta.annotation-api + implementation group: 'jakarta.annotation', name: 'jakarta.annotation-api', version: gradle.ext.jakartaAnnotationVersion + + implementation group: 'com.microsoft.onnxruntime', name: 'onnxruntime-android', version: gradle.ext.onnxruntimeVersion +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} + +android { + compileSdkVersion 26 + + defaultConfig { + minSdkVersion 26 + targetSdkVersion 26 + } + namespace "jp.hiroshiba.voicevoxcore" + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + sourceSets { + main { + jniLibs.srcDirs = ["./src/main/resources/jniLibs"] + } + } +} diff --git a/crates/voicevox_core_java_api/lib/build.gradle b/crates/voicevox_core_java_api/lib/build.gradle index 3e87cceff..f1eb5b106 100644 --- a/crates/voicevox_core_java_api/lib/build.gradle +++ b/crates/voicevox_core_java_api/lib/build.gradle @@ -11,7 +11,9 @@ plugins { id "com.diffplug.spotless" version "6.20.0" } -version = '0.0.0' +def boolean isGpu = ['cuda', 'directml'].contains(gradle.ext.targetDevice) + +version = gradle.ext.version repositories { // Use Maven Central for resolving dependencies. @@ -24,28 +26,28 @@ dependencies { testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - // This dependency is exported to consumers, that is to say found on their compile classpath. - api 'org.apache.commons:commons-math3:3.6.1' - - // This dependency is used internally, and not exposed to consumers on their own compile classpath. - implementation 'com.google.guava:guava:31.1-jre' - // https://mvnrepository.com/artifact/com.google.code.gson/gson - implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' + implementation group: 'com.google.code.gson', name: 'gson', version: gradle.ext.gsonVersion // https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api - implementation group: 'jakarta.validation', name: 'jakarta.validation-api', version: '3.0.2' + implementation group: 'jakarta.validation', name: 'jakarta.validation-api', version: gradle.ext.jakartaValidationVersion - implementation group: 'com.microsoft.onnxruntime', name: 'onnxruntime', version: '1.14.0' + // https://mvnrepository.com/artifact/jakarta.annotation/jakarta.annotation-api + implementation group: 'jakarta.annotation', name: 'jakarta.annotation-api', version: gradle.ext.jakartaAnnotationVersion + + if (isGpu) { + implementation group: 'com.microsoft.onnxruntime', name: 'onnxruntime_gpu', version: gradle.ext.onnxruntimeVersion + } else { + implementation group: 'com.microsoft.onnxruntime', name: 'onnxruntime', version: gradle.ext.onnxruntimeVersion + } } // Apply a specific Java toolchain to ease working on different environments. java { toolchain { - languageVersion = JavaLanguageVersion.of(11) + languageVersion = JavaLanguageVersion.of(8) } } - tasks.named('test') { // Use JUnit Platform for unit tests. useJUnitPlatform() diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccentPhrase.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccentPhrase.java index 8c64c9d11..61e8b5d28 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccentPhrase.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccentPhrase.java @@ -2,10 +2,10 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; /** AccentPhrase (アクセント句ごとの情報)。 */ public class AccentPhrase { diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AudioQuery.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AudioQuery.java index 4a23be3f7..c03accf2f 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AudioQuery.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AudioQuery.java @@ -2,10 +2,10 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; /** AudioQuery(音声合成用のクエリ)。 */ public class AudioQuery { diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Mora.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Mora.java index 61dbaf233..f03874323 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Mora.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Mora.java @@ -2,8 +2,8 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; /** モーラ(子音+母音)ごとの情報。 */ public class Mora { diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/OpenJtalk.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/OpenJtalk.java index 3228b8d51..c9ad2f963 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/OpenJtalk.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/OpenJtalk.java @@ -1,11 +1,7 @@ package jp.hiroshiba.voicevoxcore; -import java.lang.ref.Cleaner; - -/** テキスト解析器としてのOpen JTalk。 */ public class OpenJtalk extends Dll { private long handle; - private static final Cleaner cleaner = Cleaner.create(); /** * Open JTalkの辞書ディレクトリ。 @@ -14,8 +10,11 @@ public class OpenJtalk extends Dll { */ public OpenJtalk(String openJtalkDictDir) { rsNewWithInitialize(openJtalkDictDir); + } - cleaner.register(this, () -> rsDrop()); + protected void finalize() throws Throwable { + rsDrop(); + super.finalize(); } /** diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Synthesizer.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Synthesizer.java index 98bf9f403..5739b14f7 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Synthesizer.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Synthesizer.java @@ -1,11 +1,10 @@ package jp.hiroshiba.voicevoxcore; import com.google.gson.Gson; -import java.lang.ref.Cleaner; +import jakarta.annotation.Nonnull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.annotation.Nonnull; /** * 音声シンセサイザ。 @@ -14,11 +13,14 @@ */ public class Synthesizer extends Dll { private long handle; - private static final Cleaner cleaner = Cleaner.create(); private Synthesizer(OpenJtalk openJtalk, Builder builder) { rsNewWithInitialize(openJtalk, builder); - cleaner.register(this, () -> rsDrop()); + } + + protected void finalize() throws Throwable { + rsDrop(); + super.finalize(); } /** diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDict.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDict.java index d75924feb..b0b8921a2 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDict.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDict.java @@ -4,22 +4,23 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import com.google.gson.internal.LinkedTreeMap; +import jakarta.annotation.Nonnull; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; -import java.lang.ref.Cleaner; import java.util.HashMap; -import javax.annotation.Nonnull; /** ユーザー辞書。 */ public class UserDict extends Dll { private long handle; - private static final Cleaner cleaner = Cleaner.create(); /** ユーザー辞書を作成する。 */ public UserDict() { rsNew(); + } - cleaner.register(this, () -> rsDrop()); + protected void finalize() throws Throwable { + rsDrop(); + super.finalize(); } /** diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoiceModel.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoiceModel.java index 518f1de31..05c1a11b2 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoiceModel.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoiceModel.java @@ -3,13 +3,11 @@ import com.google.gson.Gson; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -import java.lang.ref.Cleaner; -import javax.annotation.Nonnull; +import jakarta.annotation.Nonnull; /** 音声モデル。 */ public class VoiceModel extends Dll { private long handle; - private static final Cleaner cleaner = Cleaner.create(); /** ID。 */ @Nonnull public final String id; @@ -27,8 +25,11 @@ public VoiceModel(String modelPath) { throw new RuntimeException("Failed to parse metasJson"); } metas = rawMetas; + } - cleaner.register(this, () -> rsDrop()); + protected void finalize() throws Throwable { + rsDrop(); + super.finalize(); } private native void rsFromPath(String modelPath); diff --git a/crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/README.md b/crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/README.md new file mode 100644 index 000000000..9073988ec --- /dev/null +++ b/crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/README.md @@ -0,0 +1,5 @@ +このディレクトリに Android での JNI 用に読み込まれる DLL を配置します。 +ディレクトリ名は以下のうちのいずれかになります。 + +- `arm64-v8a` +- `x86_64` diff --git a/crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/arm64-x8a/.gitkeep b/crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/arm64-x8a/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/x86_64/.gitkeep b/crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/x86_64/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/crates/voicevox_core_java_api/settings.gradle b/crates/voicevox_core_java_api/settings.gradle index 7d07347eb..20a5e2c6a 100644 --- a/crates/voicevox_core_java_api/settings.gradle +++ b/crates/voicevox_core_java_api/settings.gradle @@ -1,7 +1,44 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } + + resolutionStrategy { + eachPlugin { + if(requested.id.namespace == "com.android") { + useModule("com.android.tools.build:gradle:${requested.version}") + } + } + } +} plugins { // Apply the foojay-resolver plugin to allow automatic download of JDKs id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' } rootProject.name = 'jp.hiroshiba.voicevoxcore' +def String targetOs = System.getenv('OS')?.toLowerCase() ?: "desktop" +def boolean isAndroid = targetOs == 'android' include('lib') +if (isAndroid) { + project(':lib').buildFileName = 'build-android.gradle' +} else { + project(':lib').buildFileName = 'build.gradle' +} + +def String cargoToml = file('../../Cargo.toml').text +def String cargoTomlVersion = (cargoToml =~ /(?m)^version = "(\S+)"$/)[0][1] + +gradle.ext { + version = cargoTomlVersion + + targetOs = targetOs + targetDevice = System.getenv('DEVICE') ?: 'cpu' + + gsonVersion = '2.10.1' + jakartaValidationVersion = '3.0.2' + jakartaAnnotationVersion = '2.1.1' + onnxruntimeVersion = '1.14.0' +} From bbb35b4c89f36016a95cd313d103daa9dc97b90e Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Tue, 19 Sep 2023 10:51:27 +0900 Subject: [PATCH 4/4] =?UTF-8?q?download=5Ftest=E3=82=92=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E3=81=AE=E3=82=82=E3=81=AE=E3=81=A7=E9=80=9A=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4=20(#618)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/download_test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/download_test.yml b/.github/workflows/download_test.yml index af42532b8..6e8ff1b6f 100644 --- a/.github/workflows/download_test.yml +++ b/.github/workflows/download_test.yml @@ -35,7 +35,7 @@ jobs: download_dir: voicevox_core check_items: | voicevox_core.dll - model/metas.json + model/README.* open_jtalk_dic_utf_8-1.11 README.txt # https://github.com/VOICEVOX/voicevox_core/pull/411#issuecomment-1412457592 @@ -53,7 +53,7 @@ jobs: download_dir: voicevox_core check_items: | voicevox_core.dll - model/metas.json + model/README.* open_jtalk_dic_utf_8-1.11 README.txt check_not_exists_items: | @@ -70,7 +70,7 @@ jobs: download_dir: other_output check_items: | voicevox_core.dll - model/metas.json + model/README.* open_jtalk_dic_utf_8-1.11 README.txt check_not_exists_items: | @@ -87,7 +87,7 @@ jobs: download_dir: voicevox_core check_items: | voicevox_core.dll - model/metas.json + model/README.* README.txt check_not_exists_items: | *directml* @@ -104,7 +104,7 @@ jobs: download_dir: voicevox_core check_items: | voicevox_core.dll - model/metas.json + model/README.* open_jtalk_dic_utf_8-1.11 README.txt DirectML.dll @@ -123,7 +123,7 @@ jobs: download_dir: voicevox_core check_items: | voicevox_core.dll - model/metas.json + model/README.* README.txt check_not_exists_items: | *cuda* @@ -141,7 +141,7 @@ jobs: download_dir: voicevox_core check_items: | voicevox_core.dll - model/metas.json + model/README.* open_jtalk_dic_utf_8-1.11 README.txt EULA.txt @@ -163,7 +163,7 @@ jobs: download_dir: voicevox_core check_items: | voicevox_core.dll - model/metas.json + model/README.* README.txt check_not_exists_items: | *directml*