-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters