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

VoicevoxResultCodeをC APIに移動 #580

Merged
merged 1 commit into from
Aug 22, 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
90 changes: 90 additions & 0 deletions Cargo.lock

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

70 changes: 15 additions & 55 deletions crates/voicevox_core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use self::engine::{FullContextLabelError, KanaParseError};
use self::result_code::VoicevoxResultCode::{self, *};
use super::*;
//use engine::
use std::path::PathBuf;
Expand All @@ -9,76 +8,49 @@ use uuid::Uuid;
/// VOICEVOX COREのエラー。
#[derive(Error, Debug)]
pub enum Error {
/*
* エラーメッセージのベースとなる文字列は必ずbase_error_message関数を使用してVoicevoxResultCodeのエラー出力の内容と対応するようにすること
*/
#[error(
"{}",
base_error_message(VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT_ERROR)
)]
#[error("OpenJTalkの辞書が読み込まれていません")]
NotLoadedOpenjtalkDict,

#[error("{}", base_error_message(VOICEVOX_RESULT_GPU_SUPPORT_ERROR))]
#[error("GPU機能をサポートすることができません")]
GpuSupport,

#[error(transparent)]
LoadModel(#[from] LoadModelError),

#[error(
"{} ({model_id:?})",
base_error_message(VOICEVOX_RESULT_UNLOADED_MODEL_ERROR)
)]
#[error("Modelが読み込まれていません ({model_id:?})")]
UnloadedModel { model_id: VoiceModelId },

#[error(
"{},{0}",
base_error_message(VOICEVOX_RESULT_GET_SUPPORTED_DEVICES_ERROR)
)]
#[error("サポートされているデバイス情報取得中にエラーが発生しました,{0}")]
GetSupportedDevices(#[source] anyhow::Error),

#[error(
"{}: {style_id:?}",
base_error_message(VOICEVOX_RESULT_INVALID_STYLE_ID_ERROR)
)]
#[error("無効なspeaker_idです: {style_id:?}")]
InvalidStyleId { style_id: StyleId },

#[error(
"{}: {model_id:?}",
base_error_message(VOICEVOX_RESULT_INVALID_MODEL_ID_ERROR)
)]
#[error("無効なmodel_idです: {model_id:?}")]
InvalidModelId { model_id: VoiceModelId },

#[error("{}", base_error_message(VOICEVOX_RESULT_INFERENCE_ERROR))]
#[error("推論に失敗しました")]
InferenceFailed,

#[error(
"{},{0}",
base_error_message(VOICEVOX_RESULT_EXTRACT_FULL_CONTEXT_LABEL_ERROR)
)]
#[error("入力テキストからのフルコンテキストラベル抽出に失敗しました,{0}")]
ExtractFullContextLabel(#[from] FullContextLabelError),

#[error("{},{0}", base_error_message(VOICEVOX_RESULT_PARSE_KANA_ERROR))]
#[error("入力テキストをAquesTalk風記法としてパースすることに失敗しました,{0}")]
ParseKana(#[from] KanaParseError),

#[error("{}: {0}", base_error_message(VOICEVOX_RESULT_LOAD_USER_DICT_ERROR))]
#[error("ユーザー辞書を読み込めませんでした: {0}")]
LoadUserDict(String),

#[error("{}: {0}", base_error_message(VOICEVOX_RESULT_SAVE_USER_DICT_ERROR))]
#[error("ユーザー辞書を書き込めませんでした: {0}")]
SaveUserDict(String),

#[error(
"{}: {0}",
base_error_message(VOICEVOX_RESULT_UNKNOWN_USER_DICT_WORD_ERROR)
)]
#[error("ユーザー辞書に単語が見つかりませんでした: {0}")]
UnknownWord(Uuid),

#[error("{}: {0}", base_error_message(VOICEVOX_RESULT_USE_USER_DICT_ERROR))]
#[error("OpenJTalkのユーザー辞書の設定に失敗しました: {0}")]
UseUserDict(String),

#[error(
"{}: {0}",
base_error_message(VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR)
)]
#[error("ユーザー辞書の単語のバリデーションに失敗しました: {0}")]
InvalidWord(InvalidWordError),
}

