Skip to content
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

Change!: C APIの名前を少し変更 #576

Merged
merged 5 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions crates/voicevox_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ pub enum Error {
#[source]
source: anyhow::Error,
},
#[error("{} ({})", base_error_message(VOICEVOX_ALREADY_LOADED_MODEL_ERROR), path.display())]
#[error("{} ({})", base_error_message(VOICEVOX_RESULT_ALREADY_LOADED_MODEL_ERROR), path.display())]
AlreadyLoadedModel { path: PathBuf },

#[error("{} ({model_id:?})", base_error_message(VOICEVOX_UNLOADED_MODEL_ERROR))]
#[error(
"{} ({model_id:?})",
base_error_message(VOICEVOX_RESULT_UNLOADED_MODEL_ERROR)
)]
UnloadedModel { model_id: VoiceModelId },

#[error("{}({path}):{source}", base_error_message(VOICEVOX_OPEN_FILE_ERROR))]
#[error(
"{}({path}):{source}",
base_error_message(VOICEVOX_RESULT_OPEN_FILE_ERROR)
)]
OpenFile {
path: PathBuf,
#[source]
Expand All @@ -42,7 +48,7 @@ pub enum Error {

#[error(
"{}({path}):{source}",
base_error_message(VOICEVOX_VVM_MODEL_READ_ERROR)
base_error_message(VOICEVOX_RESULT_VVM_MODEL_READ_ERROR)
)]
VvmRead {
path: PathBuf,
Expand Down Expand Up @@ -83,19 +89,25 @@ pub enum Error {
#[error("{},{0}", base_error_message(VOICEVOX_RESULT_PARSE_KANA_ERROR))]
ParseKana(#[from] KanaParseError),

#[error("{}: {0}", base_error_message(VOICEVOX_LOAD_USER_DICT_ERROR))]
#[error("{}: {0}", base_error_message(VOICEVOX_RESULT_LOAD_USER_DICT_ERROR))]
LoadUserDict(String),

#[error("{}: {0}", base_error_message(VOICEVOX_SAVE_USER_DICT_ERROR))]
#[error("{}: {0}", base_error_message(VOICEVOX_RESULT_SAVE_USER_DICT_ERROR))]
SaveUserDict(String),

#[error("{}: {0}", base_error_message(VOICEVOX_UNKNOWN_USER_DICT_WORD_ERROR))]
#[error(
"{}: {0}",
base_error_message(VOICEVOX_RESULT_UNKNOWN_USER_DICT_WORD_ERROR)
)]
UnknownWord(Uuid),

#[error("{}: {0}", base_error_message(VOICEVOX_USE_USER_DICT_ERROR))]
#[error("{}: {0}", base_error_message(VOICEVOX_RESULT_USE_USER_DICT_ERROR))]
UseUserDict(String),

#[error("{}: {0}", base_error_message(VOICEVOX_INVALID_USER_DICT_WORD_ERROR))]
#[error(
"{}: {0}",
base_error_message(VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR)
)]
InvalidWord(InvalidWordError),
}

