From 9e87842ec3fdfbc428c56ee6ddc9d30af4c3e125 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 22 Oct 2023 11:47:12 +0900 Subject: [PATCH] =?UTF-8?q?`IOException`=E3=82=92=E7=B6=99=E6=89=BF?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=82=E3=81=AE=E3=81=AF`throws`=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hiroshiba/voicevoxcore/Synthesizer.java | 60 ++++++++++++------- .../jp/hiroshiba/voicevoxcore/UserDict.java | 10 ++-- .../voicevoxcore/SynthesizerTest.java | 10 ++-- .../hiroshiba/voicevoxcore/UserDictTest.java | 6 +- 4 files changed, 55 insertions(+), 31 deletions(-) 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 5f3df9ea8..7204dbdd6 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 @@ -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; /** * 音声シンセサイザ。 @@ -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); } @@ -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"); } @@ -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"); } @@ -103,7 +106,8 @@ public AudioQuery createAudioQuery(String text, int styleId) { * @return {@link AccentPhrase} のリスト。 */ @Nonnull - public List createAccentPhrasesFromKana(String kana, int styleId) { + public List createAccentPhrasesFromKana(String kana, int styleId) + throws InferenceFailedException { String accentPhrasesJson = rsAccentPhrasesFromKana(kana, styleId); Gson gson = new Gson(); AccentPhrase[] rawAccentPhrases = gson.fromJson(accentPhrasesJson, AccentPhrase[].class); @@ -121,7 +125,8 @@ public List createAccentPhrasesFromKana(String kana, int styleId) * @return {@link AccentPhrase} のリスト。 */ @Nonnull - public List createAccentPhrases(String text, int styleId) { + public List createAccentPhrases(String text, int styleId) + throws InferenceFailedException { String accentPhrasesJson = rsAccentPhrases(text, styleId); Gson gson = new Gson(); AccentPhrase[] rawAccentPhrases = gson.fromJson(accentPhrasesJson, AccentPhrase[].class); @@ -139,7 +144,8 @@ public List createAccentPhrases(String text, int styleId) { * @return 変更後のアクセント句の配列。 */ @Nonnull - public List replaceMoraData(List accentPhrases, int styleId) { + public List replaceMoraData(List accentPhrases, int styleId) + throws InferenceFailedException { if (!Utils.isU32(styleId)) { throw new IllegalArgumentException("styleId"); } @@ -157,7 +163,8 @@ public List replaceMoraData(List accentPhrases, int * @return 変更後のアクセント句の配列。 */ @Nonnull - public List replacePhonemeLength(List accentPhrases, int styleId) { + public List replacePhonemeLength(List accentPhrases, int styleId) + throws InferenceFailedException { if (!Utils.isU32(styleId)) { throw new IllegalArgumentException("styleId"); } @@ -175,7 +182,8 @@ public List replacePhonemeLength(List accentPhrases, * @return 変更後のアクセント句の配列。 */ @Nonnull - public List replaceMoraPitch(List accentPhrases, int styleId) { + public List replaceMoraPitch(List accentPhrases, int styleId) + throws InferenceFailedException { if (!Utils.isU32(styleId)) { throw new IllegalArgumentException("styleId"); } @@ -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(); @@ -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"); } @@ -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"); } @@ -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"); } 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 b0b8921a2..de1e612be 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 @@ -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 { @@ -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); } @@ -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); } @@ -124,9 +126,9 @@ public HashMap 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(); 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/SynthesizerTest.java index f5cdaea66..efa91eed8 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/SynthesizerTest.java @@ -8,6 +8,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; +import jp.hiroshiba.voicevoxcore.exceptions.InferenceFailedException; +import jp.hiroshiba.voicevoxcore.exceptions.InvalidModelDataException; import org.junit.jupiter.api.Test; class SynthesizerTest extends TestUtils { @@ -34,7 +36,7 @@ boolean checkAllMoras( } @Test - void checkModel() { + void checkModel() throws InvalidModelDataException { VoiceModel model = loadModel(); OpenJtalk openJtalk = loadOpenJtalk(); Synthesizer synthesizer = Synthesizer.builder(openJtalk).build(); @@ -45,7 +47,7 @@ void checkModel() { } @Test - void checkAudioQuery() { + void checkAudioQuery() throws InferenceFailedException, InvalidModelDataException { VoiceModel model = loadModel(); OpenJtalk openJtalk = loadOpenJtalk(); Synthesizer synthesizer = Synthesizer.builder(openJtalk).build(); @@ -56,7 +58,7 @@ void checkAudioQuery() { } @Test - void checkAccentPhrases() { + void checkAccentPhrases() throws InferenceFailedException, InvalidModelDataException { VoiceModel model = loadModel(); OpenJtalk openJtalk = loadOpenJtalk(); Synthesizer synthesizer = Synthesizer.builder(openJtalk).build(); @@ -86,7 +88,7 @@ void checkAccentPhrases() { } @Test - void checkTts() { + void checkTts() throws InferenceFailedException, InvalidModelDataException { VoiceModel model = loadModel(); OpenJtalk openJtalk = loadOpenJtalk(); Synthesizer synthesizer = Synthesizer.builder(openJtalk).build(); 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/UserDictTest.java index 9eb1077f5..ce9b7631a 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/UserDictTest.java @@ -4,6 +4,9 @@ import java.nio.file.Files; import java.nio.file.Path; +import jp.hiroshiba.voicevoxcore.exceptions.InferenceFailedException; +import jp.hiroshiba.voicevoxcore.exceptions.InvalidModelDataException; +import jp.hiroshiba.voicevoxcore.exceptions.LoadUserDictException; import org.junit.jupiter.api.Test; class UserDictTest extends TestUtils { @@ -11,7 +14,8 @@ class UserDictTest extends TestUtils { // 辞書ロードのテスト。 // 辞書ロード前後でkanaが異なることを確認する @Test - void checkLoad() { + void checkLoad() + throws InferenceFailedException, InvalidModelDataException, LoadUserDictException { VoiceModel model = loadModel(); OpenJtalk openJtalk = loadOpenJtalk(); Synthesizer synthesizer = Synthesizer.builder(openJtalk).build();