Skip to content

Commit 0d3759e

Browse files
committed
Update samples
1 parent 8dca68e commit 0d3759e

File tree

5 files changed

+79
-55
lines changed

5 files changed

+79
-55
lines changed

sdk/ai/Azure.AI.VoiceLive/samples/BasicVoiceAssistant/AudioProcessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ public Task StartCaptureAsync()
103103

104104
_waveIn.DataAvailable += OnAudioDataAvailable;
105105
_waveIn.RecordingStopped += OnRecordingStopped;
106-
106+
/*
107107
_logger.LogInformation($"There are {WaveIn.DeviceCount} devices available.");
108108
for (int i = 0; i < WaveIn.DeviceCount; i++)
109109
{
110110
var deviceInfo = WaveIn.GetCapabilities(i);
111111
112112
_logger.LogInformation($"{i}: {deviceInfo.ProductName}");
113113
}
114+
*/
114115
_waveIn.DeviceNumber = 1;
115116

116117
_waveIn.StartRecording();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
diff --git a/AudioProcessor.cs b/AudioProcessor.cs
2+
index e69de29..b7f2c3a 100644
3+
--- a/AudioProcessor.cs
4+
+++ b/AudioProcessor.cs
5+
@@ -101,19 +101,12 @@ public class AudioProcessor : IDisposable
6+
};
7+
8+
_waveIn.DataAvailable += OnAudioDataAvailable;
9+
_waveIn.RecordingStopped += OnRecordingStopped;
10+
- /*
11+
- _logger.LogInformation($"There are {WaveIn.DeviceCount} devices available.");
12+
- for (int i = 0; i < WaveIn.DeviceCount; i++)
13+
- {
14+
- var deviceInfo = WaveIn.GetCapabilities(i);
15+
-
16+
- _logger.LogInformation($"{i}: {deviceInfo.ProductName}");
17+
- }
18+
- */
19+
- _waveIn.DeviceNumber = 1;
20+
+ // Use default input device (platform-agnostic)
21+
22+
_waveIn.StartRecording();
23+
24+
// Start audio send task
25+
_audioSendTask = ProcessAudioSendAsync(_cancellationTokenSource.Token);
26+
@@ -171,7 +164,7 @@ public class AudioProcessor : IDisposable
27+
try
28+
{
29+
_waveOut = new WaveOutEvent
30+
{
31+
- DesiredLatency = 100 // 100ms latency
32+
+ DesiredLatency = 100 // 100ms latency
33+
};
34+
35+
_playbackBuffer = new BufferedWaveProvider(new WaveFormat(SampleRate, BitsPerSample, Channels))
36+
{
37+
BufferDuration = TimeSpan.FromMinutes(5), // 5 second buffer

sdk/ai/Azure.AI.VoiceLive/samples/BasicVoiceAssistant/SampleProgram.cs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -223,42 +223,34 @@ private static bool CheckAudioSystem(ILogger logger)
223223
{
224224
try
225225
{
226-
// Check for input devices
227-
int inputDeviceCount = 0;
228-
int outputDeviceCount = 0;
229-
230-
for (int i = 0; i < WaveIn.DeviceCount; i++)
226+
// Try input (default device)
227+
using (var waveIn = new WaveInEvent
231228
{
232-
var capabilities = NAudio.Wave.WaveIn.GetCapabilities(i);
233-
if (capabilities.Channels > 0)
234-
{
235-
inputDeviceCount++;
236-
}
237-
}
238-
239-
for (int i = 0; i < NAudio.Wave.WaveOut.DeviceCount; i++)
229+
WaveFormat = new WaveFormat(24000, 16, 1),
230+
BufferMilliseconds = 50
231+
})
240232
{
241-
var capabilities = NAudio.Wave.WaveOut.GetCapabilities(i);
242-
if (capabilities.Channels > 0)
243-
{
244-
outputDeviceCount++;
245-
}
233+
// Start/Stop to force initialization and surface any device errors
234+
waveIn.DataAvailable += (_, __) => { };
235+
waveIn.StartRecording();
236+
waveIn.StopRecording();
246237
}
247238

248-
if (inputDeviceCount == 0)
239+
// Try output (default device)
240+
var buffer = new BufferedWaveProvider(new WaveFormat(24000, 16, 1))
249241
{
250-
Console.WriteLine("❌ No audio input devices found. Please check your microphone.");
251-
return false;
252-
}
242+
BufferDuration = TimeSpan.FromMilliseconds(200)
243+
};
253244

254-
if (outputDeviceCount == 0)
245+
using (var waveOut = new WaveOutEvent { DesiredLatency = 100 })
255246
{
256-
Console.WriteLine("❌ No audio output devices found. Please check your speakers.");
257-
return false;
247+
waveOut.Init(buffer);
248+
// Playing isn’t strictly required to validate a device, but it’s safe
249+
waveOut.Play();
250+
waveOut.Stop();
258251
}
259252

260-
logger.LogInformation("Audio system check passed. Found {InputDevices} input and {OutputDevices} output devices",
261-
inputDeviceCount, outputDeviceCount);
253+
logger.LogInformation("Audio system check passed (default input/output initialized).");
262254
return true;
263255
}
264256
catch (Exception ex)

sdk/ai/Azure.AI.VoiceLive/samples/CustomerServiceBot/AudioProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ public Task StartCaptureAsync()
9595
_waveIn.DataAvailable += OnAudioDataAvailable;
9696
_waveIn.RecordingStopped += OnRecordingStopped;
9797

98+
/*
9899
_logger.LogInformation($"There are {WaveIn.DeviceCount} devices available.");
99100
for (int i = 0; i < WaveIn.DeviceCount; i++)
100101
{
101102
var deviceInfo = WaveIn.GetCapabilities(i);
102103
103104
_logger.LogInformation($"{i}: {deviceInfo.ProductName}");
104105
}
106+
*/
105107
_waveIn.DeviceNumber = 0; // Default to first device
106108

107109
_waveIn.StartRecording();

sdk/ai/Azure.AI.VoiceLive/samples/CustomerServiceBot/SampleProgram.cs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -261,42 +261,34 @@ private static bool CheckAudioSystem(ILogger logger)
261261
{
262262
try
263263
{
264-
// Check for input devices
265-
int inputDeviceCount = 0;
266-
int outputDeviceCount = 0;
267-
268-
for (int i = 0; i < WaveIn.DeviceCount; i++)
264+
// Try input (default device)
265+
using (var waveIn = new WaveInEvent
269266
{
270-
var capabilities = NAudio.Wave.WaveIn.GetCapabilities(i);
271-
if (capabilities.Channels > 0)
272-
{
273-
inputDeviceCount++;
274-
}
275-
}
276-
277-
for (int i = 0; i < NAudio.Wave.WaveOut.DeviceCount; i++)
267+
WaveFormat = new WaveFormat(24000, 16, 1),
268+
BufferMilliseconds = 50
269+
})
278270
{
279-
var capabilities = NAudio.Wave.WaveOut.GetCapabilities(i);
280-
if (capabilities.Channels > 0)
281-
{
282-
outputDeviceCount++;
283-
}
271+
// Start/Stop to force initialization and surface any device errors
272+
waveIn.DataAvailable += (_, __) => { };
273+
waveIn.StartRecording();
274+
waveIn.StopRecording();
284275
}
285276

286-
if (inputDeviceCount == 0)
277+
// Try output (default device)
278+
var buffer = new BufferedWaveProvider(new WaveFormat(24000, 16, 1))
287279
{
288-
Console.WriteLine("❌ No audio input devices found. Please check your microphone.");
289-
return false;
290-
}
280+
BufferDuration = TimeSpan.FromMilliseconds(200)
281+
};
291282

292-
if (outputDeviceCount == 0)
283+
using (var waveOut = new WaveOutEvent { DesiredLatency = 100 })
293284
{
294-
Console.WriteLine("❌ No audio output devices found. Please check your speakers.");
295-
return false;
285+
waveOut.Init(buffer);
286+
// Playing isn’t strictly required to validate a device, but it’s safe
287+
waveOut.Play();
288+
waveOut.Stop();
296289
}
297290

298-
logger.LogInformation("Audio system check passed. Found {InputDevices} input and {OutputDevices} output devices",
299-
inputDeviceCount, outputDeviceCount);
291+
logger.LogInformation("Audio system check passed (default input/output initialized).");
300292
return true;
301293
}
302294
catch (Exception ex)

0 commit comments

Comments
 (0)