-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #660 from klier/vr_stuff
Allow access to the Voice commands via the web interfacer using fuzzy matching.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
||
} |