Expand Down
38 changes: 20 additions & 18 deletions crates/voicevox_core/src/result_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ pub enum VoicevoxResultCode {
/// 無効なAccentPhrase
VOICEVOX_RESULT_INVALID_ACCENT_PHRASE_ERROR = 15,
/// ファイルオープンエラー
VOICEVOX_OPEN_FILE_ERROR = 16,
VOICEVOX_RESULT_OPEN_FILE_ERROR = 16,
/// Modelを読み込めなかった
VOICEVOX_VVM_MODEL_READ_ERROR = 17,
VOICEVOX_RESULT_VVM_MODEL_READ_ERROR = 17,
/// すでに読み込まれているModelを読み込もうとした
VOICEVOX_ALREADY_LOADED_MODEL_ERROR = 18,
VOICEVOX_RESULT_ALREADY_LOADED_MODEL_ERROR = 18,
/// Modelが読み込まれていない
VOICEVOX_UNLOADED_MODEL_ERROR = 19,
VOICEVOX_RESULT_UNLOADED_MODEL_ERROR = 19,
/// ユーザー辞書を読み込めなかった
VOICEVOX_LOAD_USER_DICT_ERROR = 20,
VOICEVOX_RESULT_LOAD_USER_DICT_ERROR = 20,
/// ユーザー辞書を書き込めなかった
VOICEVOX_SAVE_USER_DICT_ERROR = 21,
VOICEVOX_RESULT_SAVE_USER_DICT_ERROR = 21,
/// ユーザー辞書に単語が見つからなかった
VOICEVOX_UNKNOWN_USER_DICT_WORD_ERROR = 22,
VOICEVOX_RESULT_UNKNOWN_USER_DICT_WORD_ERROR = 22,
/// OpenJTalkのユーザー辞書の設定に失敗した
VOICEVOX_USE_USER_DICT_ERROR = 23,
VOICEVOX_RESULT_USE_USER_DICT_ERROR = 23,
/// ユーザー辞書の単語のバリデーションに失敗した
VOICEVOX_INVALID_USER_DICT_WORD_ERROR = 24,
VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR = 24,
/// UUIDの変換に失敗した
VOICEVOX_RESULT_INVALID_UUID_ERROR = 25,
}
Expand Down Expand Up @@ -85,17 +85,19 @@ pub const fn error_result_to_message(result_code: VoicevoxResultCode) -> &'stati
}
VOICEVOX_RESULT_INVALID_AUDIO_QUERY_ERROR => "無効なaudio_queryです\0",
VOICEVOX_RESULT_INVALID_ACCENT_PHRASE_ERROR => "無効なaccent_phraseです\0",
VOICEVOX_OPEN_FILE_ERROR => "ファイルオープンに失敗しました\0",
VOICEVOX_VVM_MODEL_READ_ERROR => "Modelを読み込めませんでした\0",
VOICEVOX_ALREADY_LOADED_MODEL_ERROR => {
VOICEVOX_RESULT_OPEN_FILE_ERROR => "ファイルオープンに失敗しました\0",
VOICEVOX_RESULT_VVM_MODEL_READ_ERROR => "Modelを読み込めませんでした\0",
VOICEVOX_RESULT_ALREADY_LOADED_MODEL_ERROR => {
"すでに読み込まれているModelを読み込もうとしました\0"
}
VOICEVOX_UNLOADED_MODEL_ERROR => "Modelが読み込まれていません\0",
VOICEVOX_LOAD_USER_DICT_ERROR => "ユーザー辞書を読み込めませんでした\0",
VOICEVOX_SAVE_USER_DICT_ERROR => "ユーザー辞書を書き込めませんでした\0",
VOICEVOX_UNKNOWN_USER_DICT_WORD_ERROR => "ユーザー辞書に単語が見つかりませんでした\0",
VOICEVOX_USE_USER_DICT_ERROR => "OpenJTalkのユーザー辞書の設定に失敗しました\0",
VOICEVOX_INVALID_USER_DICT_WORD_ERROR => {
VOICEVOX_RESULT_UNLOADED_MODEL_ERROR => "Modelが読み込まれていません\0",
VOICEVOX_RESULT_LOAD_USER_DICT_ERROR => "ユーザー辞書を読み込めませんでした\0",
VOICEVOX_RESULT_SAVE_USER_DICT_ERROR => "ユーザー辞書を書き込めませんでした\0",
VOICEVOX_RESULT_UNKNOWN_USER_DICT_WORD_ERROR => {
"ユーザー辞書に単語が見つかりませんでした\0"
}
VOICEVOX_RESULT_USE_USER_DICT_ERROR => "OpenJTalkのユーザー辞書の設定に失敗しました\0",
VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR => {
"ユーザー辞書の単語のバリデーションに失敗しました\0"
}
VOICEVOX_RESULT_INVALID_UUID_ERROR => "UUIDの変換に失敗しました\0",
Expand Down
52 changes: 26 additions & 26 deletions crates/voicevox_core_c_api/include/voicevox_core.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions crates/voicevox_core_c_api/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ pub(crate) fn into_result_code_with_error(result: CApiResult<()>) -> VoicevoxRes
Err(RustApi(ExtractFullContextLabel(_))) => {
VOICEVOX_RESULT_EXTRACT_FULL_CONTEXT_LABEL_ERROR
}
Err(RustApi(UnloadedModel { .. })) => VOICEVOX_UNLOADED_MODEL_ERROR,
Err(RustApi(AlreadyLoadedModel { .. })) => VOICEVOX_ALREADY_LOADED_MODEL_ERROR,
Err(RustApi(OpenFile { .. })) => VOICEVOX_OPEN_FILE_ERROR,
Err(RustApi(VvmRead { .. })) => VOICEVOX_VVM_MODEL_READ_ERROR,
Err(RustApi(UnloadedModel { .. })) => VOICEVOX_RESULT_UNLOADED_MODEL_ERROR,
Err(RustApi(AlreadyLoadedModel { .. })) => VOICEVOX_RESULT_ALREADY_LOADED_MODEL_ERROR,
Err(RustApi(OpenFile { .. })) => VOICEVOX_RESULT_OPEN_FILE_ERROR,
Err(RustApi(VvmRead { .. })) => VOICEVOX_RESULT_VVM_MODEL_READ_ERROR,
Err(RustApi(ParseKana(_))) => VOICEVOX_RESULT_PARSE_KANA_ERROR,
Err(RustApi(LoadUserDict(_))) => VOICEVOX_LOAD_USER_DICT_ERROR,
Err(RustApi(SaveUserDict(_))) => VOICEVOX_SAVE_USER_DICT_ERROR,
Err(RustApi(UnknownWord(_))) => VOICEVOX_UNKNOWN_USER_DICT_WORD_ERROR,
Err(RustApi(UseUserDict(_))) => VOICEVOX_USE_USER_DICT_ERROR,
Err(RustApi(InvalidWord(_))) => VOICEVOX_INVALID_USER_DICT_WORD_ERROR,
Err(RustApi(LoadUserDict(_))) => VOICEVOX_RESULT_LOAD_USER_DICT_ERROR,
Err(RustApi(SaveUserDict(_))) => VOICEVOX_RESULT_SAVE_USER_DICT_ERROR,
Err(RustApi(UnknownWord(_))) => VOICEVOX_RESULT_UNKNOWN_USER_DICT_WORD_ERROR,
Err(RustApi(UseUserDict(_))) => VOICEVOX_RESULT_USE_USER_DICT_ERROR,
Err(RustApi(InvalidWord(_))) => VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR,
Err(InvalidUtf8Input) => VOICEVOX_RESULT_INVALID_UTF8_INPUT_ERROR,
Err(InvalidAudioQuery(_)) => VOICEVOX_RESULT_INVALID_AUDIO_QUERY_ERROR,
Err(InvalidAccentPhrase(_)) => VOICEVOX_RESULT_INVALID_ACCENT_PHRASE_ERROR,
Expand Down
26 changes: 13 additions & 13 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub unsafe extern "C" fn voicevox_create_supported_devices_json(
})())
}

