FingerPrint_modifed_project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package test;
import javax.speech.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import javax.speech.synthesis.*;
public class Speak {
String voiceName = "kevin16";
String speaktext = "";
public static void main(String[] args) {
Speak speak = new Speak();
boolean check = new File(System.getProperty("user.home"), "speech.properties").exists();
System.out.println("--> speech.properties file exists in "+System.getProperty("user.home")+" = "+check);
if(!check) speak.copyFileUsingStream(new File("speech.properties"), new File(System.getProperty("user.home")+"\\speech.properties"));
speak.message("NRUSINGHA NATH NAYAK","checkout");
}
public void message(String user, String checkin_out){
if(checkin_out.trim().toUpperCase().toLowerCase().equalsIgnoreCase("checkin")){
speaktext = "WELCOME "+user+". YOUR CHECK IN TIME IS "+getCurrentTime();
}else if(checkin_out.trim().toUpperCase().toLowerCase().equalsIgnoreCase("checkout")){
speaktext = "GOOD BYE "+user+". YOUR CHECK OUT TIME IS "+getCurrentTime();
}else{
speaktext = " "+user;
}
try{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++){
if (voices[i].getName().equals(voiceName)){
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
System.out.print("Speaking : "+speaktext);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}catch (Exception e){
String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
copyFileUsingStream(new File("speech.properties"), new File(System.getProperty("user.home")+"\\speech.properties"));
System.out.println(""+e);
System.out.println(message);
}
}
public String getCurrentTime(){
String time = "";
Date curr_date = new Date();
int hh = curr_date.getHours();
int mm = curr_date.getMinutes();
/*if(hh>=0 && hh < 12){
if(hh == 0)
time = "TWELVE "+mm+" AM";
else
time = hh+" "+mm+" AM";
}else
time = (hh-12)+" "+mm+" PM";*/
String hh_str = "";
String am_pm = "";
switch (hh) {
case 0 : hh_str = "TWELVE "; am_pm = "AM"; break;
case 10: hh_str = "TEN "; am_pm = "AM"; break;
case 11: hh_str = "ELEVEN "; am_pm = "AM"; break;
case 12: hh_str = "TWELVE "; am_pm = "PM"; break;
case 13: hh_str = "ONE "; am_pm = "PM"; break;
case 14: hh_str = "TWO "; am_pm = "PM"; break;
case 15: hh_str = "THREE "; am_pm = "PM"; break;
case 16: hh_str = "FOUR "; am_pm = "PM"; break;
case 17: hh_str = "FIVE "; am_pm = "PM"; break;
case 18: hh_str = "SIX "; am_pm = "PM"; break;
case 19: hh_str = "SEVEN "; am_pm = "PM"; break;
case 20: hh_str = "EIGHT "; am_pm = "PM"; break;
case 21: hh_str = "NINE "; am_pm = "PM"; break;
case 22: hh_str = "TEN "; am_pm = "PM"; break;
case 23: hh_str = "ELEVEN "; am_pm = "PM"; break;
default: hh_str = " "+hh ; am_pm = "AM"; break;
}
time = hh_str+" "+mm+" "+am_pm;
return time;
}
public void copyFileUsingStream(File source, File dest){
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(source);
os = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
System.out.println("--> speech.property file copied to "+dest.getAbsolutePath());
} catch(Exception e){e.printStackTrace();}finally {try {is.close();os.close();} catch (Exception e) {e.printStackTrace();}}
}
}
|
Revision |
Author |
Commited |
Message |
1
|
girijabapi
|
Fri 27 Jul, 2018 07:20:23 +0000 |
|