Skip to content

Commit

Permalink
JavaStrの内容を直にUTF-8として読まない (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip authored Oct 22, 2023
1 parent f8f56ae commit 5da3f49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
7 changes: 5 additions & 2 deletions crates/voicevox_core_java_api/src/open_jtalk.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::sync::{Arc, Mutex};
use std::{
borrow::Cow,
sync::{Arc, Mutex},
};

use crate::common::throw_if_err;
use jni::{
Expand Down Expand Up @@ -26,7 +29,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_OpenJtalk_rsNewWithInit
) {
throw_if_err(env, (), |env| {
let open_jtalk_dict_dir = env.get_string(&open_jtalk_dict_dir)?;
let open_jtalk_dict_dir = open_jtalk_dict_dir.to_str()?;
let open_jtalk_dict_dir = &*Cow::from(&open_jtalk_dict_dir);

let internal = voicevox_core::OpenJtalk::new_with_initialize(open_jtalk_dict_dir)?;
env.set_rust_field(&this, "handle", Arc::new(internal))?;
Expand Down
21 changes: 12 additions & 9 deletions crates/voicevox_core_java_api/src/user_dict.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use jni::objects::JClass;
use std::sync::{Arc, Mutex};
use std::{
borrow::Cow,
sync::{Arc, Mutex},
};

use crate::common::throw_if_err;
use jni::{
Expand Down Expand Up @@ -34,7 +37,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsAddWord<'loc
.clone();

let word_json = env.get_string(&word_json)?;
let word_json = word_json.to_str()?;
let word_json = &Cow::from(&word_json);

let word: voicevox_core::UserDictWord = serde_json::from_str(word_json)?;

Expand Down Expand Up @@ -63,9 +66,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsUpdateWord<'
.clone();

let uuid = env.get_string(&uuid)?;
let uuid = uuid.to_str()?.parse()?;
let uuid = Cow::from(&uuid).parse()?;
let word_json = env.get_string(&word_json)?;
let word_json = word_json.to_str()?;
let word_json = &Cow::from(&word_json);

let word: voicevox_core::UserDictWord = serde_json::from_str(word_json)?;

Expand All @@ -90,7 +93,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsRemoveWord<'
.clone();

let uuid = env.get_string(&uuid)?;
let uuid = uuid.to_str()?.parse()?;
let uuid = Cow::from(&uuid).parse()?;

{
let mut internal = internal.lock().unwrap();
Expand Down Expand Up @@ -137,7 +140,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsLoad<'local>
.clone();

let path = env.get_string(&path)?;
let path = path.to_str()?;
let path = &Cow::from(&path);

{
let mut internal = internal.lock().unwrap();
Expand All @@ -160,7 +163,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsSave<'local>
.clone();

let path = env.get_string(&path)?;
let path = path.to_str()?;
let path = &Cow::from(&path);

{
let internal = internal.lock().unwrap();
Expand Down Expand Up @@ -211,7 +214,7 @@ extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsToZenkaku<'local>(
) -> jobject {
throw_if_err(env, std::ptr::null_mut(), |env| {
let text = env.get_string(&text)?;
let text = text.to_str()?;
let text = &Cow::from(&text);

let text = voicevox_core::__internal::to_zenkaku(text);

Expand All @@ -228,7 +231,7 @@ extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsValidatePronunciati
) {
throw_if_err(env, (), |env| {
let text = env.get_string(&text)?;
let text = text.to_str()?;
let text = &Cow::from(&text);

voicevox_core::__internal::validate_pronunciation(text)?;

Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core_java_api/src/voice_model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{borrow::Cow, sync::Arc};

use crate::common::{throw_if_err, RUNTIME};
use jni::{
Expand All @@ -15,7 +15,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModel_rsFromPath<'
) {
throw_if_err(env, (), |env| {
let model_path = env.get_string(&model_path)?;
let model_path = model_path.to_str()?;
let model_path = &*Cow::from(&model_path);

let internal = RUNTIME.block_on(voicevox_core::VoiceModel::from_path(model_path))?;

Expand Down

0 comments on commit 5da3f49

Please sign in to comment.