Skip to content

Commit 208775a

Browse files
Yulin LiCopilot
andcommitted
[VoiceLive] Remove redundant speech-start response cancellations
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent f042688 commit 208775a

6 files changed

Lines changed: 4 additions & 29 deletions

File tree

samples/voicelive/agent-voice-assistant/AgentVoiceAssistant.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private async Task ProcessEventsAsync(CancellationToken cancellationToken)
106106
{
107107
await foreach (SessionUpdate update in _session!.GetUpdatesAsync(cancellationToken).ConfigureAwait(false))
108108
{
109-
await HandleUpdateAsync(update, cancellationToken).ConfigureAwait(false);
109+
await HandleUpdateAsync(update).ConfigureAwait(false);
110110
}
111111
}
112112
catch (OperationCanceledException)
@@ -115,7 +115,7 @@ private async Task ProcessEventsAsync(CancellationToken cancellationToken)
115115
}
116116
}
117117

118-
private async Task HandleUpdateAsync(SessionUpdate update, CancellationToken cancellationToken)
118+
private async Task HandleUpdateAsync(SessionUpdate update)
119119
{
120120
_logger.LogDebug("Received event: {EventType}", update.GetType().Name);
121121

@@ -143,8 +143,6 @@ private async Task HandleUpdateAsync(SessionUpdate update, CancellationToken can
143143
if (_audioProcessor != null)
144144
await _audioProcessor.StopPlaybackAsync().ConfigureAwait(false);
145145

146-
try { await _session!.CancelResponseAsync(cancellationToken).ConfigureAwait(false); }
147-
catch (Exception ex) { _logger.LogDebug(ex, "No response to cancel"); }
148146
break;
149147

150148
case SessionUpdateInputAudioBufferSpeechStopped:

samples/voicelive/basic-voice-assistant/BasicVoiceAssistant.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace Azure.AI.VoiceLive.Samples;
1111
/// <remarks>
1212
/// This sample now demonstrates some of the new convenience methods added to the VoiceLive SDK:
1313
/// - ClearStreamingAudioAsync() - Clears all input audio currently being streamed
14-
/// - CancelResponseAsync() - Cancels the current response generation (existing method)
1514
/// - ConfigureSessionAsync() - Configures session options (existing method)
1615
///
1716
/// Additional convenience methods available but not shown in this sample:
@@ -208,16 +207,6 @@ private async Task HandleSessionUpdateAsync(SessionUpdate serverEvent, Cancellat
208207
await _audioProcessor.StopPlaybackAsync().ConfigureAwait(false);
209208
}
210209

211-
// Cancel any ongoing response
212-
try
213-
{
214-
await _session!.CancelResponseAsync(cancellationToken).ConfigureAwait(false);
215-
}
216-
catch (Exception ex)
217-
{
218-
_logger.LogDebug(ex, "No response to cancel");
219-
}
220-
221210
// Demonstrate the new ClearStreamingAudio convenience method
222211
try
223212
{

samples/voicelive/basic-voice-assistant/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ This sample now demonstrates some of the new convenience methods added to the Vo
2020
**Used in this sample:**
2121
- `ClearStreamingAudioAsync()` - Clears all input audio currently being streamed
2222
- `ConfigureSessionAsync()` - Configures conversation session options
23-
- `CancelResponseAsync()` - Cancels the current response generation
2423
- `SendInputAudioAsync()` - Sends audio data to the service
2524

2625
**Additional convenience methods available:**

samples/voicelive/customer-service-bot/CustomerServiceBot.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,6 @@ private async Task HandleSessionUpdateAsync(SessionUpdate serverEvent, Cancellat
413413
await _audioProcessor.StopPlaybackAsync().ConfigureAwait(false);
414414
}
415415

416-
// Cancel any ongoing response
417-
try
418-
{
419-
await _session!.CancelResponseAsync(cancellationToken).ConfigureAwait(false);
420-
}
421-
catch (Exception ex)
422-
{
423-
_logger.LogDebug(ex, "No response to cancel");
424-
}
425416
break;
426417

427418
case SessionUpdateInputAudioBufferSpeechStopped speechStopped:

samples/voicelive/mcp-voice-assistant/MCPVoiceAssistant.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ private async Task HandleUpdateAsync(SessionUpdate update, CancellationToken can
205205
if (_audioProcessor != null)
206206
await _audioProcessor.StopPlaybackAsync().ConfigureAwait(false);
207207

208-
try { await _session!.CancelResponseAsync(cancellationToken).ConfigureAwait(false); }
209-
catch (Exception ex) { _logger.LogDebug(ex, "No response to cancel"); }
210208
break;
211209

212210
case SessionUpdateInputAudioBufferSpeechStopped:

sdk/voicelive/Azure.AI.VoiceLive/tests/BasicVoiceAssistantLogicTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public override async Task ClearStreamingAudioAsync(CancellationToken cancellati
101101
}
102102

103103
[Test]
104-
public void SpeechStartedEvent_CancelsResponseAndClearsStreamingAudio()
104+
public void SpeechStartedEvent_StopsPlaybackAndClearsStreaming()
105105
{
106106
// This test demonstrates how BasicVoiceAssistant.HandleSessionUpdateAsync would be tested
107107
// if the samples were accessible from the test project.
@@ -112,7 +112,7 @@ public void SpeechStartedEvent_CancelsResponseAndClearsStreamingAudio()
112112
"1. Add project reference to BasicVoiceAssistant sample in test project, OR " +
113113
"2. Move BasicVoiceAssistant to the main SDK with dependency injection support. " +
114114
"Expected behavior: SessionUpdateInputAudioBufferSpeechStarted should call " +
115-
"CancelResponseAsync(), ClearStreamingAudioAsync(), and StopPlaybackAsync().");
115+
"StopPlaybackAsync() and ClearStreamingAudioAsync(), but not CancelResponseAsync().");
116116
}
117117

118118
[Test]

0 commit comments

Comments
 (0)