Skip to content

Commit

Permalink
Switched from JSAPI to FreeTTS directly
Browse files Browse the repository at this point in the history
  • Loading branch information
armageddon421 committed Feb 18, 2014
1 parent 3540dd7 commit e22692b
Showing 1 changed file with 27 additions and 60 deletions.
87 changes: 27 additions & 60 deletions src/Webcam.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.util.Locale;

import javax.speech.AudioException;
import javax.speech.Central;
import javax.speech.EngineException;
import javax.speech.EngineStateError;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.Voice;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
Expand All @@ -26,19 +17,26 @@
import org.opencv.highgui.VideoCapture;
import org.opencv.imgproc.Imgproc;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;


public class Webcam {

static Synthesizer synthesizer1;

static VideoCapture camera;
static Voice voice;

public static void main(final String args[]) {

System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java248");

listAllVoices();
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice("kevin16");
voice.allocate();

camera = new VideoCapture();


Expand All @@ -50,52 +48,6 @@ public static void main(final String args[]) {
System.out.println("Camera OK?");
}

Voice kevinHQ = new Voice("kevin",
Voice.GENDER_DONT_CARE, Voice.AGE_DONT_CARE, null);


SynthesizerModeDesc generalDesc = new SynthesizerModeDesc(
null, // engine name
"general", // mode name
Locale.US, // locale
null, // running
null); // voice

try {
synthesizer1 =
Central.createSynthesizer(generalDesc);

synthesizer1.allocate();


try {
synthesizer1.getSynthesizerProperties().setVoice(kevinHQ);
synthesizer1.getSynthesizerProperties().setPitch(10);
synthesizer1.getSynthesizerProperties().setPitchRange(0);

} catch (PropertyVetoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
synthesizer1.resume();
} catch (AudioException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (EngineStateError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synthesizer1.speakPlainText("Hello!", null);


} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

while (camera.isOpened()) {
Mat frame = new Mat();
Expand Down Expand Up @@ -125,6 +77,17 @@ public static void main(final String args[]) {
}
}

public static void listAllVoices() {
System.out.println();
System.out.println("All voices available:");
VoiceManager voiceManager = VoiceManager.getInstance();
Voice[] voices = voiceManager.getVoices();
for (int i = 0; i < voices.length; i++) {
System.out.println(" " + voices[i].getName()
+ " (" + voices[i].getDomain() + " domain)");
}
}

public static Image toBufferedImage(Mat m) {
int type = BufferedImage.TYPE_BYTE_GRAY;
if (m.channels() > 1) {
Expand Down Expand Up @@ -156,6 +119,7 @@ public void windowClosing(final WindowEvent e) {
if (i == 0)
{
frame.dispose();
voice.deallocate();
camera.release();
System.exit(0);// kill aplicacion
}
Expand Down Expand Up @@ -515,9 +479,12 @@ else if (coldet[x] >= 0) {
valuestring = String.format("%d%s\n", (int) resistance, unit);
}
System.out.println(valuestring);
if ((synthesizer1.getEngineState() & Synthesizer.QUEUE_EMPTY) > 0) {
synthesizer1.speakPlainText(valuestring, null);
}
// if(voice.getOutputQueue().)
voice.speak(valuestring);
// if ((synthesizer1.getEngineState() &
// Synthesizer.QUEUE_EMPTY) > 0) {
// synthesizer1.speakPlainText(valuestring, null);
// }
contfound = 0;
}
}
Expand Down

0 comments on commit e22692b

Please sign in to comment.