forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioCapture.cs
More file actions
49 lines (40 loc) · 1.26 KB
/
AudioCapture.cs
File metadata and controls
49 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Voice
{
public class AudioCapture
{
public async void Start()
{
List<byte> bytes = new List<byte>();
object writeLock = new object();
bool writeMore = true;
var waveIn = new WaveInEvent();
waveIn.DeviceNumber = 0;
waveIn.WaveFormat = new WaveFormat(16000, 1);
waveIn.DataAvailable +=
(object sender, WaveInEventArgs args) =>
{
bytes.AddRange(args.Buffer);
lock (writeLock)
{
if (!writeMore) return;
}
};
waveIn.StartRecording();
Console.WriteLine("Speak now.");
await Task.Delay(TimeSpan.FromSeconds(3));
// Stop recording and shut down.
waveIn.StopRecording();
Console.WriteLine("Capture stopped.");
byte[] buffer = bytes.ToArray();
for (int i = 0; i < buffer.Length; i++)
{
Console.WriteLine($"Buffer {i} ");
}
}
}
}