diff --git a/README.md b/README.md index 82298ba..fd643c2 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ uSpeech library ============== - +This is branch is the 3.0 release sandbox. It is currently vaporware unless you wish to contribute. The uSpeech library provides an interface for voice recognition using the Arduino. It currently produces phonemes, often the library will produce junk phonemes. Please bare with it for the time being. A noise removal function is underway. ##Minimum Requirements ## The library is quite intensive on the processor. Each sample collection takes about 3.2 milliseconds so pay close attention to the time. The library has been tested on the Arduino Uno (ATMega32). Each signal object uses up 160bytes. No real time scheduler should be used with this. diff --git a/formant.cpp b/formant.cpp deleted file mode 100755 index 9c0e2ce..0000000 --- a/formant.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "uspeech.h" - -void signal::voiceFormants(){ - unsigned int j; - filters[0] = fpowerex(25,0); //400 - j+= filters[0]; - filters[1] = fpowerex(16,6)-j; //600 - j+= filters[1]; - filters[2] = fpowerex(12,5)-j; //800 - j+= filters[2]; - filters[3] = fpowerex(10,0)-j; //1000 - j+= filters[3]; - filters[4] = fpowerex(8,3)-j; //1200 - j+= filters[4]; - filters[5] = fpowerex(7,1)-j; //1400 - j+= filters[5]; - filters[6] = fpowerex(6,3)-j; //1600 - j+= filters[6]; - filters[7] = fpowerex(5,5)-j; //1800 - j+= filters[7]; - filters[8] = fpowerex(5,0)-j; //2000 - j+= filters[8]; - filters[9] = fpowerex(4,5)-j; //2200 - j+= filters[9]; - filters[10] = fpowerex(4,0)-j; //2400 - j+= filters[10]; - filters[11] = fpowerex(3,8)-j; //2600 - j+= filters[11]; - filters[12] = fpowerex(3,5)-j; //2800 - j+= filters[12]; - filters[13] = fpowerex(3,3)-j; //3000 - j+= filters[13]; - filters[14] = fpowerex(2,9)-j; //3200 - j+= filters[14]; - filters[15] = fpowerex(2,7)-j; //3400 - j+= filters[15]; - filters[16] = fpowerex(2,6)-j; //3600 - j+= filters[16]; - filters[17] = fpowerex(2,5)-j; //3800 - j+= filters[17]; -} -void signal::debugPrintFilter(){ - int i = 0; - while(i<18){ - Serial.println(filters[i]); - i++; - } - Serial.println("-----"); -} - -int signal::goertzel(int freq){ -freq = freq/100000; -int s_prev = 0 ; -int s_prev2 = 0 ; -int coeff = 2 * cos(2 * 3.14 * freq) ; -for(int i = 2; i < 32; i++){ - int s = arr[i] + coeff *s_prev - s_prev2 ; - s_prev2 = s_prev ; - s_prev = s ; -} -return s_prev2 * s_prev2 + s_prev * s_prev - coeff * s_prev * s_prev2 ; - -} diff --git a/installation/examples/Calibration/Calibration.ino b/installation/examples/Calibration/Calibration.ino deleted file mode 100755 index 55903bb..0000000 --- a/installation/examples/Calibration/Calibration.ino +++ /dev/null @@ -1,12 +0,0 @@ -#include -signal voice(A0); -void setup(){ - voice.calibrate(); - Serial.begin(9600); -} -void loop(){ - //Serial.println(voice.getPhoneme()); - voice.sample(); - Serial.println(voice.power()); - -} diff --git a/installation/examples/Debug_uSpeech/Debug_uSpeech.ino b/installation/examples/Debug_uSpeech/Debug_uSpeech.ino new file mode 100644 index 0000000..28765c6 --- /dev/null +++ b/installation/examples/Debug_uSpeech/Debug_uSpeech.ino @@ -0,0 +1,42 @@ +#include +signal voice(A0); +char option = 0; +void setup(){ + voice.calibrate(); + Serial.begin(9600); +} +void loop(){ + voice.sample(); + char c=voice.getPhoneme(); + if(option==0){ + Serial.println("uSpeech debug tool--------"); + Serial.println(" Press 'a' if you wish to calibrate/check the f algorithm"); + Serial.println(" Press 'b' if you wish to calibrate/check the getPhoneme"); + Serial.println(" Press 'c' if you wish to calibrate/check the volume of your microphone"); + Serial.println(" Press 'd' if you wish to calibrate/check the coeff"); + Serial.println(" Press 'e' if you wish to calibrate/check the vowel detector"); + option = 1; + } + if(option==1){ + if (Serial.available() > 0) { + // read the incoming byte: + option = Serial.read(); + } + } + if(option=='a'){ + Serial.println(voice.micPower); + } + if(option=='b'){ + Serial.println(c); + } + if(option=='c'){ + Serial.println(voice.power()); + } + if(option=='d'){ + Serial.println(voice.testCoeff); + } + if(option=='e'){ + + Serial.println(voice.vowelRatio); + } +} \ No newline at end of file diff --git a/installation/examples/_SpeechAdvancedTraining/_SpeechAdvancedTraining.ino b/installation/examples/_SpeechAdvancedTraining/_SpeechAdvancedTraining.ino deleted file mode 100644 index 89bdd8a..0000000 --- a/installation/examples/_SpeechAdvancedTraining/_SpeechAdvancedTraining.ino +++ /dev/null @@ -1,58 +0,0 @@ -#include - -signal voice(A0); -int around = 0; -int maxp = 0; -void setup(){ - voice.calibrate(); - Serial.begin(9600); -} -void loop(){ - voice.sample(); - if(around == 0){ - Serial.println("please remain silent"); - } - else{ - if(around < 2000){ - if(voice.power()>maxp){ - maxp = voice.power(); - } - } - else{ - if(around == 2000){ - Serial.print("SILENCE is"); - Serial.print(maxp); - Serial.println("Please say ffff"); - maxp = 0; - } - else{ - if(around < 8000){ - voice.getPhoneme(); - if(maxpvoice.micPower){ - maxp = voice.micPower; - } - } - if(around==12000){ - Serial.print("f2 ="); - Serial.print(maxp); - } - } - } - } - } - } - around++; -} diff --git a/keywords.txt b/keywords.txt index dcd9a5e..58acaf8 100755 --- a/keywords.txt +++ b/keywords.txt @@ -14,6 +14,7 @@ getPhoneme KEYWORD2 snr KEYWORD2 sample KEYWORD2 calibrate KEYWORD2 +power KEYWORD2 ####################################### # Instances (KEYWORD2) ####################################### diff --git a/phoneme.cpp b/phoneme.cpp index 0583e08..72e4770 100755 --- a/phoneme.cpp +++ b/phoneme.cpp @@ -4,9 +4,12 @@ */ char signal::getPhoneme(){ sample(); - if(power()>SILENCE){ + unsigned int pp =power(); + if(pp>SILENCE){ + //Low pass filter for noise removal - int k = complexity(power()); + int k = complexity(pp); + overview[6] = overview[5]; overview[5] = overview[4]; overview[4] = overview[3]; @@ -21,17 +24,19 @@ char signal::getPhoneme(){ f++; } coeff /= 7; + testCoeff = coeff; //Serial.println(coeff); //Use this for debugging #if F_DETECTION > 0 micPower = 0.05 * maxPower() + (1 - 0.05) * micPower; //Serial.println(micPower)//If you are having trouble with fs - - if (micPower > 37/*Replace this value (37) with your own*/) { + if (micPower > F_CONSTANT/*Use the header file to change this*/) { return 'f'; } #endif - //Twiddle with the numbers here if your getting false triggers + zeroCrossingSearch(); + //Twiddle with the numbers here if your getting false triggers //This is the main recognizer part + //Todo: use move values to header file if(coeff<30 && coeff>20){ return 'u'; } @@ -65,18 +70,8 @@ char signal::getPhoneme(){ } } else{ + micPower = 0; return ' '; } } -void signal::formantAnal(){ - int i = 0; - int k = 0; - while(i<18){ - if((long)(filters[i]-filters[i-1]) > 0 & (long)(filters[i]-filters[i+1]) < 0){ - if(k < 3){ - formants[k] = i; - } - } - i++; - } -} + diff --git a/signal.cpp b/signal.cpp index a71ea63..6e4df0c 100755 --- a/signal.cpp +++ b/signal.cpp @@ -75,9 +75,12 @@ unsigned int signal::maxPower(){ while (i<32){ if(max0){ + prev = arr[i]-avgPower; + if(prev<0){ + lower = i; + i = 0; //Break out of loop + } + i--; + } + vowelRatio = (upper-i)*100/lower-i; +} diff --git a/uspeech.h b/uspeech.h index ee7b7b5..7de953f 100755 --- a/uspeech.h +++ b/uspeech.h @@ -1,5 +1,5 @@ /* - uspeech v.1.9.3 (2.0betaRC2) + uspeech v.3.0Alpha 2012 Arjo Chakravarty uspeech is a library that allows sounds to be classified into certain phonemes @@ -11,12 +11,14 @@ #include "Arduino.h" #include -#define SILENCE 92 +#define SILENCE 1500 #define F_DETECTION 3 +#define F_CONSTANT 380 class signal{ public: - int arr[32]; + int arr[32],avgPower; int calib; + int testCoeff; signal(int port); int micPower; void sample(); @@ -26,19 +28,18 @@ class signal{ unsigned long fpowerex(int sum, int xtra); //Todo: Remove int snr(int power); void calibrate(); - unsigned long filters[18], formants[3], intoned; //Todo: Remove unsigned int overview[7]; - char getPhoneme(); - void debugPrintFilter(); //Todo: Remove - void voiceFormants(); //Todo: Remove - //void lowPass(int freq); Todo: Implement moving average low pass filter. + char getPhoneme(); //void lowPass(int freq); Todo: Implement moving average low pass filter. int goertzel(int freq); - + int vowelRatio; + void zeroCrossingSearch(); private: int pin; int mil; + int maxPos; bool silence; void formantAnal(); //Todo: Remove + };