forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpeakAndSpell.java
More file actions
executable file
·51 lines (35 loc) · 1.19 KB
/
SpeakAndSpell.java
File metadata and controls
executable file
·51 lines (35 loc) · 1.19 KB
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
package section3;
import javax.swing.JOptionPane;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class SpeakAndSpell {
/*********** SOUND ***************
* This recipe requires a computer that can play sounds.
* If you cannot play sound on this computer, skip this recipe.
* If you are not sure, ask your teacher
* *****************/
public static void main(String[] args) {
// 1. Use the speak method to say the word. "e.g. spell mandlebrot"
// 2. Catch the user's answer in a String
// 3. If the user spelled the word correctly, speak "correct"
// 4. Otherwise say "wrong"
// 5. repeat the process for other words
}
static void speak(String words) {
if (System.getProperty("os.name").contains("Windows")) {
String cmd = "PowerShell -Command \"Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('"
+ words + "');\"";
try {
Runtime.getRuntime().exec(cmd).waitFor();
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
Runtime.getRuntime().exec("say " + words).waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}