Commit 57d69da4 authored by Dan Wilcox's avatar Dan Wilcox
Browse files

fix crash due to wrong prev buffer value, added verbose printing commandline...

fix crash due to wrong prev buffer value, added verbose printing commandline option, load model before starting sound again
parent 298337d9
......@@ -13,6 +13,7 @@ int main(int argc, char **argv) {
bool list = false;
int inputNum = -1;
std::string inputName = "";
bool verbose = false;
parser.add_option("-s,--senders", senders,
"OSC sender addr:port host pairs, ex. \"192.168.0.100:5555\" "
"or multicast \"239.200.200.200:6666\", default \"localhost:9999\""
......@@ -27,8 +28,12 @@ int main(int argc, char **argv) {
parser.add_option("--inputdev", inputNum, "audio input device number");
parser.add_option("--inputname", inputName,
"audio input device name, can do partial match ie. \"Microphone\"");
parser.add_flag("-v,--verbose", verbose, "verbose printing");
CLI11_PARSE(parser, argc, argv);
// verbose printing?
ofSetLogLevel("LangID", (verbose ? OF_LOG_VERBOSE : OF_LOG_NOTICE));
// list audio input devices
if(list) {
auto devices = app->soundStream.getDeviceList();
......@@ -57,7 +62,7 @@ int main(int argc, char **argv) {
}
ofSoundDevice &device = devices[inputNum];
if(device.inputChannels == 0) {
ofLogError() << "audio device " << inputNum << " has no input channels";
ofLogError("LangID") << "audio device " << inputNum << " has no input channels";
return EXIT_FAILURE;
}
app->inputDevice = inputNum;
......@@ -78,7 +83,7 @@ int main(int argc, char **argv) {
app->inputDevice = inputNum;
}
else {
ofLogWarning() << "audio input name not found: " << inputName;
ofLogWarning("LangID") << "audio input name not found: " << inputName;
}
}
......@@ -88,13 +93,13 @@ int main(int argc, char **argv) {
for(auto host : senders) {
size_t found = host.find_last_of(":");
if(found == std::string::npos) {
ofLogWarning() << "ignoring sender host without port: " << host;
ofLogWarning("LangID") << "ignoring sender host without port: " << host;
continue;
}
std::string addr = host.substr(0, found);
std::string port = host.substr(found+1);
if(addr.size() == 0 || port.size() == 0) {
ofLogWarning() << "ignoring sender host with empty address or port: " << host;
ofLogWarning("LangID") << "ignoring sender host with empty address or port: " << host;
continue;
}
if(addr[0] == '[' && addr[addr.size()-1] == ']') {
......@@ -102,7 +107,7 @@ int main(int argc, char **argv) {
}
int p = ofToInt(port);
if(p <= 1024) {
ofLogWarning() << "ignoring sender host with invalid port or system port: " << host;
ofLogWarning("LangID") << "ignoring sender host with invalid port or system port: " << host;
continue;
}
app->hosts.push_back(ofApp::OscHost(addr, p));
......
......@@ -23,6 +23,13 @@ void ofApp::setup() {
ofSetCircleResolution(80);
ofBackground(54, 54, 54);
// load the model, bail out on error
//std::string modelName = "model_4lang"; // model v1
std::string modelName = "model_attrnn"; // model v2
if(!model.load(modelName)) {
std::exit(EXIT_FAILURE);
}
// recording settings
numBuffers = samplingRate * inputSeconds / bufferSize;
previousBuffers.setMaxLen(numPreviousBuffers);
......@@ -41,12 +48,12 @@ void ofApp::setup() {
}
}
if(inputDevice < 0) {
ofLogError() << "no audio input device";
ofLogError("LangID") << "no audio input device";
std::exit(EXIT_FAILURE);
}
}
auto devices = soundStream.getDeviceList();
ofLog() << "audio input device: " << inputDevice << " " << devices[inputDevice].name;
ofLogNotice("LangID") << "audio input device: " << inputDevice << " " << devices[inputDevice].name;
settings.setInDevice(devices[inputDevice]);
settings.setInListener(this);
settings.sampleRate = samplingRate;
......@@ -54,7 +61,7 @@ void ofApp::setup() {
settings.numInputChannels = 1;
settings.bufferSize = bufferSize;
if(!soundStream.setup(settings)) {
ofLogError() << "audio input device " << inputDevice << " setup failed";
ofLogError("LangID") << "audio input device " << inputDevice << " setup failed";
std::exit(EXIT_FAILURE);
}
......@@ -62,35 +69,29 @@ void ofApp::setup() {
volHistory.assign(400, 0.0);
// print language labels we know
ofLog() << "From src/Labels.h:";
ofLog() << "----> detected languages";
ofLogVerbose("LangID") << "From src/Labels.h:";
ofLogVerbose("LangID") << "----> detected languages";
for(const auto & label : labelsMap) {
ofLog() << label.second;
}
ofLog() << "<---- detected languages";
// load the model, bail out on error
//std::string modelName = "model_4lang"; // model v1
std::string modelName = "model_attrnn"; // model v2
if(!model.load(modelName)) {
std::exit(EXIT_FAILURE);
ofLogVerbose("LangID") << label.second;
}
ofLogVerbose("LangID") << "<---- detected languages";
// warm up: inital inference involves initalization (takes longer)
auto test = cppflow::fill({1, 80000, 1}, 1.0f);
output = model.runModel(test);
ofLog() << "Setup done";
ofLog() << "============================";
// osc
ofLog() << hosts.size() << " sender host(s)";
ofLogNotice("LangID") << hosts.size() << " sender host(s)";
for(auto host : hosts) {
ofxOscSender *sender = new ofxOscSender;
if(sender->setup(host.address, host.port)) {
senders.push_back(sender);
ofLog() << " address: " << host.address << " port: " << host.port;
ofLogNotice("LangID") << " " << host.address << " " << host.port;
}
}
ofLogVerbose("LangID") << "Setup done";
ofLogVerbose("LangID") << "============================";
}
//--------------------------------------------------------------
......@@ -126,9 +127,9 @@ void ofApp::update() {
}
// look up label
ofLog() << "Label: " << labelsMap[argMax];
ofLog() << "Probabilty: " << prob;
ofLog() << "============================";
ofLogVerbose("LangID") << "Label: " << labelsMap[argMax];
ofLogVerbose("LangID") << "Probabilty: " << prob;
ofLogVerbose("LangID") << "============================";
// release the trigger signal and emit enable
trigger = false;
......@@ -233,7 +234,7 @@ void ofApp::audioIn(ofSoundBuffer & input) {
// trigger recording if the smoothed volume is high enough
if(ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true) * 100 >= volThreshold && enable) {
enable = false;
ofLog() << "Start recording...";
ofLogVerbose("LangID") << "Start recording...";
// copy previous buffers to the recording
sampleBuffers = previousBuffers;
sampleBuffers.setMaxLen(numBuffers); // just to make sure (not tested)
......@@ -254,7 +255,7 @@ void ofApp::audioIn(ofSoundBuffer & input) {
if(recordingCounter >= numBuffers) {
recording = false;
trigger = true;
ofLog() << "Done!";
ofLogVerbose("LangID") << "Done!";
}
}
// if not recording: save the incoming buffer to the previous buffer fifo
......
......@@ -61,7 +61,7 @@ class ofApp : public ofBaseApp {
// since volume detection has some latency we keep a history of buffers
AudioBufferFifo previousBuffers;
std::size_t numPreviousBuffers;
std::size_t numPreviousBuffers = 10; // how many buffers to save before trigger happens
// sampleBuffers acts as a buffer for recording (could be fused)
AudioBufferFifo sampleBuffers;
std::size_t numBuffers;
......
Supports Markdown
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