-
Notifications
You must be signed in to change notification settings - Fork 0
/
SketchingInputTextPreProcessor.cs
53 lines (48 loc) · 1.81 KB
/
SketchingInputTextPreProcessor.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
using Microsoft.Psi;
using Microsoft.Psi.Components;
using Microsoft.Psi.Speech;
using NU.Kiosk.SharedObject;
using log4net;
using System.Reflection;
using System;
namespace NU.Kqml
{
public class SketchingInputTextPreProcessor : ConsumerProducer<IStreamingSpeechRecognitionResult, Utterance>
{
//private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public SketchingInputTextPreProcessor(Pipeline pipeline) : base(pipeline) {}
protected override void Receive(IStreamingSpeechRecognitionResult result, Envelope e)
{
var message = result.Text.ToLower();
double confidence = result.Confidence.Value;
if (confidence < 0.3) {
Console.WriteLine($"Received Speech Input \"{message}\" with confidence {confidence}; discarding...");
message = "(Unintelligible)";
} else {
Console.WriteLine($"Received Speech Input \"{message}\" with confidence {confidence}; ");
}
switch (message)
{
case "okay":
case "hm":
case "um":
case "ah":
case "cool":
case "huh?":
case "wow!":
case "Huck you":
case "bye":
case "bye bye":
// Filter out a few things
Console.WriteLine($"Discarding message: {message}");
break;
case "":
message = "(Unintelligible)";
goto default;
default:
this.Out.Post(new Utterance(message, confidence, StringResultSource.speech), e.Time);
break;
}
}
}
}