@@ -15,53 +15,64 @@ import 'api.dart';
15
15
import 'content.dart' ;
16
16
import 'error.dart' ;
17
17
18
- /// The available voice options for speech synthesis.
19
- enum Voice {
18
+ /// Configuration for a prebuilt voice.
19
+ ///
20
+ /// This class allows specifying a voice by its name.
21
+ class PrebuiltVoiceConfig {
20
22
// ignore: public_member_api_docs
21
- aoede ( 'Aoede' ),
23
+ const PrebuiltVoiceConfig ({ this .voiceName});
22
24
25
+ /// The voice name to use for speech synthesis.
26
+ ///
27
+ /// See https://cloud.google.com/text-to-speech/docs/chirp3-hd for names and
28
+ /// sound demos.
29
+ final String ? voiceName;
23
30
// ignore: public_member_api_docs
24
- charon ('Charon' ),
31
+ Map <String , Object ?> toJson () =>
32
+ {if (voiceName case final voiceName? ) 'voice_name' : voiceName};
33
+ }
25
34
35
+ /// Configuration for the voice to be used in speech synthesis.
36
+ ///
37
+ /// This class currently supports using a prebuilt voice configuration.
38
+ class VoiceConfig {
26
39
// ignore: public_member_api_docs
27
- fenrir ( 'Fenrir' ),
40
+ VoiceConfig ({ this .prebuiltVoiceConfig});
28
41
29
42
// ignore: public_member_api_docs
30
- kore ('Kore' ),
31
-
43
+ final PrebuiltVoiceConfig ? prebuiltVoiceConfig;
32
44
// ignore: public_member_api_docs
33
- puck ('Puck' );
34
-
35
- const Voice (this ._jsonString);
36
- final String _jsonString;
37
-
38
- // ignore: public_member_api_docs
39
- String toJson () => _jsonString;
45
+ Map <String , Object ?> toJson () => {
46
+ if (prebuiltVoiceConfig case final prebuiltVoiceConfig? )
47
+ 'prebuilt_voice_config' : prebuiltVoiceConfig.toJson ()
48
+ };
40
49
}
41
50
42
51
/// Configures speech synthesis settings.
52
+ ///
53
+ /// Allows specifying the desired voice for speech synthesis.
43
54
class SpeechConfig {
44
55
/// Creates a [SpeechConfig] instance.
45
56
///
46
- /// [voice] (optional): The desired voice for speech synthesis.
47
- SpeechConfig ({this .voice});
48
-
49
- /// The voice to use for speech synthesis.
50
- final Voice ? voice;
57
+ /// [voiceName] See https://cloud.google.com/text-to-speech/docs/chirp3-hd
58
+ /// for names and sound demos.
59
+ SpeechConfig ({String ? voiceName})
60
+ : voiceConfig = voiceName != null
61
+ ? VoiceConfig (
62
+ prebuiltVoiceConfig: PrebuiltVoiceConfig (voiceName: voiceName))
63
+ : null ;
64
+
65
+ /// The voice config to use for speech synthesis.
66
+ final VoiceConfig ? voiceConfig;
51
67
// ignore: public_member_api_docs
52
68
Map <String , Object ?> toJson () => {
53
- if (voice case final voice? )
54
- 'voice_config' : {
55
- 'prebuilt_voice_config' : {'voice_name' : voice.toJson ()}
56
- }
69
+ if (voiceConfig case final voiceConfig? )
70
+ 'voice_config' : voiceConfig.toJson ()
57
71
};
58
72
}
59
73
60
74
/// The available response modalities.
61
75
enum ResponseModalities {
62
- /// Unspecified response modality.
63
- unspecified ('MODALITY_UNSPECIFIED' ),
64
-
65
76
/// Text response modality.
66
77
text ('TEXT' ),
67
78
@@ -132,6 +143,7 @@ class LiveServerContent implements LiveServerMessage {
132
143
/// [interrupted] (optional): Indicates if the generation was interrupted.
133
144
LiveServerContent ({this .modelTurn, this .turnComplete, this .interrupted});
134
145
146
+ // TODO(cynthia): Add accessor for media content
135
147
/// The content generated by the model.
136
148
final Content ? modelTurn;
137
149
@@ -176,6 +188,19 @@ class LiveServerToolCallCancellation implements LiveServerMessage {
176
188
final List <String >? functionIds;
177
189
}
178
190
191
+ /// A single response chunk received during a live content generation.
192
+ ///
193
+ /// It can contain generated content, function calls to be executed, or
194
+ /// instructions to cancel previous function calls, along with the status of the
195
+ /// ongoing generation.
196
+ class LiveServerResponse {
197
+ // ignore: public_member_api_docs
198
+ LiveServerResponse ({required this .message});
199
+
200
+ /// The server message generated by the live model.
201
+ final LiveServerMessage message;
202
+ }
203
+
179
204
/// Represents realtime input from the client in a live stream.
180
205
class LiveClientRealtimeInput {
181
206
/// Creates a [LiveClientRealtimeInput] instance.
@@ -237,7 +262,7 @@ class LiveClientToolResponse {
237
262
};
238
263
}
239
264
240
- /// Parses a JSON object received from the live server into a [LiveServerMessage ] .
265
+ /// Parses a JSON object received from the live server into a [LiveServerResponse ] .
241
266
///
242
267
/// This function handles different types of server messages, including:
243
268
/// - Error messages, which result in a [VertexAIException] being thrown.
@@ -275,8 +300,13 @@ class LiveClientToolResponse {
275
300
/// - [jsonObject] : The JSON object received from the live server.
276
301
///
277
302
/// Returns:
278
- /// - A [LiveServerMessage] object representing the parsed message.
279
- LiveServerMessage parseServerMessage (Object jsonObject) {
303
+ /// - A [LiveServerResponse] object representing the parsed message.
304
+ LiveServerResponse parseServerResponse (Object jsonObject) {
305
+ LiveServerMessage message = _parseServerMessage (jsonObject);
306
+ return LiveServerResponse (message: message);
307
+ }
308
+
309
+ LiveServerMessage _parseServerMessage (Object jsonObject) {
280
310
if (jsonObject case {'error' : final Object error}) {
281
311
throw parseError (error);
282
312
}
0 commit comments