Commit 923492cd authored by Dan Wilcox's avatar Dan Wilcox
Browse files

pass script in via --execute command arg, remove script from repo

parent 2f8e4ee6
http -v -j POST https://thingsboard.zkm.de/api/v1/rFKmcjtHSLgVvrT6NaCB/telemetry $*
......@@ -33,6 +33,7 @@ bool Commandline::parse(int argc, char **argv) {
bool autostop = false;
bool verbose = false;
bool version = false;
std::string command = "";
parser.add_option("-s,--senders", senders,
"OSC sender addr:port host pairs, ex. \"192.168.0.100:5555\" "
......@@ -50,6 +51,7 @@ bool Commandline::parse(int argc, char **argv) {
ofToString(ofApp::modelSampleRate) + ", default " + ofToString(app->sampleRate));
parser.add_flag( "--nolisten", nolisten, "do not listen on start");
parser.add_flag( "--autostop", autostop, "stop listening automatically after detection");
parser.add_option("-e,--execute", command, "command to execute on detection with key=value pair args");
parser.add_flag( "-v,--verbose", verbose, "verbose printing");
parser.add_flag( "--version", version, "print version and exit");
......@@ -199,6 +201,11 @@ bool Commandline::parse(int argc, char **argv) {
app->autostop = true;
}
// command
if(command != "") {
app->command = command;
}
return true;
}
......
......@@ -128,16 +128,6 @@ void ofApp::setup() {
ofLogVerbose(PACKAGE) << "============================";
}
std::string resultTOString(Labels labelsMap, std::vector<float> outputVector){
std::string result;
for (size_t i = 0; i < outputVector.size(); i++)
{
result.append(labelsMap[i] + "=" + std::to_string(outputVector[i]) + " ");
}
return result;
}
//--------------------------------------------------------------
void ofApp::update() {
......@@ -169,19 +159,22 @@ void ofApp::update() {
bool detected = false;
if(prob >= minConfidence) {
displayLabel = labelsMap[argMax];
bool isGerman = (displayLabel.compare("german") == 0) ? true : false;
std::string cmd_args = resultTOString(labelsMap, outputVector);
cmd_args.append("selected=" + displayLabel);
cmd_args.append("isGerman=" + std::to_string(isGerman));
std::string cmd = ofToDataPath("send_languages.sh") + " " + cmd_args;
ofLog() << cmd;
ofSystem(cmd);
// send osc
ofxOscMessage message;
message.setAddress("/lang");
message.addIntArg(argMax);
message.addStringArg(labelsMap[argMax]);
message.addStringArg(displayLabel);
message.addFloatArg(prob * 100);
for(auto sender: senders) {sender->sendMessage(message);}
// execute command?
if(command != "") {
std::string params = + "selected=" + displayLabel + " " + resultToString(outputVector);
ofLogVerbose(PACKAGE) << command << " " << params << " &";
ofSystem(command + " " + params + " &");
}
detected = true;
}
else {
......@@ -481,3 +474,15 @@ void ofApp::oscReceived(const ofxOscMessage &message) {
}
}
}
//--------------------------------------------------------------
std::string ofApp::resultToString(std::vector<float> outputVector) {
std::string result = "";
for(size_t i = 0; i < outputVector.size(); i++) {
result += labelsMap[i] + "=" + std::to_string(outputVector[i]);
if(i < outputVector.size()-1) {
result += " ";
}
}
return result;
}
......@@ -65,6 +65,9 @@ class ofApp : public ofBaseApp {
/// osc receiver callback
void oscReceived(const ofxOscMessage &message);
/// convert model results into a key=value string seperated by spaces
std::string resultToString(std::vector<float> outputVector);
// audio
ofSoundStream soundStream;
int inputDevice = -1; // -1 means search for default device
......@@ -126,4 +129,7 @@ class ofApp : public ofBaseApp {
ofxOscReceiver receiver;
int port = 9898;
bool recordingStarted = false;
// optional command to run on detection
std::string command = "";
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment