Skip to content

Commit 474c334

Browse files
Fix: 一部キャラで動かないのを修正
1 parent 9910c04 commit 474c334

File tree

3 files changed

+66
-23
lines changed

3 files changed

+66
-23
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ AIVoiceVox は[A.I.Voice](https://aivoice.jp/)を[Voicevox](https://voicevox.hir
2121

2222
## ライセンス
2323

24-
MIT License で公開しています。詳しくは[LICENSE](LICENSE)をご覧ください。
25-
生成された音声については、A.I.Voice の利用規約に従ってください。
26-
このブリッジ自体にはクレジット表記は必要ありませんが、このリポジトリのリンクを貼ったりや紹介動画(TODO)をおや作品登録していただくと助かります
24+
MIT License で公開しています。詳しくは[LICENSE](LICENSE)をご覧ください。
25+
生成された音声については、A.I.Voice の利用規約に従ってください。
26+
このブリッジ自体にはクレジット表記は必要ありませんが、このリポジトリのリンクを貼ったり紹介動画(TODO)を親作品登録していただくと助かります

src/icon_manager.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,24 @@ impl IconManager {
6363
)
6464
.await
6565
.map_err(|e| Error::ReadImageFailed(e.into()))?;
66-
{
66+
67+
let root = {
6768
let mut images = zip_reader.file().entries().iter().enumerate();
68-
let icon = match images.find(|(_, x)| {
69+
let (icon, root) = match images.find(|(_, x)| {
6970
let filename = x.entry().filename().as_str().unwrap_or("");
7071

71-
filename == "images/icon.png" || filename == "icon.png"
72+
filename.ends_with("icon.png")
7273
}) {
73-
Some((icon, _)) => icon,
74+
Some((icon, entry)) => {
75+
let filename = entry
76+
.entry()
77+
.filename()
78+
.as_str()
79+
.unwrap_or("")
80+
.replace('\\', "/");
81+
82+
(icon, filename.replace("icon.png", ""))
83+
}
7484
None => return Err(Error::ReadImageFailed(anyhow!("Icon not found"))),
7585
};
7686

@@ -141,7 +151,11 @@ impl IconManager {
141151
sorrow: sorrow_icon_buf,
142152
},
143153
);
144-
}
154+
155+
root
156+
};
157+
158+
info!("{} root: {}", speaker.internal_name(), root);
145159

146160
let mut portraits = StyleImages {
147161
normal: Vec::new(),
@@ -152,10 +166,14 @@ impl IconManager {
152166
for emotion in ['A', 'J', 'N', 'S'].iter() {
153167
let mut images = zip_reader.file().entries().iter().enumerate();
154168
let image_index = match images.find(|(_, x)| {
155-
let name = x.entry().filename().as_str().unwrap_or("");
156-
157-
(name.starts_with(&format!("images/{}/OpenEyes", emotion))
158-
|| name.starts_with(&format!("{}/OpenEyes", emotion)))
169+
let name = x
170+
.entry()
171+
.filename()
172+
.as_str()
173+
.unwrap_or("")
174+
.replace('\\', "/");
175+
176+
name.starts_with(&format!("{}{}/OpenEyes", root, emotion))
159177
&& name.split('/').last().and_then(|n| n.chars().nth(4)) == Some('0')
160178
}) {
161179
Some((i, _)) => i,
@@ -189,6 +207,22 @@ impl IconManager {
189207
.write_to(&mut final_image_cursor, image::ImageOutputFormat::Png)
190208
.map_err(|e| Error::ReadImageFailed(e.into()))?;
191209
}
210+
for (name, portrait) in [
211+
("Normal", &portraits.normal),
212+
("Joy", &portraits.joy),
213+
("Anger", &portraits.anger),
214+
("Sorrow", &portraits.sorrow),
215+
]
216+
.iter()
217+
{
218+
if portrait.is_empty() {
219+
return Err(Error::ReadImageFailed(anyhow!(
220+
"{}の{}の立ち絵が見つかりませんでした。",
221+
speaker.internal_name(),
222+
name,
223+
)));
224+
}
225+
}
192226

193227
self.portraits
194228
.insert(speaker.internal_name().to_string(), portraits);

src/main.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ struct Cli {
3636
#[tokio::main]
3737
async fn main() -> Result<()> {
3838
let args = Cli::parse();
39+
40+
tracing_subscriber::fmt()
41+
.with_writer(std::io::stderr)
42+
.with_ansi(cfg!(debug_assertions))
43+
.init();
44+
45+
AIVOICE.lock().await.setup().await?;
46+
47+
let result = main_impl(args).await;
48+
49+
info!("Shutting down...");
50+
51+
AIVOICE.lock().await.shutdown().await?;
52+
53+
result?;
54+
55+
Ok(())
56+
}
57+
58+
async fn main_impl(args: Cli) -> Result<()> {
3959
let app = Router::new()
4060
.route("/", get(get_index))
4161
.route("/version", get(routes::info::get_version))
@@ -80,13 +100,6 @@ async fn main() -> Result<()> {
80100
.on_response(trace::DefaultOnResponse::new().level(Level::INFO)),
81101
);
82102

83-
tracing_subscriber::fmt()
84-
.with_writer(std::io::stderr)
85-
.with_ansi(cfg!(debug_assertions))
86-
.init();
87-
88-
AIVOICE.lock().await.setup().await?;
89-
90103
ICON_MANAGER.lock().await.setup().await?;
91104

92105
let port = args.port.unwrap_or(50201);
@@ -119,10 +132,6 @@ async fn main() -> Result<()> {
119132
})
120133
.await?;
121134

122-
info!("Shutting down...");
123-
124-
AIVOICE.lock().await.shutdown().await?;
125-
126135
Ok(())
127136
}
128137

0 commit comments

Comments
 (0)