diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccelerationMode.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccelerationMode.java new file mode 100644 index 000000000..836d32eab --- /dev/null +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccelerationMode.java @@ -0,0 +1,11 @@ +package jp.hiroshiba.voicevoxcore; + +/** ハードウェアアクセラレーションモード。 */ +public enum AccelerationMode { + /** 実行環境に合わせて自動的に選択する。 */ + AUTO, + /** CPUに設定する。 */ + CPU, + /** GPUに設定する。 */ + GPU, +} 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 c03accf2f..2f50c7235 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 @@ -58,7 +58,8 @@ public class AudioQuery { /** * [読み取り専用] AquesTalk風記法。 * - *

{@link Synthesizer#createAudioQuery} が返すもののみ String となる。入力としてのAudioQueryでは無視される。 + *

{@link jp.hiroshiba.voicevoxcore.blocking.Synthesizer#createAudioQuery} が返すもののみ String + * となる。入力としてのAudioQueryでは無視される。 */ @SerializedName("kana") @Expose diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/GlobalInfo.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/GlobalInfo.java index 496c2ccc4..e8214a480 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/GlobalInfo.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/GlobalInfo.java @@ -3,9 +3,14 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import jakarta.annotation.Nonnull; +import jp.hiroshiba.voicevoxcore.internal.Dll; /** VOICEVOX CORE自体の情報。 */ -public class GlobalInfo extends Dll { +public class GlobalInfo { + static { + Dll.loadLibrary(); + } + /** * ライブラリのバージョン。 * @@ -19,6 +24,7 @@ public static String getVersion() { @Nonnull private static native String rsGetVersion(); + // FIXME: dead code @Nonnull private static native String rsGetSupportedDevicesJson(); diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/SpeakerMeta.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/SpeakerMeta.java new file mode 100644 index 000000000..c43d32a8e --- /dev/null +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/SpeakerMeta.java @@ -0,0 +1,53 @@ +package jp.hiroshiba.voicevoxcore; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; + +/** 話者(speaker)のメタ情報。 */ +public class SpeakerMeta { + /** 話者名。 */ + @SerializedName("name") + @Expose + @Nonnull + public final String name; + + /** 話者に属するスタイル。 */ + @SerializedName("styles") + @Expose + @Nonnull + public final StyleMeta[] styles; + + /** 話者のUUID。 */ + @SerializedName("speaker_uuid") + @Expose + @Nonnull + public final String speakerUuid; + + /** 話者のバージョン。 */ + @SerializedName("version") + @Expose + @Nonnull + public final String version; + + /** + * 話者の順番。 + * + *

{@code SpeakerMeta}の列は、この値に対して昇順に並んでいるべきである。 + */ + @SerializedName("order") + @Expose + @Nullable + public final Integer order; + + private SpeakerMeta() { + // GSONからコンストラクトするため、このメソッドは呼ばれることは無い。 + // このメソッドは@Nonnullを満たすために必要。 + this.name = ""; + this.styles = new StyleMeta[0]; + this.speakerUuid = ""; + this.version = ""; + this.order = null; + } +} diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/StyleMeta.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/StyleMeta.java new file mode 100644 index 000000000..fc63530a4 --- /dev/null +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/StyleMeta.java @@ -0,0 +1,43 @@ +package jp.hiroshiba.voicevoxcore; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; + +/** スタイル(style)のメタ情報。 */ +public class StyleMeta { + /** スタイル名。 */ + @SerializedName("name") + @Expose + @Nonnull + public final String name; + + /** スタイルID。 */ + @SerializedName("id") + @Expose + public final int id; + + /** スタイルに対応するモデルの種類。 */ + @SerializedName("type") + @Expose + @Nonnull + public final StyleType type; + + /** + * 話者の順番。 + * + *

{@link SpeakerMeta#styles}の列は、この値に対して昇順に並んでいるべきである。 + */ + @SerializedName("order") + @Expose + @Nullable + public final Integer order; + + private StyleMeta() { + this.name = ""; + this.id = 0; + this.type = StyleType.TALK; + this.order = null; + } +} diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/StyleType.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/StyleType.java new file mode 100644 index 000000000..1e7c52d47 --- /dev/null +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/StyleType.java @@ -0,0 +1,12 @@ +package jp.hiroshiba.voicevoxcore; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** スタイル(style)に対応するモデルの種類。 */ +public enum StyleType { + /** 音声合成クエリの作成と音声合成が可能。 */ + @SerializedName("talk") + @Expose + TALK, +} diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDictWord.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDictWord.java new file mode 100644 index 000000000..8b1e93457 --- /dev/null +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDictWord.java @@ -0,0 +1,143 @@ +package jp.hiroshiba.voicevoxcore; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; +import jakarta.annotation.Nonnull; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; + +/** ユーザー辞書の単語。 */ +public class UserDictWord { + /** 単語の表層形。 */ + @SerializedName("surface") + @Expose + @Nonnull + public String surface; + + /** 単語の発音。 発音として有効なカタカナである必要がある。 */ + @SerializedName("pronunciation") + @Expose + @Nonnull + public String pronunciation; + + /** + * 単語の種類。 + * + * @see Type + */ + @SerializedName("word_type") + @Expose + @Nonnull + public Type wordType; + + /** アクセント型。 音が下がる場所を指す。 */ + @SerializedName("accent_type") + @Expose + public int accentType; + + /** 単語の優先度。 0から10までの整数。 数字が大きいほど優先度が高くなる。 1から9までの値を指定することを推奨。 */ + @SerializedName("priority") + @Expose + @Min(0) + @Max(10) + public int priority; + + /** + * {@link UserDictWord}を作成する。 + * + * @param surface 言葉の表層形。 + * @param pronunciation 言葉の発音。 + * @throws IllegalArgumentException pronunciationが不正な場合。 + */ + public UserDictWord(String surface, String pronunciation) { + if (surface == null) { + throw new NullPointerException("surface"); + } + if (pronunciation == null) { + throw new NullPointerException("pronunciation"); + } + + this.surface = rsToZenkaku(surface); + rsValidatePronunciation(pronunciation); + this.pronunciation = pronunciation; + this.wordType = Type.COMMON_NOUN; + this.accentType = 0; + this.priority = 5; + } + + /** + * 単語の種類を設定する。 + * + * @param wordType 単語の種類。 + * @return このインスタンス。 + */ + public UserDictWord wordType(Type wordType) { + if (wordType == null) { + throw new NullPointerException("wordType"); + } + this.wordType = wordType; + return this; + } + + /** + * アクセント型を設定する。 + * + * @param accentType アクセント型。 + * @return このインスタンス。 + */ + public UserDictWord accentType(int accentType) { + if (accentType < 0) { + throw new IllegalArgumentException("accentType"); + } + this.accentType = accentType; + return this; + } + + /** + * 優先度を設定する。 + * + * @param priority 優先度。 + * @return このインスタンス。 + * @throws IllegalArgumentException priorityが0未満または10より大きい場合。 + */ + public UserDictWord priority(int priority) { + if (priority < 0 || priority > 10) { + throw new IllegalArgumentException("priority"); + } + this.priority = priority; + return this; + } + + @Nonnull + private static native String rsToZenkaku(String surface); + + private static native void rsValidatePronunciation(String pronunciation); + + /** 単語の種類。 */ + public static enum Type { + /** 固有名詞。 */ + @SerializedName("PROPER_NOUN") + @Expose + PROPER_NOUN, + + /** 一般名詞。 */ + @SerializedName("COMMON_NOUN") + @Expose + COMMON_NOUN, + + /** 動詞。 */ + @SerializedName("VERB") + @Expose + VERB, + + /** 形容詞。 */ + @SerializedName("ADJECTIVE") + @Expose + ADJECTIVE, + + /** 語尾。 */ + @SerializedName("SUFFIX") + @Expose + SUFFIX, + } +} diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoiceModelFile.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoiceModelFile.java deleted file mode 100644 index b2cceca3f..000000000 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoiceModelFile.java +++ /dev/null @@ -1,152 +0,0 @@ -package jp.hiroshiba.voicevoxcore; - -import com.google.gson.Gson; -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; -import jakarta.annotation.Nonnull; -import jakarta.annotation.Nullable; -import java.io.Closeable; -import java.util.UUID; - -/** 音声モデルファイル。 */ -public class VoiceModelFile extends Dll implements Closeable { - private long handle; - - /** ID。 */ - @Nonnull public final UUID id; - - /** メタ情報。 */ - @Nonnull public final SpeakerMeta[] metas; - - public VoiceModelFile(String modelPath) { - rsOpen(modelPath); - id = rsGetId(); - String metasJson = rsGetMetasJson(); - Gson gson = new Gson(); - SpeakerMeta[] rawMetas = gson.fromJson(metasJson, SpeakerMeta[].class); - if (rawMetas == null) { - throw new RuntimeException("Failed to parse metasJson"); - } - metas = rawMetas; - } - - /** - * VVMファイルを閉じる。 - * - *

このメソッドが呼ばれた段階で{@link Synthesizer#loadVoiceModel}からのアクセスが継続中の場合、アクセスが終わるまで待つ。 - */ - @Override - public void close() { - rsClose(); - } - - @Override - protected void finalize() throws Throwable { - rsDrop(); - super.finalize(); - } - - private native void rsOpen(String modelPath); - - @Nonnull - private native UUID rsGetId(); - - @Nonnull - private native String rsGetMetasJson(); - - private native void rsClose(); - - private native void rsDrop(); - - /** 話者(speaker)のメタ情報。 */ - public static class SpeakerMeta { - /** 話者名。 */ - @SerializedName("name") - @Expose - @Nonnull - public final String name; - - /** 話者に属するスタイル。 */ - @SerializedName("styles") - @Expose - @Nonnull - public final StyleMeta[] styles; - - /** 話者のUUID。 */ - @SerializedName("speaker_uuid") - @Expose - @Nonnull - public final String speakerUuid; - - /** 話者のバージョン。 */ - @SerializedName("version") - @Expose - @Nonnull - public final String version; - - /** - * 話者の順番。 - * - *

{@code SpeakerMeta}の列は、この値に対して昇順に並んでいるべきである。 - */ - @SerializedName("order") - @Expose - @Nullable - public final Integer order; - - private SpeakerMeta() { - // GSONからコンストラクトするため、このメソッドは呼ばれることは無い。 - // このメソッドは@Nonnullを満たすために必要。 - this.name = ""; - this.styles = new StyleMeta[0]; - this.speakerUuid = ""; - this.version = ""; - this.order = null; - } - } - - /** スタイル(style)のメタ情報。 */ - public static class StyleMeta { - /** スタイル名。 */ - @SerializedName("name") - @Expose - @Nonnull - public final String name; - - /** スタイルID。 */ - @SerializedName("id") - @Expose - public final int id; - - /** スタイルに対応するモデルの種類。 */ - @SerializedName("type") - @Expose - @Nonnull - public final StyleType type; - - /** - * 話者の順番。 - * - *

{@link SpeakerMeta#styles}の列は、この値に対して昇順に並んでいるべきである。 - */ - @SerializedName("order") - @Expose - @Nullable - public final Integer order; - - private StyleMeta() { - this.name = ""; - this.id = 0; - this.type = StyleType.TALK; - this.order = null; - } - } - - /** スタイル(style)に対応するモデルの種類。 */ - public static enum StyleType { - /** 音声合成クエリの作成と音声合成が可能。 */ - @SerializedName("talk") - @Expose - TALK, - } -} diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Onnxruntime.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Onnxruntime.java similarity index 96% rename from crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Onnxruntime.java rename to crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Onnxruntime.java index 9a9cbe133..5dc0430c9 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Onnxruntime.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Onnxruntime.java @@ -1,4 +1,4 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; import static jp.hiroshiba.voicevoxcore.GlobalInfo.SupportedDevices; @@ -6,6 +6,7 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.util.Optional; +import jp.hiroshiba.voicevoxcore.internal.Dll; /** * ONNX Runtime。 @@ -18,7 +19,11 @@ * assert ort1 == ort2; * */ -public class Onnxruntime extends Dll { +public class Onnxruntime { + static { + Dll.loadLibrary(); + } + /** ONNX Runtimeのライブラリ名。 */ public static final String LIB_NAME = "onnxruntime"; 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/blocking/OpenJtalk.java similarity index 87% rename from crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/OpenJtalk.java rename to crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/OpenJtalk.java index 11cb3c587..24f96eb42 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/blocking/OpenJtalk.java @@ -1,7 +1,13 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; + +import jp.hiroshiba.voicevoxcore.internal.Dll; /** テキスト解析機としてのOpen JTalk。 */ -public class OpenJtalk extends Dll { +public class OpenJtalk { + static { + Dll.loadLibrary(); + } + private long handle; /** 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/blocking/Synthesizer.java similarity index 97% rename from crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Synthesizer.java rename to crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Synthesizer.java index c59f8ca1e..4b59529ee 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/blocking/Synthesizer.java @@ -1,4 +1,4 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; import com.google.gson.Gson; import jakarta.annotation.Nonnull; @@ -7,15 +7,24 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import jp.hiroshiba.voicevoxcore.AccelerationMode; +import jp.hiroshiba.voicevoxcore.AccentPhrase; +import jp.hiroshiba.voicevoxcore.AudioQuery; +import jp.hiroshiba.voicevoxcore.SpeakerMeta; import jp.hiroshiba.voicevoxcore.exceptions.InvalidModelDataException; import jp.hiroshiba.voicevoxcore.exceptions.RunModelException; +import jp.hiroshiba.voicevoxcore.internal.Dll; /** * 音声シンセサイザ。 * * @see Synthesizer#builder */ -public class Synthesizer extends Dll { +public class Synthesizer { + static { + Dll.loadLibrary(); + } + private long handle; private Synthesizer(Onnxruntime onnxruntime, OpenJtalk openJtalk, Builder builder) { @@ -54,11 +63,10 @@ public boolean isGpuMode() { * @return メタ情報。 */ @Nonnull - public VoiceModelFile.SpeakerMeta[] metas() { + public SpeakerMeta[] metas() { Gson gson = new Gson(); String metasJson = rsGetMetasJson(); - VoiceModelFile.SpeakerMeta[] rawMetas = - gson.fromJson(metasJson, VoiceModelFile.SpeakerMeta[].class); + SpeakerMeta[] rawMetas = gson.fromJson(metasJson, SpeakerMeta[].class); if (rawMetas == null) { throw new NullPointerException("metas"); } @@ -389,16 +397,6 @@ public Synthesizer build() { } } - /** ハードウェアアクセラレーションモード。 */ - public static enum AccelerationMode { - /** 実行環境に合わせて自動的に選択する。 */ - AUTO, - /** CPUに設定する。 */ - CPU, - /** GPUに設定する。 */ - GPU, - } - /** {@link Synthesizer#synthesis} のオプション。 */ public class SynthesisConfigurator { private Synthesizer synthesizer; 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/blocking/UserDict.java similarity index 51% rename from crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/UserDict.java rename to crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/UserDict.java index 7135365ff..e9819959a 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/blocking/UserDict.java @@ -1,20 +1,22 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; import com.google.gson.Gson; -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.io.File; import java.nio.file.Path; import java.util.HashMap; +import jp.hiroshiba.voicevoxcore.UserDictWord; import jp.hiroshiba.voicevoxcore.exceptions.LoadUserDictException; import jp.hiroshiba.voicevoxcore.exceptions.SaveUserDictException; +import jp.hiroshiba.voicevoxcore.internal.Dll; /** ユーザー辞書。 */ -public class UserDict extends Dll { +public class UserDict { + static { + Dll.loadLibrary(); + } + private long handle; /** ユーザー辞書を作成する。 */ @@ -34,7 +36,7 @@ protected void finalize() throws Throwable { * @return 追加した単語のUUID。 */ @Nonnull - public String addWord(Word word) { + public String addWord(UserDictWord word) { Gson gson = new Gson(); String wordJson = gson.toJson(word); @@ -47,7 +49,7 @@ public String addWord(Word word) { * @param uuid 更新する単語のUUID。 * @param word 新しい単語のデータ。 */ - public void updateWord(String uuid, Word word) { + public void updateWord(String uuid, UserDictWord word) { Gson gson = new Gson(); String wordJson = gson.toJson(word); @@ -138,7 +140,7 @@ public void save(String path) throws SaveUserDictException { * @return ユーザー辞書の単語。 */ @Nonnull - public HashMap toHashMap() { + public HashMap toHashMap() { String json = rsGetWords(); Gson gson = new Gson(); @SuppressWarnings("unchecked") @@ -146,10 +148,10 @@ public HashMap toHashMap() { if (rawWords == null) { throw new NullPointerException("words"); } - HashMap words = new HashMap<>(); + HashMap words = new HashMap<>(); rawWords.forEach( (uuid, rawWord) -> { - Word word = gson.fromJson(gson.toJson(rawWord), Word.class); + UserDictWord word = gson.fromJson(gson.toJson(rawWord), UserDictWord.class); if (word == null) { throw new NullPointerException("word"); } @@ -178,140 +180,4 @@ public HashMap toHashMap() { private native String rsGetWords(); private native void rsDrop(); - - @Nonnull - private static native String rsToZenkaku(String surface); - - private static native void rsValidatePronunciation(String pronunciation); - - /** ユーザー辞書の単語。 */ - public static class Word { - /** 単語の表層形。 */ - @SerializedName("surface") - @Expose - @Nonnull - public String surface; - - /** 単語の発音。 発音として有効なカタカナである必要がある。 */ - @SerializedName("pronunciation") - @Expose - @Nonnull - public String pronunciation; - - /** - * 単語の種類。 - * - * @see Type - */ - @SerializedName("word_type") - @Expose - @Nonnull - public Type wordType; - - /** アクセント型。 音が下がる場所を指す。 */ - @SerializedName("accent_type") - @Expose - public int accentType; - - /** 単語の優先度。 0から10までの整数。 数字が大きいほど優先度が高くなる。 1から9までの値を指定することを推奨。 */ - @SerializedName("priority") - @Expose - @Min(0) - @Max(10) - public int priority; - - /** - * UserDict.Wordを作成する。 - * - * @param surface 言葉の表層形。 - * @param pronunciation 言葉の発音。 - * @throws IllegalArgumentException pronunciationが不正な場合。 - */ - public Word(String surface, String pronunciation) { - if (surface == null) { - throw new NullPointerException("surface"); - } - if (pronunciation == null) { - throw new NullPointerException("pronunciation"); - } - - this.surface = rsToZenkaku(surface); - rsValidatePronunciation(pronunciation); - this.pronunciation = pronunciation; - this.wordType = Type.COMMON_NOUN; - this.accentType = 0; - this.priority = 5; - } - - /** - * 単語の種類を設定する。 - * - * @param wordType 単語の種類。 - * @return このインスタンス。 - */ - public Word wordType(Type wordType) { - if (wordType == null) { - throw new NullPointerException("wordType"); - } - this.wordType = wordType; - return this; - } - - /** - * アクセント型を設定する。 - * - * @param accentType アクセント型。 - * @return このインスタンス。 - */ - public Word accentType(int accentType) { - if (accentType < 0) { - throw new IllegalArgumentException("accentType"); - } - this.accentType = accentType; - return this; - } - - /** - * 優先度を設定する。 - * - * @param priority 優先度。 - * @return このインスタンス。 - * @throws IllegalArgumentException priorityが0未満または10より大きい場合。 - */ - public Word priority(int priority) { - if (priority < 0 || priority > 10) { - throw new IllegalArgumentException("priority"); - } - this.priority = priority; - return this; - } - - /** 単語の種類。 */ - public static enum Type { - /** 固有名詞。 */ - @SerializedName("PROPER_NOUN") - @Expose - PROPER_NOUN, - - /** 一般名詞。 */ - @SerializedName("COMMON_NOUN") - @Expose - COMMON_NOUN, - - /** 動詞。 */ - @SerializedName("VERB") - @Expose - VERB, - - /** 形容詞。 */ - @SerializedName("ADJECTIVE") - @Expose - ADJECTIVE, - - /** 語尾。 */ - @SerializedName("SUFFIX") - @Expose - SUFFIX, - } - } } diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Utils.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Utils.java similarity index 65% rename from crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Utils.java rename to crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Utils.java index 19b154cbc..803bb3ed4 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Utils.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Utils.java @@ -1,6 +1,9 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; + +// TODO: `IllegalArgumentException`はRustコード内で`throw`する class Utils { + // FIXME: dead code static boolean isU8(int value) { return value >= 0 && value <= 255; } diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelFile.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelFile.java new file mode 100644 index 000000000..4c1c265b2 --- /dev/null +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelFile.java @@ -0,0 +1,63 @@ +package jp.hiroshiba.voicevoxcore.blocking; + +import com.google.gson.Gson; +import jakarta.annotation.Nonnull; +import java.io.Closeable; +import java.util.UUID; +import jp.hiroshiba.voicevoxcore.SpeakerMeta; +import jp.hiroshiba.voicevoxcore.internal.Dll; + +/** 音声モデルファイル。 */ +public class VoiceModelFile implements Closeable { + static { + Dll.loadLibrary(); + } + + private long handle; + + /** ID。 */ + @Nonnull public final UUID id; + + /** メタ情報。 */ + @Nonnull public final SpeakerMeta[] metas; + + public VoiceModelFile(String modelPath) { + rsOpen(modelPath); + id = rsGetId(); + String metasJson = rsGetMetasJson(); + Gson gson = new Gson(); + SpeakerMeta[] rawMetas = gson.fromJson(metasJson, SpeakerMeta[].class); + if (rawMetas == null) { + throw new RuntimeException("Failed to parse metasJson"); + } + metas = rawMetas; + } + + /** + * VVMファイルを閉じる。 + * + *

このメソッドが呼ばれた段階で{@link Synthesizer#loadVoiceModel}からのアクセスが継続中の場合、アクセスが終わるまで待つ。 + */ + @Override + public void close() { + rsClose(); + } + + @Override + protected void finalize() throws Throwable { + rsDrop(); + super.finalize(); + } + + private native void rsOpen(String modelPath); + + @Nonnull + private native UUID rsGetId(); + + @Nonnull + private native String rsGetMetasJson(); + + private native void rsClose(); + + private native void rsDrop(); +} diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Dll.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/internal/Dll.java similarity index 86% rename from crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Dll.java rename to crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/internal/Dll.java index 94ee33a8d..b37e1fcac 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/Dll.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/internal/Dll.java @@ -1,13 +1,21 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.internal; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -/** ライブラリを読み込むためだけのクラス。 */ -abstract class Dll { - static { +/** ライブラリを読み込むためだけ。 */ +public class Dll { + private static boolean loaded = false; + + private Dll() { + throw new UnsupportedOperationException(); + } + + public static synchronized void loadLibrary() { + if (loaded) return; + String runtimeName = System.getProperty("java.runtime.name"); if (runtimeName.equals("Android Runtime")) { // Android ではjniLibsから読み込む。 @@ -58,11 +66,14 @@ abstract class Dll { System.load(dllPath.toAbsolutePath().toString()); } } catch (Exception e) { + // FIXME: `tempDir`の削除 throw new RuntimeException("Failed to load Voicevox Core DLL for " + target, e); } } new LoggerInitializer().initLogger(); + + loaded = true; } static class LoggerInitializer { diff --git a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/TestUtils.java b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/TestUtils.java index f505c327f..d73566b15 100644 --- a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/TestUtils.java +++ b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/TestUtils.java @@ -1,9 +1,12 @@ package jp.hiroshiba.voicevoxcore; import java.io.File; +import jp.hiroshiba.voicevoxcore.blocking.Onnxruntime; +import jp.hiroshiba.voicevoxcore.blocking.OpenJtalk; +import jp.hiroshiba.voicevoxcore.blocking.VoiceModelFile; -class TestUtils { - VoiceModelFile openModel() { +public class TestUtils { + protected VoiceModelFile openModel() { // cwdはvoicevox_core/crates/voicevox_core_java_api/lib String cwd = System.getProperty("user.dir"); File path = new File(cwd + "/../../test_util/data/model/sample.vvm"); @@ -15,7 +18,7 @@ VoiceModelFile openModel() { } } - Onnxruntime loadOnnxruntime() { + protected Onnxruntime loadOnnxruntime() { final String FILENAME = "../../test_util/data/lib/" + Onnxruntime.LIB_VERSIONED_FILENAME; try { @@ -25,7 +28,7 @@ Onnxruntime loadOnnxruntime() { } } - OpenJtalk loadOpenJtalk() { + protected OpenJtalk loadOpenJtalk() { String cwd = System.getProperty("user.dir"); File path = new File(cwd + "/../../test_util/data/open_jtalk_dic_utf_8-1.11"); diff --git a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/MetaTest.java b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/MetaTest.java similarity index 92% rename from crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/MetaTest.java rename to crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/MetaTest.java index ece3a87ff..24230f3a8 100644 --- a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/MetaTest.java +++ b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/MetaTest.java @@ -1,7 +1,7 @@ /* * This Java source file was generated by the Gradle 'init' task. */ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/SynthesizerTest.java b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/SynthesizerTest.java similarity index 92% rename from crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/SynthesizerTest.java rename to crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/SynthesizerTest.java index 4c7d16f56..b137ca382 100644 --- a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/SynthesizerTest.java +++ b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/SynthesizerTest.java @@ -2,12 +2,17 @@ * 音声合成のテスト。 * ttsaudioQuery -> synthesisの順に実行する。 */ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; +import jp.hiroshiba.voicevoxcore.AccelerationMode; +import jp.hiroshiba.voicevoxcore.AccentPhrase; +import jp.hiroshiba.voicevoxcore.AudioQuery; +import jp.hiroshiba.voicevoxcore.Mora; +import jp.hiroshiba.voicevoxcore.TestUtils; import jp.hiroshiba.voicevoxcore.exceptions.InvalidModelDataException; import jp.hiroshiba.voicevoxcore.exceptions.RunModelException; import org.junit.jupiter.api.Test; @@ -23,9 +28,7 @@ void checkIsGpuMode() { Onnxruntime onnxruntime = loadOnnxruntime(); OpenJtalk openJtalk = loadOpenJtalk(); Synthesizer synthesizer = - Synthesizer.builder(onnxruntime, openJtalk) - .accelerationMode(Synthesizer.AccelerationMode.CPU) - .build(); + Synthesizer.builder(onnxruntime, openJtalk).accelerationMode(AccelerationMode.CPU).build(); assertFalse(synthesizer.isGpuMode()); } diff --git a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/UserDictTest.java b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/UserDictTest.java similarity index 80% rename from crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/UserDictTest.java rename to crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/UserDictTest.java index ed9a94e8e..272bdfd86 100644 --- a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/UserDictTest.java +++ b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/UserDictTest.java @@ -1,9 +1,12 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.file.Files; import java.nio.file.Path; +import jp.hiroshiba.voicevoxcore.AudioQuery; +import jp.hiroshiba.voicevoxcore.TestUtils; +import jp.hiroshiba.voicevoxcore.UserDictWord; import jp.hiroshiba.voicevoxcore.exceptions.InvalidModelDataException; import jp.hiroshiba.voicevoxcore.exceptions.LoadUserDictException; import jp.hiroshiba.voicevoxcore.exceptions.RunModelException; @@ -27,7 +30,7 @@ void checkLoad() throws RunModelException, InvalidModelDataException, LoadUserDi "this_word_should_not_exist_in_default_dictionary", synthesizer.metas()[0].styles[0].id); - userDict.addWord(new UserDict.Word("this_word_should_not_exist_in_default_dictionary", "テスト")); + userDict.addWord(new UserDictWord("this_word_should_not_exist_in_default_dictionary", "テスト")); openJtalk.useUserDict(userDict); AudioQuery query2 = synthesizer.createAudioQuery( @@ -41,11 +44,11 @@ void checkLoad() throws RunModelException, InvalidModelDataException, LoadUserDi void checkManipulation() throws Exception { UserDict userDict = new UserDict(); // 単語追加 - String uuid = userDict.addWord(new UserDict.Word("hoge", "ホゲ")); + String uuid = userDict.addWord(new UserDictWord("hoge", "ホゲ")); assertTrue(userDict.toHashMap().get(uuid) != null); // 単語更新 - userDict.updateWord(uuid, new UserDict.Word("hoge", "ホゲホゲ")); + userDict.updateWord(uuid, new UserDictWord("hoge", "ホゲホゲ")); assertTrue(userDict.toHashMap().get(uuid).pronunciation.equals("ホゲホゲ")); // 単語削除 @@ -53,9 +56,9 @@ void checkManipulation() throws Exception { assertTrue(userDict.toHashMap().get(uuid) == null); // 辞書のインポート - userDict.addWord(new UserDict.Word("hoge", "ホゲ")); + userDict.addWord(new UserDictWord("hoge", "ホゲ")); UserDict userDict2 = new UserDict(); - userDict2.addWord(new UserDict.Word("fuga", "フガ")); + userDict2.addWord(new UserDictWord("fuga", "フガ")); userDict.importDict(userDict2); assertTrue(userDict.toHashMap().size() == 2); diff --git a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/VoiceModelTest.java b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelTest.java similarity index 92% rename from crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/VoiceModelTest.java rename to crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelTest.java index 2bdba9c28..ba3c76ffc 100644 --- a/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/VoiceModelTest.java +++ b/crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/blocking/VoiceModelTest.java @@ -1,4 +1,4 @@ -package jp.hiroshiba.voicevoxcore; +package jp.hiroshiba.voicevoxcore.blocking; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -11,6 +11,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.UUID; +import jp.hiroshiba.voicevoxcore.TestUtils; import org.junit.jupiter.api.Test; class VoiceModelTest extends TestUtils { diff --git a/crates/voicevox_core_java_api/src/logger.rs b/crates/voicevox_core_java_api/src/logger.rs index eaa1889b5..e32680ca4 100644 --- a/crates/voicevox_core_java_api/src/logger.rs +++ b/crates/voicevox_core_java_api/src/logger.rs @@ -2,7 +2,7 @@ use jni::{objects::JObject, JNIEnv}; // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -extern "system" fn Java_jp_hiroshiba_voicevoxcore_Dll_00024LoggerInitializer_initLogger( +extern "system" fn Java_jp_hiroshiba_voicevoxcore_internal_Dll_00024LoggerInitializer_initLogger( _: JNIEnv<'_>, _: JObject<'_>, ) { diff --git a/crates/voicevox_core_java_api/src/onnxruntime.rs b/crates/voicevox_core_java_api/src/onnxruntime.rs index becf773b8..78044c750 100644 --- a/crates/voicevox_core_java_api/src/onnxruntime.rs +++ b/crates/voicevox_core_java_api/src/onnxruntime.rs @@ -12,10 +12,10 @@ use crate::common::throw_if_err; // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[duplicate_item( f CONST; - [ Java_jp_hiroshiba_voicevoxcore_Onnxruntime_rsLibName ] [ LIB_NAME ]; - [ Java_jp_hiroshiba_voicevoxcore_Onnxruntime_rsLibVersion ] [ LIB_VERSION ]; - [ Java_jp_hiroshiba_voicevoxcore_Onnxruntime_rsLibVersionedFilename ] [ LIB_VERSIONED_FILENAME ]; - [ Java_jp_hiroshiba_voicevoxcore_Onnxruntime_rsLibUnversionedFilename ] [ LIB_UNVERSIONED_FILENAME ]; + [ Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rsLibName ] [ LIB_NAME ]; + [ Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rsLibVersion ] [ LIB_VERSION ]; + [ Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rsLibVersionedFilename ] [ LIB_VERSIONED_FILENAME ]; + [ Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rsLibUnversionedFilename ] [ LIB_UNVERSIONED_FILENAME ]; )] #[unsafe(no_mangle)] extern "system" fn f(env: JNIEnv<'_>) -> jobject { @@ -27,7 +27,7 @@ extern "system" fn f(env: JNIEnv<'_>) -> jobject { // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Onnxruntime_rsNew<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rsNew<'local>( env: JNIEnv<'local>, this: JObject<'local>, filename: JString<'local>, @@ -44,7 +44,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Onnxruntime_rsNew<'loca // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Onnxruntime_rsSupportedDevices<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rsSupportedDevices< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, ) -> jobject { diff --git a/crates/voicevox_core_java_api/src/open_jtalk.rs b/crates/voicevox_core_java_api/src/open_jtalk.rs index 06201bc8a..f520aef2a 100644 --- a/crates/voicevox_core_java_api/src/open_jtalk.rs +++ b/crates/voicevox_core_java_api/src/open_jtalk.rs @@ -8,7 +8,7 @@ use jni::{ // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_OpenJtalk_rsNew<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_OpenJtalk_rsNew<'local>( env: JNIEnv<'local>, this: JObject<'local>, open_jtalk_dict_dir: JString<'local>, @@ -26,7 +26,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_OpenJtalk_rsNew<'local> // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_OpenJtalk_rsUseUserDict<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_OpenJtalk_rsUseUserDict< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, user_dict: JObject<'local>, @@ -48,7 +50,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_OpenJtalk_rsUseUserDict // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_OpenJtalk_rsDrop<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_OpenJtalk_rsDrop<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) { diff --git a/crates/voicevox_core_java_api/src/synthesizer.rs b/crates/voicevox_core_java_api/src/synthesizer.rs index d1116c05f..3487d3c50 100644 --- a/crates/voicevox_core_java_api/src/synthesizer.rs +++ b/crates/voicevox_core_java_api/src/synthesizer.rs @@ -12,7 +12,7 @@ use std::sync::Arc; // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsNew<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsNew<'local>( env: JNIEnv<'local>, this: JObject<'local>, onnxruntime: JObject<'local>, @@ -26,14 +26,14 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsNew<'loca .get_field( &builder, "accelerationMode", - object_type!("Synthesizer$AccelerationMode"), + object_type!("AccelerationMode"), )? .l()?; if !acceleration_mode.is_null() { - let auto = enum_object!(env, "Synthesizer$AccelerationMode", "AUTO")?; - let cpu = enum_object!(env, "Synthesizer$AccelerationMode", "CPU")?; - let gpu = enum_object!(env, "Synthesizer$AccelerationMode", "GPU")?; + let auto = enum_object!(env, "AccelerationMode", "AUTO")?; + let cpu = enum_object!(env, "AccelerationMode", "CPU")?; + let gpu = enum_object!(env, "AccelerationMode", "GPU")?; options.acceleration_mode = if env.is_same_object(&acceleration_mode, auto)? { voicevox_core::AccelerationMode::Auto } else if env.is_same_object(&acceleration_mode, cpu)? { @@ -67,7 +67,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsNew<'loca // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsIsGpuMode<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsIsGpuMode< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, ) -> jboolean { @@ -85,7 +87,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsIsGpuMode // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsGetMetasJson<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsGetMetasJson< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, ) -> jobject { @@ -106,7 +110,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsGetMetasJ // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsLoadVoiceModel<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsLoadVoiceModel< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, model: JObject<'local>, @@ -128,7 +134,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsLoadVoice // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsUnloadVoiceModel<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsUnloadVoiceModel< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, model_id: JObject<'local>, @@ -150,7 +158,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsUnloadVoi // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsIsLoadedVoiceModel< +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsIsLoadedVoiceModel< 'local, >( env: JNIEnv<'local>, @@ -175,7 +183,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsIsLoadedV // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAudioQueryFromKana< +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsAudioQueryFromKana< 'local, >( env: JNIEnv<'local>, @@ -206,7 +214,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAudioQuer // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAudioQuery<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsAudioQuery< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, text: JString<'local>, @@ -234,7 +244,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAudioQuer // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAccentPhrasesFromKana< +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsAccentPhrasesFromKana< 'local, >( env: JNIEnv<'local>, @@ -265,7 +275,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAccentPhr // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAccentPhrases<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsAccentPhrases< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, text: JString<'local>, @@ -294,7 +306,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsAccentPhr // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsReplaceMoraData<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsReplaceMoraData< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, accent_phrases_json: JString<'local>, @@ -324,7 +338,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsReplaceMo // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsReplacePhonemeLength< +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsReplacePhonemeLength< 'local, >( env: JNIEnv<'local>, @@ -356,7 +370,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsReplacePh // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsReplaceMoraPitch<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsReplaceMoraPitch< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, accent_phrases_json: JString<'local>, @@ -386,7 +402,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsReplaceMo // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsSynthesis<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsSynthesis< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, query_json: JString<'local>, @@ -425,7 +443,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsSynthesis // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsTtsFromKana<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsTtsFromKana< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, kana: JString<'local>, @@ -458,7 +478,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsTtsFromKa // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsTts<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsTts<'local>( env: JNIEnv<'local>, this: JObject<'local>, query_json: JString<'local>, @@ -491,7 +511,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsTts<'loca // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_Synthesizer_rsDrop<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsDrop<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) { diff --git a/crates/voicevox_core_java_api/src/user_dict.rs b/crates/voicevox_core_java_api/src/user_dict.rs index deac5d676..9b02e7b94 100644 --- a/crates/voicevox_core_java_api/src/user_dict.rs +++ b/crates/voicevox_core_java_api/src/user_dict.rs @@ -10,7 +10,7 @@ use jni::{ // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsNew<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsNew<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) { @@ -25,7 +25,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsNew<'local>( // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsAddWord<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsAddWord<'local>( env: JNIEnv<'local>, this: JObject<'local>, word_json: JString<'local>, @@ -50,7 +50,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsAddWord<'loc // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsUpdateWord<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsUpdateWord<'local>( env: JNIEnv<'local>, this: JObject<'local>, uuid: JString<'local>, @@ -77,7 +77,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsUpdateWord<' // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsRemoveWord<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsRemoveWord<'local>( env: JNIEnv<'local>, this: JObject<'local>, uuid: JString<'local>, @@ -98,7 +98,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsRemoveWord<' // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsImportDict<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsImportDict<'local>( env: JNIEnv<'local>, this: JObject<'local>, other_dict: JObject<'local>, @@ -119,7 +119,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsImportDict<' // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsLoad<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsLoad<'local>( env: JNIEnv<'local>, this: JObject<'local>, path: JString<'local>, @@ -140,7 +140,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsLoad<'local> // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsSave<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsSave<'local>( env: JNIEnv<'local>, this: JObject<'local>, path: JString<'local>, @@ -161,7 +161,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsSave<'local> // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsGetWords<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsGetWords<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) -> jobject { @@ -179,7 +179,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsGetWords<'lo // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsDrop<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_UserDict_rsDrop<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) { @@ -191,7 +191,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsDrop<'local> // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsToZenkaku<'local>( +extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDictWord_rsToZenkaku<'local>( env: JNIEnv<'local>, _cls: JClass<'local>, text: JString<'local>, @@ -209,7 +209,7 @@ extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsToZenkaku<'local>( // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsValidatePronunciation<'local>( +extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDictWord_rsValidatePronunciation<'local>( env: JNIEnv<'local>, _cls: JClass<'local>, text: JString<'local>, diff --git a/crates/voicevox_core_java_api/src/voice_model.rs b/crates/voicevox_core_java_api/src/voice_model.rs index 154449d42..d638a6ccc 100644 --- a/crates/voicevox_core_java_api/src/voice_model.rs +++ b/crates/voicevox_core_java_api/src/voice_model.rs @@ -15,7 +15,7 @@ impl HasJavaClassIdent for voicevox_core::blocking::VoiceModelFile { // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsOpen<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_VoiceModelFile_rsOpen<'local>( env: JNIEnv<'local>, this: JObject<'local>, model_path: JString<'local>, @@ -34,7 +34,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsOpen<' // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsGetId<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_VoiceModelFile_rsGetId<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) -> jobject { @@ -52,7 +52,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsGetId< // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsGetMetasJson<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_VoiceModelFile_rsGetMetasJson< + 'local, +>( env: JNIEnv<'local>, this: JObject<'local>, ) -> jobject { @@ -70,7 +72,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsGetMet // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsClose<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_VoiceModelFile_rsClose<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) { @@ -83,7 +85,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsClose< // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModelFile_rsDrop<'local>( +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_VoiceModelFile_rsDrop<'local>( env: JNIEnv<'local>, this: JObject<'local>, ) {