Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions VoiceCommand/voicecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ using namespace boost;
void changemode(int);
int kbhit(void);

static const char *optString = "I:l:d:D:psb::c::v::ei::q::t:k:r:f:h?";
static const char *optString = "I:l:d:D:psb::c::v::ei::q::t:k:r:S:f:h?";

inline void ProcessVoice(FILE *cmd, VoiceCommand &vc, char *message) {
printf("Found audio\n");
if(vc.has_setup_command) {
string command = vc.setup_command.c_str();
cmd = popen(command.c_str(),"r");
fscanf(cmd,"\"%[^\"\n]\"",message);
fclose(cmd);
}
vc.Speak(vc.response);
string command = "speech-recog.sh";
if(vc.differentHW) {
Expand Down Expand Up @@ -72,6 +78,8 @@ int main(int argc, char* argv[]) {
}
if(vc.quiet)
fprintf(stderr,"running in quiet mode\n");
if(vc.has_setup_command)
fprintf(stderr,"running with \"%s\" as a setup_command\n",vc.setup_command.c_str());
if(vc.ignoreOthers)
fprintf(stderr,"Not querying for answers\n");
if(vc.edit) {
Expand Down Expand Up @@ -227,6 +235,10 @@ inline void VoiceCommand::CheckCmdLineParam(int argc, char* argv[]) {
verify = true;
keyword = string(optarg);
break;
case 'S':
setup_command = string(optarg);
has_setup_command = true;
break;
case 'r':
response = string(optarg);
break;
Expand Down Expand Up @@ -254,6 +266,8 @@ VoiceCommand::VoiceCommand() {
thresh = 0.7f;
keyword = "pi";
response = "Yes sir?";
setup_command = "";
has_setup_command = false;
improper = "Received improper command";
lang="en";
quiet = false;
Expand Down Expand Up @@ -384,7 +398,7 @@ inline void VoiceCommand::ProcessMessage(const char* message) {
}

void VoiceCommand::GetConfig() {
fprintf(stderr,"Opening config file...\n");
fprintf(stderr,"Opening confarg file...\n");
ifstream file(config_file.c_str(),ios::in);
if(!file.is_open()) {
printf("Can't find config file!\nI'll make one.\n");
Expand All @@ -397,7 +411,7 @@ void VoiceCommand::GetConfig() {
unsigned int loc = line.find("==");
if(line[0] == '!') {
//This is a special config option
//Valid options are keyword==word,continuous==#,verify==#,ignore==#,quiet==#,thresh==#f,response==word improper==word.
//Valid options are keyword==word,continuous==#,verify==#,ignore==#,quiet==#,thresh==#f,response==word,setup_command==word improper==word.
string tmp = line.substr(0,6);
if(tmp.compare("!api==") == 0)
api = line.substr(6);
Expand Down Expand Up @@ -430,7 +444,7 @@ void VoiceCommand::GetConfig() {
command_duration = line.substr(10);
if(tmp.compare("!pidfile==") == 0)
pid_file = line.substr(10);
tmp = line.substr(0,11);
tmp = line.substr(0,11);
if(tmp.compare("!response==") == 0)
response = line.substr(11);
if(tmp.compare("!improper==") == 0)
Expand All @@ -443,6 +457,11 @@ void VoiceCommand::GetConfig() {
lang = line.substr(11);
if(tmp.compare("!duration==") == 0)
duration = line.substr(11);
tmp = line.substr(0,16);
if(tmp.compare("!setup_command==") == 0) {
setup_command = line.substr(16);
has_setup_command = true;
}
tmp = line.substr(0,13);
if(tmp.compare("!continuous==") == 0)
continuous = bool(atoi(line.substr(13).c_str()));
Expand Down Expand Up @@ -480,7 +499,7 @@ void VoiceCommand::EditConfig() {
"This means that ~ arguments should probably be at the end.\n"
"arguments with multiple variables like the play $1 season $2 episode $3 example should be before ones like play... because it will pick the first match\n"
"You can also put comments if the line starts with # and options if the line starts with a !\nDefault options are shown as follows:\n"
"!keyword==pi,!verify==1,!continuous==1,!quiet==0,!ignore==0,!thresh=0.7,!response=Yes sir?, !improper=Received improper command:,!duration==3,!com_dur==2,!filler==FILLER FILL,!api==BLANK,!maxResponse==-1,"
"!keyword==pi,!verify==1,!continuous==1,!quiet==0,!ignore==0,!thresh=0.7,!response=Yes sir?, !setup_command=BLANK, !improper=Received improper command:,!duration==3,!com_dur==2,!filler==FILLER FILL,!api==BLANK,!maxResponse==-1,"
"!lang==en,!hardware==plughw:1,0\n"
"Press any key to continue\n");
getchar();
Expand Down Expand Up @@ -836,6 +855,27 @@ void VoiceCommand::Setup() {
write += response;
write += "\n";
}
printf("\nThe default command to run before listeing for a response is nothing\"\n");
printf("Do you want to change the setup command? (y/n)\n");
change = false;
scanf("%s",buffer);
if(buffer[0] == 'y') {
change = true;
while(change) {
printf("Type the command you want run to set it up:\n");
scanf("%s",buffer);
cmd += "\"";
system(cmd.c_str());
setup_command = string(buffer);
printf("Did that sound correct? (y/n)\n");
scanf("%s",buffer);
if(buffer[0] == 'y')
change = false;
}
write += "!setup_command==";
write += setup_command;
write += "\n";
}
printf("\nThe default response of the system after it receives an unknown command is \"Received improper command:\"\n");
printf("Do you want to change the response? (y/n)\n");
change = false;
Expand Down
2 changes: 2 additions & 0 deletions VoiceCommand/voicecommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class VoiceCommand {
bool ignoreOthers;
bool quiet;
bool differentHW;
bool has_setup_command;
bool passthrough;
float thresh;
//I'm storing the durations as strings because it makes the commands less messy and requires less overhead
Expand All @@ -48,6 +49,7 @@ class VoiceCommand {
string keyword;
string config_file;
string response;
string setup_command;
string improper;
string lang;
string api;
Expand Down