Skip to content

Commit 9542c54

Browse files
committed
Add snippets to solution and make sure they build
1 parent 2876acf commit 9542c54

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

sdk/ai/Azure.AI.VoiceLive/Azure.AI.VoiceLive.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicVoiceAssistant", "samp
1212
EndProject
1313
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomerServiceBot", "samples\CustomerServiceBot\CustomerServiceBot.csproj", "{0821FA24-C459-5CC2-DB1B-2F755A9B3148}"
1414
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.VoiceLive.Snippets", "samples\snippets\Azure.AI.VoiceLive.Snippets.csproj", "{1694BF5F-7AE7-9D41-44E7-A50680B5CA40}"
16+
EndProject
1517
Global
1618
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1719
Debug|Any CPU = Debug|Any CPU
@@ -38,6 +40,10 @@ Global
3840
{0821FA24-C459-5CC2-DB1B-2F755A9B3148}.Debug|Any CPU.Build.0 = Debug|Any CPU
3941
{0821FA24-C459-5CC2-DB1B-2F755A9B3148}.Release|Any CPU.ActiveCfg = Release|Any CPU
4042
{0821FA24-C459-5CC2-DB1B-2F755A9B3148}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{1694BF5F-7AE7-9D41-44E7-A50680B5CA40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44+
{1694BF5F-7AE7-9D41-44E7-A50680B5CA40}.Debug|Any CPU.Build.0 = Debug|Any CPU
45+
{1694BF5F-7AE7-9D41-44E7-A50680B5CA40}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{1694BF5F-7AE7-9D41-44E7-A50680B5CA40}.Release|Any CPU.Build.0 = Release|Any CPU
4147
EndGlobalSection
4248
GlobalSection(SolutionProperties) = preSolution
4349
HideSolutionNode = FALSE

sdk/ai/Azure.AI.VoiceLive/samples/snippets/BasicUsageSnippets.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task BasicVoiceAssistantExample()
2626
VoiceLiveClient client = new VoiceLiveClient(endpoint, credential);
2727

2828
// Start a new session
29-
VoiceLiveSession session = await client.StartSessionAsync();
29+
VoiceLiveSession session = await client.StartSessionAsync().ConfigureAwait(false);
3030

3131
// Configure session for voice conversation
3232
ConversationSessionOptions sessionOptions = new ConversationSessionOptions()
@@ -49,10 +49,10 @@ public async Task BasicVoiceAssistantExample()
4949
sessionOptions.Modalities.Add(InputModality.Text);
5050
sessionOptions.Modalities.Add(InputModality.Audio);
5151

52-
await session.ConfigureConversationSessionAsync(sessionOptions);
52+
await session.ConfigureConversationSessionAsync(sessionOptions).ConfigureAwait(false);
5353

5454
// Process events from the session
55-
await foreach (ServerEvent serverEvent in session.ReceiveEventsAsync())
55+
await foreach (ServerEvent serverEvent in session.GetUpdatesAsync().ConfigureAwait(false))
5656
{
5757
if (serverEvent is ServerEventResponseAudioDelta audioDelta)
5858
{
@@ -77,16 +77,15 @@ public async Task AdvancedVoiceConfiguration()
7777
Uri endpoint = new Uri("https://your-resource.cognitiveservices.azure.com");
7878
DefaultAzureCredential credential = new DefaultAzureCredential();
7979
VoiceLiveClient client = new VoiceLiveClient(endpoint, credential);
80-
VoiceLiveSession session = await client.StartSessionAsync();
80+
VoiceLiveSession session = await client.StartSessionAsync().ConfigureAwait(false);
8181

8282
#region Snippet:AdvancedVoiceConfiguration
8383
ConversationSessionOptions sessionOptions = new ConversationSessionOptions()
8484
{
8585
Model = "gpt-4o-realtime-preview",
8686
Instructions = "You are a customer service representative. Be helpful and professional.",
87-
Voice = new AzureCustomVoice("your-custom-voice-name", AzureCustomVoiceType.AzureCustom)
87+
Voice = new AzureCustomVoice("your-custom-voice-name", "your-custom-voice-endpoint-id", AzureCustomVoiceType.AzureCustom)
8888
{
89-
EndpointId = "your-custom-voice-endpoint-id",
9089
Temperature = 0.8f
9190
},
9291
TurnDetection = new AzureSemanticVad()
@@ -104,7 +103,7 @@ public async Task AdvancedVoiceConfiguration()
104103
sessionOptions.Modalities.Add(InputModality.Text);
105104
sessionOptions.Modalities.Add(InputModality.Audio);
106105

107-
await session.ConfigureConversationSessionAsync(sessionOptions);
106+
await session.ConfigureConversationSessionAsync(sessionOptions).ConfigureAwait(false);
108107
#endregion
109108
}
110109

@@ -116,13 +115,12 @@ public async Task FunctionCallingExample()
116115
Uri endpoint = new Uri("https://your-resource.cognitiveservices.azure.com");
117116
DefaultAzureCredential credential = new DefaultAzureCredential();
118117
VoiceLiveClient client = new VoiceLiveClient(endpoint, credential);
119-
VoiceLiveSession session = await client.StartSessionAsync();
118+
VoiceLiveSession session = await client.StartSessionAsync().ConfigureAwait(false);
120119

121120
#region Snippet:FunctionCallingExample
122121
// Define a function for the assistant to call
123-
var getCurrentWeatherFunction = new FunctionTool
122+
var getCurrentWeatherFunction = new FunctionTool("get_current_weather")
124123
{
125-
Name = "get_current_weather",
126124
Description = "Get the current weather for a given location",
127125
Parameters = BinaryData.FromString("""
128126
{
@@ -155,8 +153,8 @@ public async Task FunctionCallingExample()
155153
sessionOptions.Modalities.Add(InputModality.Text);
156154
sessionOptions.Modalities.Add(InputModality.Audio);
157155

158-
await session.ConfigureConversationSessionAsync(sessionOptions);
156+
await session.ConfigureConversationSessionAsync(sessionOptions).ConfigureAwait(false);
159157
#endregion
160158
}
161159
}
162-
}
160+
}

0 commit comments

Comments
 (0)