From 91dddf377b5bb764e795ad4af02ea020374eae08 Mon Sep 17 00:00:00 2001 From: chinosk <2248589280@qq.com> Date: Sun, 14 May 2023 19:25:03 +0800 Subject: [PATCH] update error handling --- voice extractor/voice extractor/voice_ex.cs | 9 +++++---- voiceex/resource.py | 1 + voiceex/voice_ex.py | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/voice extractor/voice extractor/voice_ex.cs b/voice extractor/voice extractor/voice_ex.cs index 4c5afbf..b1e43dd 100644 --- a/voice extractor/voice extractor/voice_ex.cs +++ b/voice extractor/voice extractor/voice_ex.cs @@ -39,6 +39,7 @@ public UmaVoiceEx(string acbPath, string awbPath) } catch (Exception ex) { + Close(); throw new Exception($"File load failed: {ex.Message}"); } } @@ -460,10 +461,10 @@ public static void SilenceWavPartsByActivePos(string fileName, string saveName, public void Close() { - acbFile.Dispose(); - awbFile.Dispose(); - acbReader.Dispose(); - awbReader.Dispose(); + acbFile?.Dispose(); + awbFile?.Dispose(); + acbReader?.Dispose(); + awbReader?.Dispose(); } } diff --git a/voiceex/resource.py b/voiceex/resource.py index 14ab3c4..21deb49 100644 --- a/voiceex/resource.py +++ b/voiceex/resource.py @@ -15,6 +15,7 @@ clr.AddReference("./voice extractor/voice extractor/bin/Release/net6.0/voice extractor") from System.Collections.Generic import List as CsList from System import UInt64, String +from System.IO import InvalidDataException import voice_extractor diff --git a/voiceex/voice_ex.py b/voiceex/voice_ex.py index ce105a2..f4e726d 100644 --- a/voiceex/voice_ex.py +++ b/voiceex/voice_ex.py @@ -135,11 +135,12 @@ def extract_text_and_voice(self, data: t.Dict[int, t.List[m.VoiceBaseInfo]], out continue for i in stories[voice_ab_hash]: - try: + def _ex(): save_name = extractor.ExtractAudioFromCueId( f"{self.save_path}/{i.story_resource_name}", "", i.CueId, i.gender ) - save_text = i.Text.replace("\r\n", " ").replace("\n", " ").replace("\r", " ").replace("|", " ") + save_text = i.Text.replace("\r\n", " ").replace("\n", " ").replace("\r", " ").replace("|", + " ") log.logger(f"{save_name} {save_text}", debug=True) if not output_multi: out_file.write(f"{save_name[len(self.save_path) + 1:]}|{save_text}\n") @@ -147,6 +148,15 @@ def extract_text_and_voice(self, data: t.Dict[int, t.List[m.VoiceBaseInfo]], out out_file.write(f"{save_name[len(self.save_path) + 1:]}|" f"{self.multi_char_out_ids.get(char_id, char_id)}|" f"{save_text}\n") + try: + _ex() + except ures.InvalidDataException: + log.logger(f"InvalidData: {voice_ab_hash} - {bundle_name}", error=True) + if self.download_missing_voice_files: + log.logger(f"Try redownloading: {voice_ab_hash} - {bundle_name}", warning=True) + self.download_sound(voice_ab_hash, bundle_name) + log.logger(f"Download success: {bundle_name}") + _ex() except BaseException as e: log.logger(f"Exception occurred when extract story text: {e}", error=True) extractor.Close()