/// ::voicevox_synthesizer_audio_query のオプション。
/// ::voicevox_synthesizer_create_audio_query のオプション。
#[repr(C)]
pub struct VoicevoxAudioQueryOptions {
/// AquesTalk風記法としてテキストを解釈する
Expand All @@ -523,20 +523,20 @@ pub static voicevox_default_audio_query_options: VoicevoxAudioQueryOptions = Con
/// \examples{
/// ```c
/// char *audio_query;
/// voicevox_synthesizer_audio_query(synthesizer,
/// "こんにちは", // 日本語テキスト
/// 2, // "四国めたん (ノーマル)"
/// (VoicevoxAudioQueryOptions){.kana = false},
/// &audio_query);
/// voicevox_synthesizer_create_audio_query(synthesizer,
qryxip marked this conversation as resolved.
Show resolved Hide resolved
/// "こんにちは", // 日本語テキスト
/// 2, // "四国めたん (ノーマル)"
/// (VoicevoxAudioQueryOptions){.kana = false},
/// &audio_query);
/// ```
///
/// ```c
/// char *audio_query;
/// voicevox_synthesizer_audio_query(synthesizer,
/// "コンニチワ'", // AquesTalk風記法
/// 2, // "四国めたん (ノーマル)"
/// (VoicevoxAudioQueryOptions){.kana = true},
/// &audio_query);
/// voicevox_synthesizer_create_audio_query(synthesizer,
/// "コンニチワ'", // AquesTalk風記法
/// 2, // "四国めたん (ノーマル)"
/// (VoicevoxAudioQueryOptions){.kana = true},
/// &audio_query);
/// ```
/// }
///
Expand All @@ -547,7 +547,7 @@ pub static voicevox_default_audio_query_options: VoicevoxAudioQueryOptions = Con
/// - `output_audio_query_json`は<a href="#voicevox-core-safety">書き込みについて有効</a>でなければならない。
/// }
#[no_mangle]
pub unsafe extern "C" fn voicevox_synthesizer_audio_query(
pub unsafe extern "C" fn voicevox_synthesizer_create_audio_query(
synthesizer: &VoicevoxSynthesizer,
text: *const c_char,
style_id: VoicevoxStyleId,
Expand Down Expand Up @@ -882,7 +882,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_tts(
/// \safety{
/// - `json`は以下のAPIで得られたポインタでなくてはいけない。
/// - ::voicevox_create_supported_devices_json
/// - ::voicevox_synthesizer_audio_query
/// - ::voicevox_synthesizer_create_audio_query
/// - ::voicevox_synthesizer_create_accent_phrases
/// - ::voicevox_synthesizer_replace_mora_data
/// - ::voicevox_synthesizer_replace_phoneme_length
Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core_c_api/tests/e2e/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) struct Symbols<'lib> {
Symbol<'lib, unsafe extern "C" fn(*const VoicevoxSynthesizer) -> *const c_char>,
pub(crate) voicevox_create_supported_devices_json:
Symbol<'lib, unsafe extern "C" fn(*mut *mut c_char) -> VoicevoxResultCode>,
pub(crate) voicevox_synthesizer_audio_query: Symbol<
pub(crate) voicevox_synthesizer_create_audio_query: Symbol<
'lib,
unsafe extern "C" fn(
*const VoicevoxSynthesizer,
Expand Down Expand Up @@ -204,7 +204,7 @@ impl<'lib> Symbols<'lib> {
voicevox_synthesizer_is_loaded_voice_model,
voicevox_synthesizer_get_metas_json,
voicevox_create_supported_devices_json,
voicevox_synthesizer_audio_query,
voicevox_synthesizer_create_audio_query,
voicevox_synthesizer_synthesis,
voicevox_synthesizer_tts,
voicevox_json_free,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl assert_cdylib::TestCase for TestCase {
voicevox_synthesizer_new_with_initialize,
voicevox_synthesizer_delete,
voicevox_synthesizer_load_voice_model,
voicevox_synthesizer_audio_query,
voicevox_synthesizer_create_audio_query,
voicevox_synthesizer_synthesis,
voicevox_json_free,
voicevox_wav_free,
Expand Down Expand Up @@ -90,7 +90,7 @@ impl assert_cdylib::TestCase for TestCase {
let audio_query = {
let mut audio_query = MaybeUninit::uninit();
let text = CString::new(&*self.text).unwrap();
assert_ok(voicevox_synthesizer_audio_query(
assert_ok(voicevox_synthesizer_create_audio_query(
synthesizer,
text.as_ptr(),
STYLE_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl assert_cdylib::TestCase for TestCase {
voicevox_synthesizer_new_with_initialize,
voicevox_synthesizer_delete,
voicevox_synthesizer_load_voice_model,
voicevox_synthesizer_audio_query,
voicevox_synthesizer_create_audio_query,
..
} = Symbols::new(lib)?;

Expand Down Expand Up @@ -103,7 +103,7 @@ impl assert_cdylib::TestCase for TestCase {
assert_ok(voicevox_synthesizer_load_voice_model(synthesizer, model));

let mut audio_query_without_dict = std::ptr::null_mut();
assert_ok(voicevox_synthesizer_audio_query(
assert_ok(voicevox_synthesizer_create_audio_query(
synthesizer,
cstr!("this_word_should_not_exist_in_default_dictionary").as_ptr(),
STYLE_ID,
Expand All @@ -117,7 +117,7 @@ impl assert_cdylib::TestCase for TestCase {
assert_ok(voicevox_open_jtalk_rc_use_user_dict(openjtalk, dict));

let mut audio_query_with_dict = std::ptr::null_mut();
assert_ok(voicevox_synthesizer_audio_query(
assert_ok(voicevox_synthesizer_create_audio_query(
synthesizer,
cstr!("this_word_should_not_exist_in_default_dictionary").as_ptr(),
STYLE_ID,
Expand Down