Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chinosk6 committed May 14, 2023
1 parent 2639bde commit 91dddf3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
9 changes: 5 additions & 4 deletions voice extractor/voice extractor/voice_ex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public UmaVoiceEx(string acbPath, string awbPath)
}
catch (Exception ex)
{
Close();
throw new Exception($"File load failed: {ex.Message}");
}
}
Expand Down Expand Up @@ -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();
}

}
Expand Down
1 change: 1 addition & 0 deletions voiceex/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions voiceex/voice_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,28 @@ 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")
else:
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()
Expand Down

0 comments on commit 91dddf3

Please sign in to comment.