Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python APIとJava APIのエラーを詳細にする #640

Merged
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resolver = "2"
anyhow = "1.0.65"
async_zip = { version = "0.0.11", features = ["full"] }
clap = { version = "4.0.10", features = ["derive"] }
derive_more = "0.99.17"
easy-ext = "1.0.1"
fs-err = { version = "2.9.0", features = ["tokio"] }
futures = "0.3.26"
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async_zip.workspace = true
cfg-if = "1.0.0"
derive-getters.workspace = true
derive-new = "0.5.9"
derive_more = "0.99.17"
derive_more.workspace = true
duplicate = "1.0.0"
easy-ext.workspace = true
fs-err.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/voicevox_core_java_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ directml = ["voicevox_core/directml"]

[dependencies]
android_logger = "0.13.1"
anyhow.workspace = true
chrono = "0.4.26"
derive_more.workspace = true
jni = "0.21.1"
once_cell.workspace = true
serde_json.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid.workspace = true
voicevox_core.workspace = true

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import jp.hiroshiba.voicevoxcore.exceptions.InferenceFailedException;
import jp.hiroshiba.voicevoxcore.exceptions.InvalidModelDataException;

/**
* 音声シンセサイザ。
Expand All @@ -28,7 +30,7 @@ protected void finalize() throws Throwable {
*
* @param voiceModel 読み込むモデル。
*/
public void loadVoiceModel(VoiceModel voiceModel) {
public void loadVoiceModel(VoiceModel voiceModel) throws InvalidModelDataException {
rsLoadVoiceModel(voiceModel);
}

Expand Down Expand Up @@ -59,7 +61,8 @@ public boolean isLoadedVoiceModel(String voiceModelId) {
* @return {@link AudioQuery}。
*/
@Nonnull
public AudioQuery createAudioQueryFromKana(String kana, int styleId) {
public AudioQuery createAudioQueryFromKana(String kana, int styleId)
throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand All @@ -81,7 +84,7 @@ public AudioQuery createAudioQueryFromKana(String kana, int styleId) {
* @return {@link AudioQuery}。
*/
@Nonnull
public AudioQuery createAudioQuery(String text, int styleId) {
public AudioQuery createAudioQuery(String text, int styleId) throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand All @@ -103,7 +106,8 @@ public AudioQuery createAudioQuery(String text, int styleId) {
* @return {@link AccentPhrase} のリスト。
*/
@Nonnull
public List<AccentPhrase> createAccentPhrasesFromKana(String kana, int styleId) {
public List<AccentPhrase> createAccentPhrasesFromKana(String kana, int styleId)
throws InferenceFailedException {
String accentPhrasesJson = rsAccentPhrasesFromKana(kana, styleId);
Gson gson = new Gson();
AccentPhrase[] rawAccentPhrases = gson.fromJson(accentPhrasesJson, AccentPhrase[].class);
Expand All @@ -121,7 +125,8 @@ public List<AccentPhrase> createAccentPhrasesFromKana(String kana, int styleId)
* @return {@link AccentPhrase} のリスト。
*/
@Nonnull
public List<AccentPhrase> createAccentPhrases(String text, int styleId) {
public List<AccentPhrase> createAccentPhrases(String text, int styleId)
throws InferenceFailedException {
String accentPhrasesJson = rsAccentPhrases(text, styleId);
Gson gson = new Gson();
AccentPhrase[] rawAccentPhrases = gson.fromJson(accentPhrasesJson, AccentPhrase[].class);
Expand All @@ -139,7 +144,8 @@ public List<AccentPhrase> createAccentPhrases(String text, int styleId) {
* @return 変更後のアクセント句の配列。
*/
@Nonnull
public List<AccentPhrase> replaceMoraData(List<AccentPhrase> accentPhrases, int styleId) {
public List<AccentPhrase> replaceMoraData(List<AccentPhrase> accentPhrases, int styleId)
throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand All @@ -157,7 +163,8 @@ public List<AccentPhrase> replaceMoraData(List<AccentPhrase> accentPhrases, int
* @return 変更後のアクセント句の配列。
*/
@Nonnull
public List<AccentPhrase> replacePhonemeLength(List<AccentPhrase> accentPhrases, int styleId) {
public List<AccentPhrase> replacePhonemeLength(List<AccentPhrase> accentPhrases, int styleId)
throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand All @@ -175,7 +182,8 @@ public List<AccentPhrase> replacePhonemeLength(List<AccentPhrase> accentPhrases,
* @return 変更後のアクセント句の配列。
*/
@Nonnull
public List<AccentPhrase> replaceMoraPitch(List<AccentPhrase> accentPhrases, int styleId) {
public List<AccentPhrase> replaceMoraPitch(List<AccentPhrase> accentPhrases, int styleId)
throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand Down Expand Up @@ -226,42 +234,50 @@ public TtsConfigurator tts(String text, int styleId) {

private native void rsNewWithInitialize(OpenJtalk openJtalk, Builder builder);

private native void rsLoadVoiceModel(VoiceModel voiceModel);
private native void rsLoadVoiceModel(VoiceModel voiceModel) throws InvalidModelDataException;

private native void rsUnloadVoiceModel(String voiceModelId);

private native boolean rsIsLoadedVoiceModel(String voiceModelId);

@Nonnull
private native String rsAudioQueryFromKana(String kana, int styleId);
private native String rsAudioQueryFromKana(String kana, int styleId)
throws InferenceFailedException;

@Nonnull
private native String rsAudioQuery(String text, int styleId);
private native String rsAudioQuery(String text, int styleId) throws InferenceFailedException;

@Nonnull
private native String rsAccentPhrasesFromKana(String kana, int styleId);
private native String rsAccentPhrasesFromKana(String kana, int styleId)
throws InferenceFailedException;

@Nonnull
private native String rsAccentPhrases(String text, int styleId);
private native String rsAccentPhrases(String text, int styleId) throws InferenceFailedException;

@Nonnull
private native String rsReplaceMoraData(String accentPhrasesJson, int styleId, boolean kana);
private native String rsReplaceMoraData(String accentPhrasesJson, int styleId, boolean kana)
throws InferenceFailedException;

@Nonnull
private native String rsReplacePhonemeLength(String accentPhrasesJson, int styleId, boolean kana);
private native String rsReplacePhonemeLength(String accentPhrasesJson, int styleId, boolean kana)
throws InferenceFailedException;

@Nonnull
private native String rsReplaceMoraPitch(String accentPhrasesJson, int styleId, boolean kana);
private native String rsReplaceMoraPitch(String accentPhrasesJson, int styleId, boolean kana)
throws InferenceFailedException;

@Nonnull
private native byte[] rsSynthesis(
String queryJson, int styleId, boolean enableInterrogativeUpspeak);
String queryJson, int styleId, boolean enableInterrogativeUpspeak)
throws InferenceFailedException;

@Nonnull
private native byte[] rsTtsFromKana(String kana, int styleId, boolean enableInterrogativeUpspeak);
private native byte[] rsTtsFromKana(String kana, int styleId, boolean enableInterrogativeUpspeak)
throws InferenceFailedException;

@Nonnull
private native byte[] rsTts(String text, int styleId, boolean enableInterrogativeUpspeak);
private native byte[] rsTts(String text, int styleId, boolean enableInterrogativeUpspeak)
throws InferenceFailedException;

private native void rsDrop();

Expand Down Expand Up @@ -368,7 +384,7 @@ public SynthesisConfigurator interrogativeUpspeak(boolean interrogativeUpspeak)
* @return 音声データ。
*/
@Nonnull
public byte[] execute() {
public byte[] execute() throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand Down Expand Up @@ -412,7 +428,7 @@ public TtsFromKanaConfigurator interrogativeUpspeak(boolean interrogativeUpspeak
* @return 音声データ。
*/
@Nonnull
public byte[] execute() {
public byte[] execute() throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand Down Expand Up @@ -454,7 +470,7 @@ public TtsConfigurator interrogativeUpspeak(boolean interrogativeUpspeak) {
* @return 音声データ。
*/
@Nonnull
public byte[] execute() {
public byte[] execute() throws InferenceFailedException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import java.util.HashMap;
import jp.hiroshiba.voicevoxcore.exceptions.LoadUserDictException;
import jp.hiroshiba.voicevoxcore.exceptions.SaveUserDictException;

/** ユーザー辞書。 */
public class UserDict extends Dll {
Expand Down Expand Up @@ -73,7 +75,7 @@ public void importDict(UserDict dict) {
*
* @param path ユーザー辞書のパス。
*/
public void load(String path) {
public void load(String path) throws LoadUserDictException {
rsLoad(path);
}

Expand All @@ -82,7 +84,7 @@ public void load(String path) {
*
* @param path ユーザー辞書のパス。
*/
public void save(String path) {
public void save(String path) throws SaveUserDictException {
rsSave(path);
}

Expand Down Expand Up @@ -124,9 +126,9 @@ public HashMap<String, Word> toHashMap() {

private native void rsImportDict(UserDict dict);

private native void rsLoad(String path);
private native void rsLoad(String path) throws LoadUserDictException;

private native void rsSave(String path);
private native void rsSave(String path) throws SaveUserDictException;

@Nonnull
private native String rsGetWords();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jp.hiroshiba.voicevoxcore.exceptions;

/** コンテキストラベル出力に失敗した。 */
public class ExtractFullContextLabelException extends IllegalArgumentException {
public ExtractFullContextLabelException(String message) {
super(message);
}

public ExtractFullContextLabelException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package jp.hiroshiba.voicevoxcore.exceptions;

import java.io.IOException;

/** サポートされているデバイス情報取得に失敗した。 */
public class GetSupportedDevicesException extends IOException {
public GetSupportedDevicesException(String message) {
super(message);
}

public GetSupportedDevicesException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jp.hiroshiba.voicevoxcore.exceptions;

/** GPUモードがサポートされていない。 */
public class GpuSupportException extends RuntimeException {
public GpuSupportException(String message) {
super(message);
}

public GpuSupportException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package jp.hiroshiba.voicevoxcore.exceptions;

import java.io.IOException;

/** 推論に失敗した。 */
public class InferenceFailedException extends IOException {
public InferenceFailedException(String message) {
super(message);
}

public InferenceFailedException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package jp.hiroshiba.voicevoxcore.exceptions;

import java.io.IOException;

/** 無効なモデルデータ。 */
public class InvalidModelDataException extends IOException {
public InvalidModelDataException(String message) {
super(message);
}

public InvalidModelDataException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jp.hiroshiba.voicevoxcore.exceptions;

/** ユーザー辞書の単語のバリデーションに失敗した。 */
public class InvalidWordException extends IllegalArgumentException {
public InvalidWordException(String message) {
super(message);
}

public InvalidWordException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package jp.hiroshiba.voicevoxcore.exceptions;

import java.io.IOException;

/** ユーザー辞書を読み込めなかった。 */
public class LoadUserDictException extends IOException {
public LoadUserDictException(String message) {
super(message);
}

public LoadUserDictException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jp.hiroshiba.voicevoxcore.exceptions;

/** すでに読み込まれている音声モデルを読み込もうとした。 */
public class ModelAlreadyLoadedException extends IllegalStateException {
public ModelAlreadyLoadedException(String message) {
super(message);
}

public ModelAlreadyLoadedException(String message, Throwable cause) {
super(message, cause);
}
}
Loading
Loading