From 1a5930e1b989d80e10ac0d6e1f5dd2a7d57e942b Mon Sep 17 00:00:00 2001 From: uezo Date: Sat, 1 Aug 2020 21:28:28 +0900 Subject: [PATCH] Enable to play AnimatedSay from JSON --- ChatdollKit/Scripts/Model/ModelController.cs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ChatdollKit/Scripts/Model/ModelController.cs b/ChatdollKit/Scripts/Model/ModelController.cs index 3c45e86..ea4d665 100644 --- a/ChatdollKit/Scripts/Model/ModelController.cs +++ b/ChatdollKit/Scripts/Model/ModelController.cs @@ -231,6 +231,30 @@ public async Task AnimatedSay(AnimatedVoiceRequest request, CancellationToken to } } + // AnimatedSay from JSON file + public async Task AnimatedSay(string filePath, CancellationToken token) + { + AnimatedVoiceRequest animatedVoiceRequest; + + try + { + var jsonString = string.Empty; + using (var reader = File.OpenText(filePath)) + { + jsonString = await reader.ReadToEndAsync(); + } + + animatedVoiceRequest = JsonConvert.DeserializeObject(jsonString); + } + catch (Exception ex) + { + Debug.LogError($"Error occured in AnimatedSay from file {filePath}: {ex.Message}\n{ex.StackTrace}"); + return; + } + + await AnimatedSay(animatedVoiceRequest, token); + } + // Speak one phrase public async Task Say(string voiceName, float preGap = 0f, float postGap = 0f) {