Skip to content

Commit

Permalink
IOExceptionを継承するものはthrowsにする
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Oct 22, 2023
1 parent 5c5e04a commit 9e87842
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

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 {

// 辞書ロードのテスト。
// 辞書ロード前後でkanaが異なることを確認する
@Test
void checkLoad() {
void checkLoad()
throws InferenceFailedException, InvalidModelDataException, LoadUserDictException {
VoiceModel model = loadModel();
OpenJtalk openJtalk = loadOpenJtalk();
Synthesizer synthesizer = Synthesizer.builder(openJtalk).build();
Expand Down

0 comments on commit 9e87842

Please sign in to comment.