Expand All @@ -105,26 +77,14 @@ impl LoadModelError {

#[derive(derive_more::Display, Debug)]
pub enum LoadModelErrorKind {
//#[display(fmt = "{}", "base_error_message(VOICEVOX_RESULT_OPEN_ZIP_FILE_ERROR)")]
#[display(fmt = "ZIPファイルとして開くことができませんでした")]
OpenZipFile,
//#[display(fmt = "{}", "base_error_message(VOICEVOX_RESULT_READ_ZIP_ENTRY_ERROR)")]
#[display(fmt = "`{filename}`を読み取れませんでした")]
ReadZipEntry { filename: String },
//#[display(fmt = "{}", "base_error_message(VOICEVOX_RESULT_MODEL_ALREADY_LOADED_ERROR)")]
#[display(fmt = "モデル`{id}`は既に読み込まれています")]
ModelAlreadyLoaded { id: VoiceModelId },
//#[display(fmt = "{}", "base_error_message(VOICEVOX_RESULT_STYLE_ALREADY_LOADED_ERROR)")]
#[display(fmt = "スタイル`{id}`は既に読み込まれています")]
StyleAlreadyLoaded { id: StyleId },
#[display(
fmt = "{}",
"base_error_message(VOICEVOX_RESULT_INVALID_MODEL_DATA_ERROR)"
)]
#[display(fmt = "モデルデータを読むことができませんでした")]
InvalidModelData,
}

fn base_error_message(result_code: VoicevoxResultCode) -> &'static str {
let c_message: &'static str = crate::result_code::error_result_to_message(result_code);
&c_message[..(c_message.len() - 1)]
}
1 change: 0 additions & 1 deletion crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod manifest;
mod metas;
mod numerics;
mod result;
pub mod result_code;
mod status;
mod user_dict;
mod version;
Expand Down
2 changes: 2 additions & 0 deletions crates/voicevox_core_c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ name = "e2e"
directml = ["voicevox_core/directml"]

[dependencies]
cstr = "0.2.11"
derive-getters.workspace = true
libc = "0.2.134"
once_cell.workspace = true
Expand Down Expand Up @@ -47,6 +48,7 @@ process_path.workspace = true
regex.workspace = true
rstest = "0.15.0"
serde.workspace = true
serde_with = "3.3.0"
strum.workspace = true
tempfile.workspace = true
test_util.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/voicevox_core_c_api/src/compatible_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{collections::BTreeMap, sync::Arc};
use super::*;
use libc::c_int;

pub use voicevox_core::result_code::VoicevoxResultCode;
use voicevox_core::{OpenJtalk, StyleId, VoiceModel};

macro_rules! ensure_initialized {
Expand Down
3 changes: 2 additions & 1 deletion crates/voicevox_core_c_api/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ pub(crate) fn into_result_code_with_error(result: CApiResult<()>) -> VoicevoxRes
}

fn into_result_code(result: CApiResult<()>) -> VoicevoxResultCode {
use voicevox_core::{result_code::VoicevoxResultCode::*, Error::*, LoadModelErrorKind::*};
use voicevox_core::{Error::*, LoadModelErrorKind::*};
use CApiError::*;
use VoicevoxResultCode::*;

match result {
Ok(()) => VOICEVOX_RESULT_OK,
Expand Down
10 changes: 3 additions & 7 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ mod c_impls;
mod compatible_engine;
mod drop_check;
mod helpers;
mod result_code;
mod slice_owner;
use self::drop_check::C_STRING_DROP_CHECKER;
use self::helpers::*;
use self::result_code::VoicevoxResultCode;
use self::slice_owner::U8_SLICE_OWNER;
use chrono::SecondsFormat;
use derive_getters::Getters;
Expand Down Expand Up @@ -177,8 +179,6 @@ pub extern "C" fn voicevox_open_jtalk_rc_delete(open_jtalk: Box<OpenJtalkRc>) {
drop(open_jtalk);
}

pub use voicevox_core::result_code::VoicevoxResultCode;

/// ハードウェアアクセラレーションモードを設定する設定値。
#[repr(i32)]
#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -948,11 +948,7 @@ pub extern "C" fn voicevox_wav_free(wav: *mut u8) {
pub extern "C" fn voicevox_error_result_to_message(
result_code: VoicevoxResultCode,
) -> *const c_char {
let message = CStr::from_bytes_with_nul(
voicevox_core::result_code::error_result_to_message(result_code).as_ref(),
)
.expect("`error_result_to_message`が返す文字列はヌル終端であるはずである");

let message = result_code::error_result_to_message(result_code);
C_STRING_DROP_CHECKER.blacklist(message).as_ptr()
}

Expand Down
Loading