-
Notifications
You must be signed in to change notification settings - Fork 2
/
VoiceInputToolbox.java
53 lines (44 loc) · 1.37 KB
/
VoiceInputToolbox.java
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
package me.atom.windowsj;
import java.util.UUID;
import java.net.*;
import java.io.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
/**
*
* VoiceInputoolbox.java created by Guillaume Cendre (aka chlkbumper)
*
* This class is kind of a bridge between the DialogWindow class and
* the JavaSoundRecorder class. It generates an unique identifier for
* the audio record that will be used to reference it through all the
* steps of the speech recognition.
*
*/
public class VoiceInputToolbox {
static String uuid;
final static JavaSoundRecorder recorder = new JavaSoundRecorder();
public static void startRecording() {
///play a Siri-like sound effect ... Just for fun
try{
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("sounds/mictap.wav").getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
}catch(Exception ex){
System.out.println("Error with playing sound.");
ex.printStackTrace();
}
//////End
uuid = UUID.randomUUID().toString();
System.out.println(uuid);
recorder.start(uuid);
}
public static void stopRecording() throws MalformedURLException{
try {
recorder.finishAndProcess(uuid);
} catch (IOException e) {
e.printStackTrace();
}
}
}