3
3
using UnityEngine ;
4
4
using Cysharp . Threading . Tasks ;
5
5
using VRM ;
6
+ using Newtonsoft . Json . Linq ;
6
7
using ChatdollKit . IO ;
7
8
using ChatdollKit . Model ;
8
9
using ChatdollKit . Dialog ;
@@ -89,17 +90,27 @@ private async UniTask HandleExternalMessage(ExternalInboundMessage message)
89
90
90
91
else if ( message . Operation == "appearance" )
91
92
{
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" ] ) ;
94
95
modelController . AvatarModel . transform . position = new Vector3 ( positionX , 0 , 0 ) ;
95
96
modelController . AvatarModel . transform . rotation = Quaternion . Euler ( 0 , rotationY , 0 ) ;
96
97
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" ] ) ;
100
101
mainCamera . transform . position = new Vector3 ( 0 , cameraPositionY , 2 ) ;
101
102
mainCamera . transform . rotation = Quaternion . Euler ( cameraRotationX , 180 , 0 ) ;
102
103
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
+ }
103
114
}
104
115
}
105
116
@@ -125,26 +136,56 @@ private async UniTask HandleExternalMessage(ExternalInboundMessage message)
125
136
{
126
137
if ( message . Operation == "activate" )
127
138
{
139
+ var speechSynthesizerName = ( ( string ) message . Payloads [ "name" ] ) . ToLower ( ) ;
128
140
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
+ }
129
158
}
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" )
141
160
{
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
+ }
148
189
}
149
190
}
150
191
@@ -156,7 +197,7 @@ private async UniTask HandleExternalMessage(ExternalInboundMessage message)
156
197
var name = ( ( string ) message . Payloads [ "name" ] ) . ToLower ( ) ;
157
198
var apiKey = message . Payloads . ContainsKey ( "api_key" ) ? ( string ) message . Payloads [ "api_key" ] : null ;
158
199
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 ;
160
201
161
202
if ( name == "chatgpt" )
162
203
{
0 commit comments