Skip to content

Commit

Permalink
добавлена Нечеткое сравнение строк
Browse files Browse the repository at this point in the history
  • Loading branch information
3XclusiVe committed Nov 17, 2016
1 parent 27b4fc9 commit 1a54c38
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added AudioTestNow.flac
Binary file not shown.
Binary file added java-string-similarity-0.19.jar
Binary file not shown.
84 changes: 84 additions & 0 deletions src/com/company/Ambient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.company;

import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
import com.darkprograms.speech.recognizer.GoogleResponse;
import com.darkprograms.speech.recognizer.Recognizer;
import javaFlacEncoder.FLACFileWriter;

import java.io.File;

/**
* Created by user on 16.11.16.
*/
public class Ambient {

public static void main(String[] args) {

MicrophoneAnalyzer mic = new MicrophoneAnalyzer(FLACFileWriter.FLAC);
mic.setAudioFile(new File("AudioTestNow.flac"));
while(true){
mic.open();
final int THRESHOLD = 20;
int volume = mic.getAudioVolume(10);
boolean isSpeaking = (volume > THRESHOLD);

if(isSpeaking){
try {
System.out.println("RECORDING...");
mic.captureAudioToFile(mic.getAudioFile());//Saves audio to file.
do{
Thread.sleep(2000);//Updates every second
}
while(mic.getAudioVolume(100) > THRESHOLD);
System.out.println("Recording Complete!");
System.out.println("Recognizing...");
Recognizer rec = new Recognizer(Recognizer.Languages.RUSSIAN, "AIzaSyDMRFZsdncfP2udmTbozAQ2owJuL5RRm34");
GoogleResponse response = rec.getRecognizedDataForFlac(mic.getAudioFile(), 3);
displayResponse(response);//Displays output in Console

reckognizeResponce(response);

System.out.println("Looping back");//Restarts loops
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error Occured");
}
finally{
mic.close();//Makes sure microphone closes on exit.
}
}
}
}

private static void displayResponse(GoogleResponse gr){
if(gr.getResponse() == null){
System.out.println((String)null);
return;
}
System.out.println("Google Response: " + gr.getResponse());
System.out.println("Google is " + Double.parseDouble(gr.getConfidence())*100 + "% confident in"
+ " the reply");
System.out.println("Other Possible responses are: ");
for(String s: gr.getOtherPossibleResponses()){
System.out.println("\t" + s);
}
}

private static void reckognizeResponce(GoogleResponse gr){
if(gr.getResponse() == null){
System.out.println((String)null);
return;
}

VoiceCommands vc = new VoiceCommands();

vc.isCommand(gr.getResponse());


for(String s: gr.getOtherPossibleResponses()){
vc.isCommand(s);
}
}

}
18 changes: 18 additions & 0 deletions src/com/company/StringSimilarityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.company;

import info.debatty.java.stringsimilarity.JaroWinkler;

/**
* Created by user on 17.11.16.
*/
public class StringSimilarityTest {
public static void main (String[]args) {
JaroWinkler jw = new JaroWinkler();

// substitution of s and t
System.out.println(jw.similarity("начать обучение", "начать обучение"));

// substitution of s and n
System.out.println(jw.similarity("My string", "My ntrisg"));
}
}
51 changes: 51 additions & 0 deletions src/com/company/VoiceCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.company;

import info.debatty.java.stringsimilarity.JaroWinkler;

/**
* Created by user on 17.11.16.
*/
public class VoiceCommands {

private static final String startTraining = "начать";
private static final String poseType = "новая поза";
private static final String capturePose = "фиксация";
private static final String completeTraining = "закончить";

private JaroWinkler jaroWinkler = new JaroWinkler();

public boolean isCommand(String command) {

if(isLooksLike(command, startTraining)) {
System.out.println(startTraining);
}

if(isLooksLike(command, poseType)) {
System.out.println(poseType);
}

if(isLooksLike(command, capturePose)) {
System.out.println(capturePose);
}

if(isLooksLike(command, completeTraining)) {
System.out.println(completeTraining);
}

return false;

}

private boolean isLooksLike(String command, String etalon) {

double tresHold = 0.7;
double similaruty = jaroWinkler.similarity(command, etalon);

if(similaruty >= tresHold) {
return true;
}

return false;
}

}
1 change: 1 addition & 0 deletions test_google_speach_api.iml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="library" name="java-string-similarity-0.19" level="project" />
</component>
</module>
Binary file added wav.test
Binary file not shown.

0 comments on commit 1a54c38

Please sign in to comment.