示例#1
0
void train (const ssi_char_t *dir, const ssi_char_t *model) {

	// load samples
	StringList files;
	FileTools::ReadFilesFromDir (files, dir, "*.wav");
	SampleList samples;	
	samples.addUserName ("user");

	for (ssi_size_t i = 0; i < files.size (); i++) {
		ssi_stream_t *stream = new ssi_stream_t;
		ssi_sample_t *sample = new ssi_sample_t;
		const ssi_char_t *filename = files.get (i);
	
		// parse class name
		FilePath fp (files.get(i));
		ssi_char_t *class_name = ssi_strcpy (fp.getName ());
		for (ssi_size_t j = 0; j < strlen (class_name); j++) {
			if (class_name[j] == '_') {
				class_name[j] = '\0';
				break;
			}
		}
		ssi_size_t class_id = samples.addClassName (class_name);
		delete[] class_name;

		// read wave file
		WavTools::ReadWavFile (filename, *stream);

		// create sample
		sample->class_id = class_id;
		sample->num = 1;
		sample->score = 1.0f;
		sample->streams = new ssi_stream_t *[1];
		sample->streams[0] = stream;
		sample->time = 0;
		sample->user_id = 0;				

		// add sample
		samples.addSample (sample);
	}

	// extract features
	SampleList samples_t;
	EmoVoiceFeat *ev_feat = ssi_create (EmoVoiceFeat, "ev_feat", true);
	ModelTools::TransformSampleList (samples, samples_t, *ev_feat);
	
	// create model
	IModel *bayes = ssi_create (NaiveBayes, "bayes", true);
	Trainer trainer (bayes);

	// evalulation
	Evaluation eval;
	eval.evalKFold (&trainer, samples_t, 10);
	eval.print ();

	// train & save
	trainer.train (samples_t);
	trainer.save (model);
}
示例#2
0
bool FileSamplesOut::close () { 

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "close files '%s'", _path);

	if (!_console) {

		if (!_file_data->close ()) {
			ssi_wrn ("could not close data file '%s'", _path);
			return false;
		}

		switch (_version) {
			
			case File::V2: {

				TiXmlElement info ("info" );	
				info.SetAttribute ("ftype", File::TYPE_NAMES[_file_data->getType ()]);
				info.SetAttribute ("size", _n_samples);
				info.SetAttribute ("missing", _has_missing_data ? 1 : 0);
				info.SetAttribute ("garbage", _n_garbage_class);

				TiXmlElement streams ("streams");
				for (ssi_size_t i = 0; i < _n_streams; i++) {
					TiXmlElement item ("item");
					item.SetDoubleAttribute ("sr", _streams[i].sr);
					item.SetAttribute ("dim", _streams[i].dim);
					item.SetAttribute ("byte", _streams[i].byte);
					item.SetAttribute ("type", SSI_TYPE_NAMES[_streams[i].type]);
					streams.InsertEndChild (item);
				}
				info.InsertEndChild (streams);

				TiXmlElement classes ("classes");
				for (ssi_size_t i = 0; i < _n_classes; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _classes[i]);			
					item.SetAttribute ("size", _n_per_class[i]);
					classes.InsertEndChild (item);
				}
				info.InsertEndChild (classes);

				TiXmlElement users ("users");
				for (ssi_size_t i = 0; i < _n_users; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _users[i]);			
					item.SetAttribute ("size", _n_per_user[i]);
					users.InsertEndChild (item);
				}
				info.InsertEndChild (users);

				info.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("\n</samples>");

				if (!_file_info->close ()) {
					ssi_wrn ("could not close info file '%s'", _file_info->getPath ());
					return false;
				}

			}
			break;

			case File::V3: {

				TiXmlElement info ("info" );	
				info.SetAttribute ("ftype", File::TYPE_NAMES[_file_data->getType ()]);
				info.SetAttribute ("size", _n_samples);
				info.SetAttribute ("missing", _has_missing_data ? "true" : "false");
				info.SetAttribute ("garbage", _n_garbage_class);

				TiXmlElement streams ("streams");
				for (ssi_size_t i = 0; i < _n_streams; i++) {
					TiXmlElement item ("item");
					FilePath fp (_file_streams[i].getInfoFile ()->getPath ());
					item.SetAttribute ("path", fp.getName ());
					streams.InsertEndChild (item);
				}

				TiXmlElement classes ("classes");
				for (ssi_size_t i = 0; i < _n_classes; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _classes[i]);			
					item.SetAttribute ("size", _n_per_class[i]);
					classes.InsertEndChild (item);
				}

				TiXmlElement users ("users");
				for (ssi_size_t i = 0; i < _n_users; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _users[i]);			
					item.SetAttribute ("size", _n_per_user[i]);
					users.InsertEndChild (item);
				}

				info.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("");
				streams.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("");
				classes.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("");
				users.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("\n</samples>");

				if (!_file_info->close ()) {
					ssi_wrn ("could not close info file '%s'", _file_info->getPath ());
					return false;
				}
			}
		}
	}

	if (_file_streams) {
		for (ssi_size_t i = 0; i < _n_streams; i++) {			
			_file_streams[i].close ();
		}
	}

	delete _file_data; _file_data = 0;
	delete _file_info; _file_info = 0;
	delete[] _file_streams; _file_streams = 0;
	delete _path; _path = 0;

	for (ssi_size_t i = 0; i < _n_classes; i++) {
		delete[] _classes[i];
	}
	delete[] _classes; _classes = 0;
	delete[] _n_per_class; _n_per_class = 0;
	_n_garbage_class = 0;
	for (ssi_size_t i = 0; i < _n_users; i++) {
		delete[] _users[i];
	}
	delete[] _users; _users = 0;
	delete[] _n_per_user; _n_per_user = 0;	
	delete[] _streams; _streams = 0;

	_n_samples = 0;
	_n_classes = 0;
	_n_users = 0;	
	_n_streams = 0;

	return true;
};
示例#3
0
void EditFiles::viewFile(OovStringRef const fn, int lineNum)
    {
    FilePath fp;

    fp.getAbsolutePath(fn, FP_File);
    auto iter = std::find_if(mFileViews.begin(), mFileViews.end(),
        [fp](std::unique_ptr<ScrolledFileView> const &fv) -> bool
        { return fv->mFilename.comparePaths(fp) == 0; });
    if(iter == mFileViews.end())
        {
        GtkNotebook *book = nullptr;
        if(putInMainWindow(fn))
            book = mSourceBook;
        else
            book = mHeaderBook;
        if(book)
            {
            GtkWidget *scrolled = gtk_scrolled_window_new(nullptr, nullptr);
            GtkWidget *editView = gtk_text_view_new();

            /// @todo - use make_unique when supported.
            ScrolledFileView *scrolledView = new ScrolledFileView(mDebugger);
            scrolledView->mFileView.init(GTK_TEXT_VIEW(editView), this);
            OovStatus status = scrolledView->mFileView.openTextFile(fp);
            if(status.needReport())
                {
                OovString err = "Unable to open file ";
                err += fp;
                status.report(ET_Error, err);
                }
            scrolledView->mScrolled = GTK_SCROLLED_WINDOW(scrolled);
            scrolledView->mFilename = fp;

            gtk_container_add(GTK_CONTAINER(scrolled), editView);
            Gui::appendPage(book, scrolled,
                    newTabLabel(fp.getName(), scrolledView->getViewTopParent()));
            gtk_widget_show_all(scrolled);
            scrolledView->mLeftMargin.setupMargin(GTK_TEXT_VIEW(editView));

            // Set up the windows to draw the line numbers in the left margin.
            // GTK has changed, and different setups are required for different
            // versions of GTK.
            // This is not allowed for a text view
            //          gtk_widget_set_app_paintable(editView, true);
#if(USE_DRAW_LAYER)
            overrideDrawLayer(editView);
            // If the left window is not created, errors display, "Attempt to
            // convert text buffer coordinates to coordinates for a nonexistent
            // buffer or private child window of GtkTextView". So create a
            // window that is only one pixel wide, and draw the line numbers
            // on the main text view window.
            gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(editView),
                    GTK_TEXT_WINDOW_LEFT, 1);
            gtk_text_view_set_left_margin(GTK_TEXT_VIEW(editView),
                    scrolledView->mLeftMargin.getMarginWidth());
#else
            // The margin is drawn on the border window.
            gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(editView),
                    GTK_TEXT_WINDOW_LEFT, scrolledView->mLeftMargin.getMarginWidth());
            g_signal_connect(editView, "draw", G_CALLBACK(onTextViewDraw), scrolledView);
#endif

            g_signal_connect(editView, "focus_in_event",
                    G_CALLBACK(on_EditFiles_focus_in_event), NULL);
            g_signal_connect(editView, "key_press_event",
                    G_CALLBACK(on_EditFiles_key_press_event), NULL);
            g_signal_connect(editView, "button_press_event",
                    G_CALLBACK(on_EditFiles_button_press_event), NULL);
            mFileViews.push_back(std::unique_ptr<ScrolledFileView>(scrolledView));
#if(DBG_EDITF)
        sDbgFile.printflush("viewFile count %d, line %d\n", mFileViews.size(), lineNum);
#endif
            iter = mFileViews.end()-1;
            }
        }
    GtkNotebook *notebook = (*iter)->getBook();
    if(notebook)
        {
        int pageIndex = getPageNumber(notebook, (*iter)->getTextView());
        Gui::setCurrentPage(notebook, pageIndex);
        // focus is set after the screen is displayed by onIdle
//      gtk_widget_grab_focus(GTK_WIDGET((*iter).getTextView()));
#if(DBG_EDITF)
        sDbgFile.printflush("viewFile %d\n", pageIndex);
#endif
        if(lineNum > 1)
            {
            (*iter)->mDesiredLine = lineNum;
            }
        }
    }
