Skip to content

Commit 0a974f3

Browse files
authored
Merge pull request #397 from uezo/demo-for-v0.8.7
Update demo for v0.8.7
2 parents 0709320 + 4e39832 commit 0a974f3

11 files changed

+1593
-1779
lines changed

Diff for: Demo/AITuber/AITuber.unity

+1,486-62
Large diffs are not rendered by default.

Diff for: Demo/AITuber/AITuberMessageHandler.cs

+64-23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using Cysharp.Threading.Tasks;
55
using VRM;
6+
using Newtonsoft.Json.Linq;
67
using ChatdollKit.IO;
78
using ChatdollKit.Model;
89
using ChatdollKit.Dialog;
@@ -89,17 +90,27 @@ private async UniTask HandleExternalMessage(ExternalInboundMessage message)
8990

9091
else if (message.Operation == "appearance")
9192
{
92-
var positionX = (float)(double)message.Payloads["position_x"];
93-
var rotationY = (float)(double)message.Payloads["rotation_y"];
93+
var positionX = Convert.ToSingle(message.Payloads["position_x"]);
94+
var rotationY = Convert.ToSingle(message.Payloads["rotation_y"]);
9495
modelController.AvatarModel.transform.position = new Vector3(positionX, 0, 0);
9596
modelController.AvatarModel.transform.rotation = Quaternion.Euler(0, rotationY, 0);
9697

97-
var cameraPositionY = (float)(double)message.Payloads["camera_position_y"];
98-
var cameraRotationX = (float)(double)message.Payloads["camera_rotation_x"];
99-
var cameraFieldOfView = (float)(double)message.Payloads["camera_field_of_view"];
98+
var cameraPositionY = Convert.ToSingle(message.Payloads["camera_position_y"]);
99+
var cameraRotationX = Convert.ToSingle(message.Payloads["camera_rotation_x"]);
100+
var cameraFieldOfView = Convert.ToSingle(message.Payloads["camera_field_of_view"]);
100101
mainCamera.transform.position = new Vector3(0, cameraPositionY, 2);
101102
mainCamera.transform.rotation = Quaternion.Euler(cameraRotationX, 180, 0);
102103
mainCamera.fieldOfView = cameraFieldOfView;
104+
105+
if (message.Payloads.ContainsKey("camera_background_color"))
106+
{
107+
var bgString = (string)message.Payloads["camera_background_color"];
108+
if (ColorUtility.TryParseHtmlString(bgString.StartsWith("#") ? bgString : "#" + bgString, out Color color))
109+
{
110+
color.a = 1.0f;
111+
mainCamera.backgroundColor = color;
112+
}
113+
}
103114
}
104115
}
105116

@@ -125,26 +136,56 @@ private async UniTask HandleExternalMessage(ExternalInboundMessage message)
125136
{
126137
if (message.Operation == "activate")
127138
{
139+
var speechSynthesizerName = ((string)message.Payloads["name"]).ToLower();
128140

141+
if (speechSynthesizerName == "voicevox")
142+
{
143+
styleBertVits2SpeechSynthesizer.IsEnabled = false;
144+
voicevoxSpeechSynthesizer.IsEnabled = true;
145+
voicevoxSpeechSynthesizer.EndpointUrl = (string)message.Payloads["url"];
146+
voicevoxSpeechSynthesizer.Speaker = int.Parse($"{message.Payloads["voicevox_speaker"]}");
147+
modelController.SpeechSynthesizerFunc = voicevoxSpeechSynthesizer.GetAudioClipAsync;
148+
}
149+
else if (speechSynthesizerName == "style-bert-vits2")
150+
{
151+
voicevoxSpeechSynthesizer.IsEnabled = false;
152+
styleBertVits2SpeechSynthesizer.IsEnabled = true;
153+
styleBertVits2SpeechSynthesizer.EndpointUrl = (string)message.Payloads["url"];
154+
styleBertVits2SpeechSynthesizer.ModelId = int.Parse($"{message.Payloads["sbv2_model_id"]}");
155+
styleBertVits2SpeechSynthesizer.SpeakerId = int.Parse($"{message.Payloads["sbv2_speaker_id"]}");
156+
modelController.SpeechSynthesizerFunc = styleBertVits2SpeechSynthesizer.GetAudioClipAsync;
157+
}
129158
}
130-
var speechSynthesizerName = ((string)message.Payloads["name"]).ToLower();
131-
132-
if (speechSynthesizerName == "voicevox")
133-
{
134-
styleBertVits2SpeechSynthesizer.IsEnabled = false;
135-
voicevoxSpeechSynthesizer.IsEnabled = true;
136-
voicevoxSpeechSynthesizer.EndpointUrl = (string)message.Payloads["url"];
137-
voicevoxSpeechSynthesizer.Speaker = int.Parse($"{message.Payloads["voicevox_speaker"]}");
138-
modelController.SpeechSynthesizerFunc = voicevoxSpeechSynthesizer.GetAudioClipAsync;
139-
}
140-
else if (speechSynthesizerName == "style-bert-vits2")
159+
else if (message.Operation == "styles")
141160
{
142-
voicevoxSpeechSynthesizer.IsEnabled = false;
143-
styleBertVits2SpeechSynthesizer.IsEnabled = true;
144-
styleBertVits2SpeechSynthesizer.EndpointUrl = (string)message.Payloads["url"];
145-
styleBertVits2SpeechSynthesizer.ModelId = int.Parse($"{message.Payloads["sbv2_model_id"]}");
146-
styleBertVits2SpeechSynthesizer.SpeakerId = int.Parse($"{message.Payloads["sbv2_speaker_id"]}");
147-
modelController.SpeechSynthesizerFunc = styleBertVits2SpeechSynthesizer.GetAudioClipAsync;
161+
if (styleBertVits2SpeechSynthesizer.IsEnabled)
162+
{
163+
var styles = ((JObject)message.Payloads["styles"]).ToObject<Dictionary<string, string>>();
164+
styleBertVits2SpeechSynthesizer.VoiceStyles.Clear();
165+
foreach (var style in styles)
166+
{
167+
styleBertVits2SpeechSynthesizer.VoiceStyles.Add(
168+
new StyleBertVits2SpeechSynthesizer.VoiceStyle() {
169+
VoiceStyleValue = style.Key,
170+
StyleBertVITSStyle = style.Value
171+
}
172+
);
173+
}
174+
}
175+
else if (voicevoxSpeechSynthesizer.IsEnabled)
176+
{
177+
var styles = ((JObject)message.Payloads["styles"]).ToObject<Dictionary<string, int>>();
178+
voicevoxSpeechSynthesizer.VoiceStyles.Clear();
179+
foreach (var style in styles)
180+
{
181+
voicevoxSpeechSynthesizer.VoiceStyles.Add(
182+
new VoicevoxSpeechSynthesizer.VoiceStyle() {
183+
VoiceStyleValue = style.Key,
184+
VoiceVoxSpeaker = style.Value
185+
}
186+
);
187+
}
188+
}
148189
}
149190
}
150191

