 |
There are currently, 1 guest(s) and 0 member(s) that are online.
You are Anonymous user. You can register for free by clicking here |
|
 |
 |
 |
Select Interface Language:
|
|
 |
 |
|
 |
 |  |  |  | | |
Parts of kln2 source possibly useful to others
Elements of the code, which may be useful to others:
[this chapter is VERY messy; sorry; 2B corrected soon]
1.
Elements of the code, which may be useful to others
voice recognition
I used Daniel Kiecza's cvoicecontrol for KLearnNotes2 voice recognition.
I designed a KDE/QT interface to cvoicecontol setup which you may find
useful. KLearnNotes2 can be used as an example of cvoicecontrol
implementation.
Note, that for now voice recognition is available only in CVS.
CVS contains fully functional code. Still, 1.1 version of
KLearnNotes2 (including voice recognition) is almost ready (this is what
you can find in CVS), and should be released within a week.
I recommend, that before reading the following description, you read
info about voice recognition from recent KLearnNotes2 help files (select
"more info" section from the left menu). Probably it is also inevitable that
you see KLearnNotes2 voice recognition in action (just to get a general
idea what kinds of dialogs/interaction to expect) before reading any
further.
original CVoiceControl files
The files
audio.c configuration.c mixer.c preprocess.c score.c
bb_queue.c cvoicecontrolkln2.c model.c realfftf.c semaphore.c
audio.h configuration.h mixer.h preprocess.h score.h
bb_queue.h cvoicecontrolkln2.h model.h realfftf.h semaphore.h
queue.h
come from Daniel Kiecza's CVoiceControl 0.9 . Note, that I altered slightly
some of the files - changed some char* to const char* (to make the compiler
stop complaining), added some extern or semicolons etc. - just to marry C
and C++ code. The compiler still writes some warnings, but the code compiles
now. (I wanted to make as small changes as possible in Kiecza's code,
to be able to alter it easily if Daniel Kiecza issues a new version of
CVoiceControl.)
Major changes:
- cvoicecontrolkln2.c does NOT perform any commands;
instead it prints out to standard-out model item's label:
-
I completely changed keypressed.* to make it work under Qt. Therefore,
I had to extracted "getUtterance()" (which uses keypress functions)
from audio.c to voice_recognition.cpp .
If you want to use CVoiceControl in your program you need all the above,
but none of these should require any change.
other files you need
voice_recognition.h voice_recognition.cpp globals.h globals.cpp
These files contain definition of Class dVoiceMicroSetup (Qt interface to
Kiecza's microphone calibration code), Class dModelEditor (Qt interface to
Kiecza's voice model editor - you will have to alter this code!),
definitions of commands' strings.
You will also need some extracts from klearnnotes2.{cpp,h} (implementation
of voice recognition into a real program).
How to use this code in your program: step-by-step
- Copy all files listed in above two sections.
- Edit top of voice_recognition.h - add your own commands. For each command
there are three lines:
#define cmd_sndOn "SOUND_ON"
#define txt_sndOn QT_TR_NOOP("turn SOUND ON")
#define sug_sndOn QT_TR_NOOP("just record 'sound ON'")
- cmd_X is actual string by which a command will be identified
(model-item label)
- txt_X is what user will see in dModelEditor dialog
- sug_X is a short suggestion for a phrase recording (make user
aware of particular problems with this phrase)
You shouldn't need to alter Class dVoiceMicroSetup.
- Class dModelEditor:
voice_recognition.{h,cpp}
For KLearnNotes2 all phrases were split into two parts: notes' names and
program commands. If you do not need notes' names voice recognition
you can
safely delete from the code all lines referring to "Page 2" (that is
page setup and all slot-functions) of dModelEditor (don't
change the second page of dVoiceMicroSetup !!!).
You also do not need "extern char orderOfNotes [8] ;".
Note, that one of arguments of dModelEditor is 'KLearnNotes2* parent', saved
as protected 'papa'. This is only to run
papa->setVoiceModelFilename(modelFileName);
You may prefer to use a more flexible way to make your main program aware
of modelFileName (like returning QString or reading it by parent from
e.g. some dModelEditor's QLabel after running it and before deleting.
You have to add all your commands explicitly to PAGE3 setup:
commandItems[9]=new QListViewItem(head[2],txt_sndOn,"-",QString("%1").arg(9));
commandStrings[9][0]=new QString(cmd_sndOn);
commandStrings[9][1]=new QString(txt_sndOn);
commandStrings[9][2]=new QString(sug_sndOn);
All commands are split into few head[]-s and will be seen by user in
order reversed to how they were added.
- cvoicecontrolkln2:
You should compile cvoicecontrolkln2 as a separate runnable program. Just add
a line like
cvoicecontrolkln2_SOURCES = audio.c bb_queue.c configuration.c mixer.c model.c preprocess.c realfftf.c score.c
semaphore.c cvoicecontrolkln2.h audio.h bb_queue.h configuration.h mixer.h model.h preprocess.h realfftf.h
score.h semaphore.h cvoicecontrolkln2.h
to your Makefile.am file.
- main program:
In the case of KLearnNotes2 this is the Class KLearnNotes2. The
methods/properties relevant to voice recognition are:
void setVoiceModelFilename(QString newName); // sets up cvoicecontrol
// command line
protected slots:
void dialogVoiceMircoSetup(); // runs microphone setup
void dialogVoiceModelEditor(); // runs voice-model editor
void readFromVoice(); // reads cvoicecontrol input
void voiceStartStop(bool); // starts/stops cvoicecontrol
void voiceExited(); // get notified when cvoicecontrol exits
protected:
QPopupMenu *mo_Voice_menu;
QAction *a_mo_voiceMicroSetup;
actionWithIconSwitch *a_mo_voiceOnOff; // you may use QAction here !
QAction *a_mo_startVoiceEditor;
QProcess *voiceProcess; // !!!!!!!!!!!!!!
QFile *voiceModelFile;
The program should:
- set up/restore voice model filename
- set up QProcess communication (and connect a signal to readFromVoice()
- set up programs reactions in readFromVoice()
- force user to run microphone calibration first, and only then
model editor, and only then to enable activating cvoicecontolkln2
In future I plan to make a separate class with voice capabilities (to be
inherited by Class KLearnNotes2) with some clear initVoiceRecoginition(),
start/endVR() etc. functions and which should emit a signal whenever
cvoicecontrol says anything. This would make things implementable
out-of-the-box.
wise random draws
This program uses a simple "wise random draw" algorithm to focus
learning on what a student knows worse. It can be very useful for
other teaching programs too!
To use this algorithm in your programs copy randomobject.{h,cpp} and make
all classes representing objects which should be random-chosen inherit
RandomObject. To make the description simpler I will use aNote example from
KLearnNotes2 (see KLNcanvasitems.{cpp,h}).
class aNote : public RandomObject
The RandomObject-operating functions use tables of aNotes for all arguments.
This is because such tables are pre-allocated and no aNote* => RandomObject*
=> aNote* assignment is ever done!
In all the following examples
- 'aNote* note' is a current note (question)
- 'int quenum' is current question number
- 'aNote* suggestion[defMAXseria]' is a table of force-scheduled questions
- 'aNote* activeNotes[defMAXall]' is a table of all possible questions
- 'int numActiveNotes' is number of fields used in activeNotes[] in a
particular test
Now, the program should do the following:
- before start of a test choose activeNotes[] (questions to draw from)
and remember number of them in 'int numActiveNotes'
- at the beginning of a new test
- for all 'i' call 'activeNotes[i]->resetStats()'
- call
RandomObject_init((RandomObject**)suggestion, defMAXseria,
(RandomObject**)activeNotes, numActiveNotes);
to schedule a first force-scheduled run
- set 'note' to NULL.
- to random-draw next question ('note') call
aNote* lastNote[1];
lastNote[0]=note;
aNote* newNote[1];
newNote[0]=NULL;
RandomObject_next(quenum, (RandomObject**) lastNote,
(RandomObject**) newNote,
(RandomObject**)suggestion, defMAXseria,
(RandomObject**)activeNotes, numActiveNotes);
note=newNote[0];
- show a the selected question ('note'), start a timer and count ticks
(see 'void KLearnNotes2::growtime()')
- whenever there is a correct answer call
note->addCorrect(onetime)
where 'onetime' is number of ticks counted
- whenever there is a wrong answer call
note->addWrong(onetime);
and
aNote* tmpNotes[1];
tmpNotes[0]=note;
RandomObject_schedule(quenum,(RandomObject**) tmpNotes,
(RandomObject**)suggestion, defMAXseria);
to schedule the same question for force-scheduled questions
in future.
I will gladly answer any questions regarding the code. :)
MW Copyright © by KLearnNotes2 - the music teaching program All Right Reserved. Published on: 2004-05-08 (1502 reads) [ Go Back ] |
| |
|  |
 |
| Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name. |
|
 |
 |
|