-
Notifications
You must be signed in to change notification settings - Fork 0
/
calvin.pl
101 lines (99 loc) · 3.66 KB
/
calvin.pl
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/perl
#use strict;
#use warnings;
#Verify Correct packages are installed
my $espeak = `dpkg -l|grep -E '^ii' |grep espeak`;
if(!$espeak){
print "package \"espeak\" must be installed\n";
exit(1);
}
my $words = "talk";
my $num_args = $#ARGV;
my $mode ||= talk;#command,-c,talk,-t,spell,-s,quiet,-q
$mode = shift;
if ($mode eq "-c") {
$mode = "command";
} elsif ($mode eq "-s"){
$mode = "spell";
} elsif ($mode eq "-q"){
$mode = "quiet";
} else {
$mode = "talk";
}
while($num_args > 0){
$param = $param . shift . " ";
--$num_args;
}
$param ||= "^]NULL^]";
#command will run a command a speak the output raw
#talk will repeat everything you type
#spell will run a command, then literally repeat it
#quiet will skip the introduction and closing statement
#
#I considered a file option, but it is so similar to the
#command option which already includes this functionality
#and the implementation would be redundant which
#would be redundant. Simply type in your terminal:
#calvin command cat [file path]
#or make an alias in your bashrc such as:
#alias file='command cat'
#and then type:
#calvin file [file path]
my $user = getpwuid ($<);
my $random = int(rand(100));
if ($mode ne "quiet" && $mode ne "-q" && $param eq "^]NULL^]"){
system("echo \"Hello $user, I am Calvin, You're digital assistant\" | espeak -s 120 2>/dev/null");
}
while ($words ne "q\n"){
if ($param eq "^]NULL^]"){
$words = <STDIN>;
} else {
$words = $param;
}
$random = int(rand(100));
if ($words eq "command\n" ||$words eq "-c\n"){
$mode = "command";
} elsif ($words eq "talk\n" || $words eq "-t\n") {
$mode = "talk";
} elsif ($words eq "spell\n" || $words eq "-s\n") {
$mode = "spell";#spell out the results of a command
} elsif ($mode eq "spell") {
chomp ($words);
system ("touch spell.tmp");
system ("$words > spell.tmp");
system ("touch spell.bak");
my $sed = "'s/\\(.\\)/\\1 /g;s/ \$//'";
system ("sed $sed spell.tmp > spell.bak");
$sed = "'s/\\./point/g'";
system ("sed $sed spell.bak > spell.tmp");
$sed = "'s/\\ / space /g'";
system ("sed $sed spell.tmp > spell.bak");
$sed = "':a;N;\$!ba;s/\\n/ new line /g'";
system ("sed $sed spell.bak > spell.tmp");
$sed = "'s/\\t/ tab /g'";
system ("sed $sed spell.tmp > spell.bak");
system ("cat spell.bak | espeak -p $random -s 80 2>/dev/null");
system ("rm spell.tmp");
system ("rm spell.bak");
} elsif ($mode eq "command"){
chomp($words);
system("$words |espeak -p $random -s 120 2>/dev/null");
} elsif ($words ne "q\n" && $words ne "exit\n") {
chomp($words);
system("echo \"$words\" | espeak -p $random -s 120 2>/dev/null");
} elsif ($mode ne "quiet" && $mode ne "-q" && $param eq "^]NULL^]") {
system("echo \"Goodbye $user\" | espeak -s 120 2>/dev/null");
}
if ($param ne "^]NULL^]"){
exit(0);
}
}
#bashrc addition:
#alias calvin='/root/Documents/developement/espeak/calvin.pl'
#function alice {
# espeak -ven-us+f4espeak -ven-us+f4espeak -ven-us+f2 -s100 -p 99 "$@" 2>/dev/null
#}
#function say {
# /root/Documents/developement/espeak/calvin.pl -c cat /root/Documents/developement/espeak/preset/"$1"
#}
#preset files are NOT included, but I encourage you to write your own