Skip to content

Commit

Permalink
Merge pull request #660 from klier/vr_stuff
Browse files Browse the repository at this point in the history
Allow access to the Voice commands via the web interfacer using fuzzy matching.
  • Loading branch information
hollie authored Jan 8, 2017
2 parents b20d548 + cf3029a commit d39ca9a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
16 changes: 16 additions & 0 deletions code/common/vr_match.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sub phrase_match1 {
my ($phrase) = @_;
my (%list1);
my $d_min1 = 999;
my $set1 = 'abcdefghijklmnopqrstuvwxyz0123456789';
my @phrases = &Voice_Cmd::voice_items('mh', 'no_category');
for my $phrase2 (sort @phrases) {
my $d = pdistance($phrase, $phrase2, $set1, \&distance, {-cost => [0.5,0,4], -mode => 'set'});
# my $brianlendist = abs(length($phrase)-length($phrase2));
# $d = $brianlendist + $d;
# print_log "---------------- $phrase --- $phrase2 --- $d";
push @{$list1{$d}}, $phrase2 if $d <= $d_min1;
$d_min1 = $d if $d < $d_min1;
}
return ${$list1{$d_min1}}[0];
}
38 changes: 38 additions & 0 deletions web/bin/runit.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
return &runit(@ARGV);
sub runit {
my ($cmd) = "@_";
#print_log "-------------------- Original Command: $cmd";
$cmd =~ s/_/ /g;
#print_log "-------------------- Manipulated Command: $cmd";
# Look for exact command matches
if (&process_external_command($cmd, 1, 'android', 'speak')) {
print_log "-------------------- Exact Command Match $cmd";
return &html_page('', 'done');
}

# added by Brian: STRIP out articles and then check for exact command match
$cmd =~ s/the //g;
$cmd =~ s/to //g;
$cmd =~ s/turn //g;

$cmd =~ s/an //g;
$cmd =~ s/make //g;
$cmd =~ s/switch //g;

if (&process_external_command($cmd, 1, 'android', 'speak')) {
print_log "-------------------- Exact Command Match removing articles $cmd";
return &html_page('', 'done');
}

# Look for nearest fuzzy match
my $cmd1 = &phrase_match1($cmd);
print_log "-------------------- Fuzzy Command Match $cmd1";
&process_external_command($cmd1, 1, 'android', 'speak');
return &html_page('', 'done');

# # Added by Brian: Give up
# print_log "-------------------- No command found $cmd";
# play('file' => 'c:\mh\sounds\log.wav');
# return &html_page('', 'No command found');

}

0 comments on commit d39ca9a

Please sign in to comment.