示例#4
0
文件: Main.cpp 项目: hcmlab/mobileSSI
int main (int argc, char **argv) {

#ifdef USE_SSI_LEAK_DETECTOR
	{
#endif

	char info[1024];
	ssi_sprint (info, "\n%s\n\nbuild version: %s\n\n", SSI_COPYRIGHT, SSI_VERSION);

	//**** READ COMMAND LINE ****//

	CmdArgParser cmd;
	cmd.info (info);

	ssi_char_t *dllpath = 0;	
	ssi_char_t *apipath = 0;	
	ssi_char_t *outdir = 0;
	ssi_char_t *reg = 0; 
	bool index;

	cmd.addText("\nArguments:");
	cmd.addSCmdArg("dllpath", &dllpath, "input path to dll");	

	cmd.addText ("\nOptions:");
	cmd.addSCmdOption ("-dir", &outdir, "", "output directory []");
	cmd.addBCmdOption ("-index", &index, false, "create index [false]");
	cmd.addSCmdOption ("-reg", &reg, "", "register additional dll's (if several separate by semicolon)");
	
	if (cmd.read (argc, argv)) {		

		ssi_char_t string[SSI_MAX_CHAR];

		FilePath fp (dllpath);
		ssi_char_t *dllpath_with_ext = 0;
		if (strcmp (fp.getExtension (), ".dll") != 0) {
			dllpath_with_ext = ssi_strcat (dllpath, ".dll");
		} else {
			dllpath_with_ext = ssi_strcpy (dllpath);
		}

		if (Factory::RegisterDLL (dllpath_with_ext)) {	

			// register additional dlls
			if (reg) {
				APIGenerator::SaveCurrentComponentList ();
				ssi_size_t n_reg = ssi_split_string_count (reg, ';');
				ssi_char_t **regs = new ssi_char_t *[n_reg];
				ssi_split_string (n_reg, regs, reg, ';');
				for (ssi_size_t i = 0; i < n_reg; i++) {
					Factory::RegisterDLL (regs[i]);
					delete[] regs[i];
				}
				delete[] regs;
			}

			if (outdir[0] == '\0') {
				ssi_sprint (string, "%s", fp.getPath ());
			} else {
				ssi_sprint (string, "%s\\%s", outdir, fp.getName ());
			}

			APIGenerator::CreateAPI (string);
			APIGenerator::ResetCurrentComponentList ();
			Factory::Clear ();
		}

		if (index) {
			if (outdir[0] == '\0') {
				APIGenerator::CreateAPIIndex (fp.getDir ());
			} else {
				APIGenerator::CreateAPIIndex (outdir);
			}
		}

		delete[] dllpath_with_ext;
	}

	delete[] dllpath;	
	delete[] apipath;	
	delete[] outdir;

#ifdef USE_SSI_LEAK_DETECTOR
	}
	_CrtDumpMemoryLeaks();
#endif

	return 0;
}