@@ -156,7 +197,7 @@ private async UniTask HandleExternalMessage(ExternalInboundMessage message)
156197
var name = ((string)message.Payloads["name"]).ToLower();
157198
var apiKey = message.Payloads.ContainsKey("api_key") ? (string)message.Payloads["api_key"] : null;
158199
var model = message.Payloads.ContainsKey("model") ? (string)message.Payloads["model"] : null;
159-
var temperature = message.Payloads.ContainsKey("temperature") ? (float)(double)message.Payloads["temperature"] : -1;
200+
var temperature = message.Payloads.ContainsKey("temperature") ? Convert.ToSingle(message.Payloads["temperature"]) : -1;
160201

161202
if (name == "chatgpt")
162203
{

Diff for: Demo/AITuber/FileLogger.cs

+19
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ private void HandleLog(string logString, string stackTrace, LogType type)
6161
writer.WriteLine(message);
6262
}
6363

64+
public void OpenLogFile()
65+
{
66+
try
67+
{
68+
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
69+
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
70+
{
71+
FileName = logFilePath,
72+
UseShellExecute = true
73+
});
74+
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
75+
System.Diagnostics.Process.Start("open", $"\"{logFilePath}\"");
76+
#endif
77+
}
78+
catch (Exception ex)
79+
{
80+
Debug.LogError($"Error in opening log file: {ex.Message}");
81+
}
82+
}
6483
private void OnDestroy()
6584
{
6685
Application.logMessageReceived -= HandleLog;

Diff for: Demo/AITuber/MainAITuber.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using UnityEngine;
22
using ChatdollKit.Model;
33
using ChatdollKit.Dialog;
4+
using Cysharp.Threading.Tasks;
45

56
namespace ChatdollKit.Demo
67
{
@@ -22,6 +23,9 @@ public class MainAITuber : MonoBehaviour
2223
[TextArea(1, 6)]
2324
public string AutoPilotRequestText;
2425

26+
[SerializeField]
27+
private GameObject licensePanel;
28+
2529
private void Start()
2630
{
2731
// Get ChatdollKit components
@@ -45,8 +49,12 @@ private void Start()
4549

4650
// Add handler for auto pilot
4751
aiTuberMessageHandler.AddHandler("dialog", "auto_pilot", async (message) => {
48-
autoPilot = (bool)message.Payloads["is_on"];
49-
Debug.LogWarning($"auto_pilog: {autoPilot}");
52+
if (message.Payloads == null) return;
53+
54+
if (message.Payloads.ContainsKey("is_on"))
55+
{
56+
autoPilot = (bool)message.Payloads["is_on"];
57+
}
5058
if (message.Payloads.ContainsKey("auto_pilot_request"))
5159
{
5260
AutoPilotRequestText = (string)message.Payloads["auto_pilot_request"];
@@ -66,5 +74,10 @@ private void Update()
6674
}
6775
}
6876
}
77+
78+
public void OnLicenseButton()
79+
{
80+
licensePanel.SetActive(!licensePanel.activeSelf);
81+
}
6982
}
7083
}

0 commit comments

Comments
 (0)