-
Notifications
You must be signed in to change notification settings - Fork 117
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
Improve: Java APIを色々改善 #673
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
300dd30
Add: Java APIのサンプルを追加
sevenc-nanashi b30c011
Add: @throwsを追加
sevenc-nanashi ae66178
Add: Voicevox Core自体の情報を追加
sevenc-nanashi 4c1e3e7
Add: OpenJtalkのドキュメントを追加
sevenc-nanashi d01d996
Fix: ドキュメントのリンク周りを修正
sevenc-nanashi e075f28
Add: Synthesizerにメソッドを追加
sevenc-nanashi 47616aa
Add: .gitattributesを追記
sevenc-nanashi 58e5390
Code: gradle spotlessApply
sevenc-nanashi 98498ec
Delete: コメントを削除
sevenc-nanashi 83fe1dc
Delete: テストを削除
sevenc-nanashi 943e264
Add: READMEを追加
sevenc-nanashi 0d2cb8e
Update: 記述を更新
sevenc-nanashi 4aaa611
Change: #getMetas -> #metas
sevenc-nanashi 46fc3bc
Update: テストを更新
sevenc-nanashi 7265ccf
Change: VoicevoxCoreInfo -> GlobalInfo
sevenc-nanashi 525ef2d
Change: Rust側を信頼するように
sevenc-nanashi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/OpenJtalk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
.../voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/VoicevoxCoreInfo.java
sevenc-nanashi marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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; | ||
|
||
/** VOICEVOX CORE自体の情報。 */ | ||
public class VoicevoxCoreInfo extends Dll { | ||
/** | ||
* ライブラリのバージョン。 | ||
* | ||
* @return ライブラリのバージョン。 | ||
*/ | ||
@Nonnull | ||
public static String getVersion() { | ||
String version = rsGetVersion(); | ||
if (version == null) { | ||
throw new NullPointerException("version"); | ||
} | ||
return version; | ||
sevenc-nanashi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* このライブラリで利用可能なデバイスの情報を取得する。 | ||
* | ||
* @return {@link SupportedDevices}。 | ||
*/ | ||
@Nonnull | ||
public static SupportedDevices getSupportedDevices() { | ||
Gson gson = new Gson(); | ||
String supportedDevicesJson = rsGetSupportedDevicesJson(); | ||
SupportedDevices supportedDevices = gson.fromJson(supportedDevicesJson, SupportedDevices.class); | ||
if (supportedDevices == null) { | ||
throw new NullPointerException("supported_devices"); | ||
} | ||
return supportedDevices; | ||
} | ||
|
||
@Nonnull | ||
private static native String rsGetVersion(); | ||
|
||
@Nonnull | ||
private static native String rsGetSupportedDevicesJson(); | ||
|
||
/** | ||
* このライブラリで利用可能なデバイスの情報。 | ||
* | ||
* <p>あくまで本ライブラリが対応しているデバイスの情報であることに注意。GPUが使える環境ではなかったとしても {@link #cuda} や {@link #dml} は {@code | ||
* true} を示しうる。 | ||
*/ | ||
public static class SupportedDevices { | ||
/** | ||
* CPUが利用可能。 | ||
* | ||
* <p>常に <code>true</code> 。 | ||
*/ | ||
@SerializedName("cpu") | ||
@Expose | ||
@Nonnull | ||
public final boolean cpu; | ||
|
||
/** | ||
* CUDAが利用可能。 | ||
* | ||
* <p>ONNX Runtimeの <a href= | ||
* "https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html" | ||
* target="_blank">CUDAExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。 | ||
*/ | ||
@SerializedName("cuda") | ||
@Expose | ||
@Nonnull | ||
public final boolean cuda; | ||
|
||
/** | ||
* DirectMLが利用可能。 | ||
* | ||
* <p>ONNX Runtimeの <a href= | ||
* "https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html" | ||
* target="_blank">DmlExecutionProvider</a>に対応する。 必要な環境についてはそちらを参照。 | ||
*/ | ||
@SerializedName("dml") | ||
@Expose | ||
@Nonnull | ||
public final boolean dml; | ||
|
||
private SupportedDevices() { | ||
this.cpu = false; | ||
this.cuda = false; | ||
this.dml = false; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
crates/voicevox_core_java_api/lib/src/test/java/jp/hiroshiba/voicevoxcore/InfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* VoicevoxCoreInfoのテスト。 | ||
*/ | ||
package jp.hiroshiba.voicevoxcore; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class InfoTest { | ||
@Test | ||
void checkVersion() { | ||
assertNotNull(VoicevoxCoreInfo.getVersion()); | ||
} | ||
|
||
@Test | ||
void checkSupportedDevices() { | ||
VoicevoxCoreInfo.SupportedDevices supportedDevices = VoicevoxCoreInfo.getSupportedDevices(); | ||
|
||
assertNotNull(supportedDevices); | ||
assertTrue(supportedDevices.cpu); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::common::throw_if_err; | ||
use jni::{sys::jobject, JNIEnv}; | ||
#[no_mangle] | ||
extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoicevoxCoreInfo_rsGetVersion( | ||
env: JNIEnv<'_>, | ||
) -> jobject { | ||
throw_if_err(env, std::ptr::null_mut(), |env| { | ||
let version = env.new_string(env!("CARGO_PKG_VERSION"))?; | ||
Ok(version.into_raw()) | ||
}) | ||
} | ||
#[no_mangle] | ||
extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoicevoxCoreInfo_rsGetSupportedDevicesJson( | ||
env: JNIEnv<'_>, | ||
) -> jobject { | ||
throw_if_err(env, std::ptr::null_mut(), |env| { | ||
let supported_devices = voicevox_core::SupportedDevices::create()?; | ||
let json = serde_json::to_string(&supported_devices).expect("Should not fail"); | ||
let json = env.new_string(json)?; | ||
Ok(json.into_raw()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod common; | ||
mod info; | ||
mod open_jtalk; | ||
mod synthesizer; | ||
mod user_dict; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# Linux start script should use lf | ||
./gradlew text eol=lf linguist-vendored linguist-generated | ||
|
||
# These are Windows script files and should use crlf | ||
*.bat text eol=crlf | ||
|
||
./gradlew linguist-vendored linguist-generated | ||
./gradlew.bat linguist-vendored linguist-generated | ||
./gradle/wrapper/gradle-wrapper.jar linguist-vendored linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build | ||
output.wav |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
気になったので質問です!
これがJavaAPIのメソッドになる感じなんでしたっけ。
Rustは
.metas
、pythonもmetas
なのですが、JavaはgetMetas
になってるかも? 👀(言語仕様に詳しくないので、その方が望ましいのかがわからず。。)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javaでは
getMetas
という名前は、「metas
というメンバ変数が内部にあり、それに対するgetter」という意味であるのが一般的かと思います。この命名をするのであれば、
VoiceModel
のようにSpeakerMeta[] metas
を持って随時更新し、それに対するgetterという形の定義にした方がよいと思います。(ちなみに私の感覚だと
public final
というgetterを介さないメンバ変数の露出は、Javaの慣習に反するのではと思っています。)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかにgetMetasはmetasプロパティの単なるgetterじゃないので直感的じゃないかもと思いました。
audio_query辺りと一緒だから命名規則もこれに合わせておくと直感的かも。
ということで変更お願いできると・・・!! @sevenc-nanashi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#metas()
にしました(という解釈で合ってるのかな)