forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStephenHawking.java
More file actions
executable file
·51 lines (33 loc) · 1.15 KB
/
StephenHawking.java
File metadata and controls
executable file
·51 lines (33 loc) · 1.15 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
50
51
package section3;
import javax.swing.JOptionPane;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class StephenHawking {
/*********** 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
* *****************/
// 1. make a main method and put steps 2, 3 & 4 inside it
// 4. Use a for loop to repeat steps #2 and #3, a lot of times
// 2. ask the user for a sentence
// 3. call the speak method below and send it the sentence
/* Don't change this. */
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();
}
}
}
}