VOICEVOX / voicevox_core

無料で使える中品質なテキスト読み上げソフトウェア、VOICEVOXのコア
https://voicevox.hiroshiba.jp/
MIT License
857 stars 115 forks source link

CとJavaのブロッキングAPIを実装 #705

Closed qryxip closed 9 months ago

qryxip commented 9 months ago

内容

702 で実装したブロッキングAPIをC APIとJava APIで使い、両者からtokioの依存を外します。

ロガーの初期化をどうするかですが、次の方針に従います。

        // FIXME: `into_result_code_with_error`を`run`とかに改名し、`init_logger`をその中に移動

追記: https://github.com/VOICEVOX/voicevox_core/pull/705#issuecomment-1848890070

関連 Issue

662

702

その他

qryxip commented 9 months ago

ロガーの初期化をどこに置くのかについては選択肢がいくつかあると思います。例えば次のように毎回init_logger()を呼ぶというのもありなはずで、draftの間に意見を伺えればと思っています。

#[no_mangle]
pub unsafe extern "C" fn f() -> VoicevoxResultCode {
    let _ = init_logger();
    into_result_code_with_error((|| { … })())
}

#[no_mangle]
pub unsafe extern "C" fn g() -> VoicevoxResultCode {
    let _ = init_logger();
    into_result_code_with_error((|| { … })())
}
qryxip commented 9 months ago

ロガーの初期化ですが、C APIについては、全ての関数にロガー初期化を明示的にはさむようにしました。

 #[no_mangle]
 pub unsafe extern "C" fn voicevox_synthesizer_new(
     open_jtalk: &OpenJtalkRc,
     options: VoicevoxInitializeOptions,
     out_synthesizer: NonNull<Box<VoicevoxSynthesizer>>,
 ) -> VoicevoxResultCode {
+    init_logger_once();
     into_result_code_with_error((|| {
         let options = options.into();

         let synthesizer = VoicevoxSynthesizer::new(open_jtalk, &options)?.into();
         out_synthesizer.as_ptr().write_unaligned(synthesizer);
         Ok(())
     })())
 }

Javaではclass Dllの末尾で直接呼ぶようにしました。

@@ -64,5 +64,11 @@ abstract class Dll {
         throw new RuntimeException("Failed to load Voicevox Core DLL for " + target, e);
       }
     }
+
+    new LoggerInitializer().initLogger();
+  }
+
+  static class LoggerInitializer {
+    native void initLogger();
   }
 }
Hiroshiba commented 9 months ago

あすみません、返信できてませんでした 🙇

ロガーの初期化ですが、ちょっと考えた感じCもJavaも実装された方法が良いのかなと思いました。 明示的に呼んでもらう方法もありますが、うーん・・・・・・・。 主要な機能だけに入れるのはありかもですが、なんかこっちが予期しない流れもあるだろうと思うので、であればまあ毎回呼ぶのがやっぱり無難なのかなと!