Esempio n. 1
0
            public bool OnGesture(Android.Glass.Touchpad.Gesture p0)
            {
                Log.Info("GlassPrompter", "gesture: " + p0.Name());

                if (p0 == Gesture.Tap)
                {
                    parent.curLine += 4;
                    parent.SetLines();
                    return(true);
                }

                return(false);
            }
Esempio n. 2
0
            public void OnResults(Bundle results)
            {
                Log.Info("GlassPrompter", "results");
                waitingOnNetwork = 0;

                parent.indicator.SetBackgroundColor(Color.Argb(255, 50, 50, 0));


                IList <String> matches = results.GetStringArrayList(SpeechRecognizer.ResultsRecognition);


                if (matches.Count == 0)
                {
                    Log.Info("GlassPrompter", "No matches");
                }
                else
                {
                    // try to see if anything matches, weighting things that are closer to the current known location
                    // match agtain single lines and pairs of lines, since we can't control where the spech reco decides to stop

                    List <string> texts         = new List <string>();
                    List <string> sourceMatches = new List <string>();

                    List <float> bestScores = new List <float>();
                    List <int>   lineNum    = new List <int>();
                    List <float> weights    = new List <float>();

                    for (int i = 0; i < 6; i++)
                    {
                        texts.Add(parent.scriptLines[parent.curLine + i]);
                        bestScores.Add(0f);
                        lineNum.Add(parent.curLine + i);
                        weights.Add(5f / ((float)i + 5f));
                        sourceMatches.Add("");

                        texts.Add(parent.scriptLines[parent.curLine + i] + " " + parent.scriptLines[parent.curLine + i + 1]);
                        bestScores.Add(0f);
                        lineNum.Add(parent.curLine + i + 1);
                        weights.Add(5f / ((float)i + 5.6f));
                        sourceMatches.Add("");
                    }

                    foreach (var match in matches)
                    {
                        for (int i = 0; i < texts.Count; i++)
                        {
                            float thisScore = Utils.GetOverlap(texts[i], match) * weights[i];
                            if (thisScore > bestScores[i])
                            {
                                bestScores[i]    = thisScore;
                                sourceMatches[i] = match;
                            }
                        }


                        Log.Info("GlassPrompter", "Heard ~ '" + match + "'");
                    }
                    float maxScore  = bestScores.Max();
                    int   bestIndex = bestScores.FindIndex(m => m == maxScore);

                    if (maxScore < 0.2)
                    {
                        Log.Info("GlassPrompter", "Did not match any line. Best score was " + Math.Floor(maxScore * 1000).ToString() + " for '" + sourceMatches[bestIndex] + "' matching '" + texts[bestIndex] + "'");
                        parent.indicator.SetBackgroundColor(Color.Argb(255, 50, 50, 0));
                    }
                    else
                    {
                        parent.curLine = lineNum[bestIndex] + 1;
                        parent.SetLines();
                        parent.indicator.SetBackgroundColor(Color.Argb(255, 40, 40, 150));

                        Log.Info("GlassPrompter", "Matched. Best score was " + Math.Floor(maxScore * 1000).ToString() + " for '" + sourceMatches[bestIndex] + "' matching '" + texts[bestIndex] + "'");
                    }
                }

                parent.startReco();
            }