-
Notifications
You must be signed in to change notification settings - Fork 6
/
VADSample.cs
59 lines (51 loc) · 1.66 KB
/
VADSample.cs
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
50
51
52
53
54
55
56
57
58
59
#nullable enable
using System;
using UniRx;
using Unity.Logging;
using UnityEngine;
namespace Mochineko.VoiceActivityDetection.Samples
{
/// <summary>
/// A sample of voice activity detection as a component.
/// Input UnityEngine.Microphone and output only log.
/// </summary>
internal sealed class VADSample : MonoBehaviour
{
[SerializeField]
private VADParameters? parameters = null;
private IVoiceActivityDetector? vad;
private UnityMicrophoneProxy? proxy;
private void Start()
{
if (parameters == null)
{
throw new NullReferenceException(nameof(parameters));
}
proxy = new UnityMicrophoneProxy();
vad = new QueueingVoiceActivityDetector(
source: new UnityMicrophoneSource(proxy),
buffer: new NullVoiceBuffer(),
parameters.MaxQueueingTimeSeconds,
parameters.MinQueueingTimeSeconds,
parameters.ActiveVolumeThreshold,
parameters.ActivationRateThreshold,
parameters.InactivationRateThreshold,
parameters.ActivationIntervalSeconds,
parameters.InactivationIntervalSeconds,
parameters.MaxActiveDurationSeconds);
vad
.VoiceIsActive
.Subscribe(isActive => Log.Info("[VAD.Sample] IsActive: {0}", isActive))
.AddTo(this);
}
private void OnDestroy()
{
vad?.Dispose();
proxy?.Dispose();
}
private void Update()
{
vad?.Update();
}
}
}