text to speech in java using freetts - java

I am using freetts jar file for text to speech.
But I need much more voices like Indian English.
There my code is:
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
class s
{
VoiceManager freettsVM;
Voice freettsVoice;
private Voice voice;
public s(String voiceName)
{
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(voiceName);
}
public void speak(String msg) {
freettsVoice.allocate();
freettsVoice.speak(msg);
freettsVoice.deallocate();
}
}
public class Main {
public static void main(String[] args) {
String speekstring = txtmassage.getText();
s t = new s("kevin16");
t.speak(speekstring);}
}
It’s work correctly, but I need more voices.
now i changed my code into
then there error is
Could not validate any MBROLA voices at
C:/Users/anand/Documents/NetBeansProjects/mbrola
Make sure you FULLY specify the path to
the MBROLA directory using the mbrola.base
system property.
Exception in thread "main" java.lang.NullPointerException
at newpro.TestTTS.<init>(TestTTS.java:20)
at newpro.TestTTS.main(TestTTS.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

You could use the MBROLA - Project. It's free and offers
several languages.
You will need to download the project-package itself and the voices.
For a step-by-step guide on how to install and use MBROLA you can go to here:
https://stackoverflow.com/a/26236563/1368690
Or go to the project page itself:
http://tcts.fpms.ac.be/synthesis/mbrola.html
When you scroll down a bit, there a lots of voice you can test and see, if they will be usefull for you.

Related

Why the exported to desktop (.exe) processing app with java classes can not run properly? My another project was exported without problems

I try to export my processing app as the "ready to use" application with exe launch file for desktop.
My code is pretty simple. Proccessing code:
//import io.itch.mgdsstudio.airfight.connecteddevices.*;
private io.itch.mgdsstudio.airfight.connecteddevices.Controller controller;
void setup(){
size(600,800, JAVA2D);
background(0);
//I think the next code line can not be launched after export. Background stays black
controller = new io.itch.mgdsstudio.airfight.connecteddevices.Controller(this);
}
void draw(){
controller.render();
}
and the java-class:
package io.itch.mgdsstudio.airfight.connecteddevices;
import processing.core.PApplet;
public class Controller {
private PApplet engine;
public Controller(PApplet engine) {
this.engine = engine;
}
public void render(){
engine.background(255,0,0);
}
}
The application runs perfect from processing ide - the screen is red. But after export it can not run properly. The screen is black. I tested processing 3 and 4. In january I exported an another application succesfully. But now I can not launch exported file. I think the trouble is in versions of the java source files.
I tried to change code so:
import io.itch.mgdsstudio.airfight.connecteddevices.Controller;
private Controller controller;
void setup(){
size(600,800, JAVA2D);
background(0);
controller = new Controller(this);
}
void draw(){
controller.render();
}
I receive the message in the console:
No library found for io.itch.mgdsstudio.airfight.connecteddevices
but it runs in the ide. But after export it can not run properly again. Maybe i need another package names?
There seems to be an issue/bug using package inside the Processing IDE.
As you hinted in your comments, if you could compile a .jar in your Java IDE of choice and use that in Processing that should work.
From a pragmatic point of view, if you don't plan on fixing the Processing IDE to handle package as expected, you can simply not use it your code:
import processing.core.PApplet;
public class Controller {
private PApplet engine;
public Controller(PApplet engine) {
this.engine = engine;
}
public void render(){
engine.background(255,0,0);
}
}
Controller controller;
void setup(){
size(600,800, JAVA2D);
background(0);
controller = new Controller(this);
}
void draw(){
controller.render();
}
This wouldn't be convenient on a larger project where you may want to write Java code in your preferred IDE but still be able to colaborate with others that use the Processing IDE alone.
Since running in the Processing IDE works (e.g. dev/testing), but can't export a .exe for easy deployment, a workaround could be using the processing-java command. (If you add your Processing installation folder to the Windows %PATH% environment variable you should be able to type processing-java in a new Command Prompt window and see the help/usage guide).
Running processing-java --sketch=path\to\YourSketchFolder --run should run the sketch the same way the Processing IDE does (without actually having the IDE open). While this implies installing Processing and adding it to %PATH% on any new machine on one hand, on the other it saves you the time of having rebuild/repackage new .exe files for every single change.

MBROLA voices with FreeTTS - Windows

Using MBROLA voices in a Java program with FreeTTS...
I am working on a simple text-to-speech program in Java. I have decided to use FreeTTS, but the voices are not really what I was thinking, and I was looking to use a female voice anyway. So I started looking around, and decided that I would use MBROLA to change the voice of my text-to-speech program.
I read that "FreeTTS can use MBROLA voices", but I searched everywhere and couldn't find a clear guide how to set MBROLA up, and what files are needed to do so. There are many forums on MBROLA working alongside FreeTTS, however it also seems that none of the people have any idea what they are doing.
So the questions:
What files need to be downloaded?
Steps to include these into my program?
Simple FreeTTS example using MBROLA voices?
Answers to the questions above:
1. What files need to be downloaded?
FreeTTS with all the libraries (freeTTS 1.2.2-bin) - download here
MBROLA zip folder mbr301d.zip
Voices which can be found on the MBROLA website
1.1 The FreeTTS libraries (found in freetts-1.2.2-bin/freetts-1.2/lib):
cmu_time_awb.jar
cmu_us_kal.jar
cmudict04.jar
cmulex.jar
cmutimelex.jar
en_us.jar
freetts.jar
freetts-jsapi10.jar
mbrola.jar
1.2 The MBROLA zip folder will include:
mbrola.exe
mbr302a (folder)
readme.txt
1.3 The Voices are zipped folders that include a single folder named 'us1' or 'af1' etc.
2. Steps to include these into my program?
NOTE: I had the MBROLA Tooklit installed on my computer too, however I am unsure whether it has an impact on the program, but I suspect that it doesn't. EDIT: I have tested to see whether the MBROLA toolkit is needed to run MBROLA alongside FreeTTS, and it turns out that it is not needed.
Extract freetts-1.2.2-bin
Copy the libraries to your project and include in build path
Unzip the mbr301d.zip folder
Rename 'mbr301d' to 'mbrola'
Unzip the voices to the folder you named 'mbrola'
After this is done, your mbrola folder should look like this:
[mbr302a] - folder
[us1] - folder (name depends on the language you downloaded)
mbrola.exe - file
readme.txt - file
You can place all your languages in this folder, and they will just be called from your Java program.
3. Simple FreeTTS example using MBROLA voices?
I've seen many people get this error:
System property "mbrola.base" is undefined. Will not use MBROLA voices.
The mbrola.base refers to where your mbrola files are located on your computer, and without the property being pointed to the correct location, you will recieve this error.
To NON-MBROLA users who get this error: Simply remove the mbrola.jar from your referenced libraries if you're only using FreeTTS
To set the mbrola.base property, use:
System.setProperty("mbrola.base", "C:/Path/to/your/mbrola")
Below is a simple Example to use the MBROLA voices in your FreeTTS program. Note that the steps above must be done before this will work. Simply changing the name of the voice to "mbrola_us1" will not work if the base isn't set!
package com.madmob.test;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TestTTS {
VoiceManager freettsVM;
Voice freettsVoice;
public TestTTS(String words) {
// Most important part!
System.setProperty("mbrola.base", "C:/mbrola");
freettsVM = VoiceManager.getInstance();
// Simply change to MBROLA voice
freettsVoice = freettsVM.getVoice("mbrola_us1");
// Allocate your chosen voice
freettsVoice.allocate();
sayWords(words);
}
public void sayWords(String words) {
// Make her speak!
freettsVoice.speak(words);
}
public static void main(String [] args) {
new TestTTS("Hello there! Now M BROLA and Free T T S work together!");
}
}
MBROLA and FreeTTS should now be working together! This code was copied right from my computer and has been tested before putting it down here.
Thanks to responses on this forum, I was finally able to make it working.
On windows 10; I carried out following steps to make it working:
Download freeTTS libraries and include them in my Java project in eclipse.
Download mbr301d.zip, extract it in a folder named mbrola within my project
Download mbrola database for us1, us2, us3 and en1 from http://www.tcts.fpms.ac.be/synthesis/mbrola/mbrcopybin.html
extract the voice DB zips downloaded in previous step directly in mbrola folder - don't change names of the folders.
include following code pieces to use it:
System.setProperty("mbrola.base", "ABSOLUTE_PATH_TO_mbrola_directory_ending_with_/");
voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice("mbrola_us1");
Note: if your voice DB folder name is us1; then you should add it above as "mbrola_us1"; if it is en1, then it should be "mbrola_en1". This actually has done the trick for me.
Please find working example from here:
https://github.com/sunrise-projects/sphinx4/tree/glass
package com.sunriseprojects.freetts.demo;
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;
public class SpeechUtils {
SynthesizerModeDesc desc;
Synthesizer synthesizer;
Voice voice;
public void init(String voiceName) throws EngineException, AudioException,
EngineStateError, PropertyVetoException {
if (desc == null) {
//default
// System.setProperty("freetts.voices",
// "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
//have to be setup
System.setProperty("freetts.voices",
"de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory");
desc = new SynthesizerModeDesc(Locale.US);
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
SynthesizerModeDesc smd = (SynthesizerModeDesc) synthesizer
.getEngineModeDesc();
Voice[] voices = smd.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);
}
}
public void terminate() throws EngineException, EngineStateError {
synthesizer.deallocate();
}
public void doSpeak(String speakText) throws EngineException,
AudioException, IllegalArgumentException, InterruptedException {
synthesizer.speakPlainText(speakText, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
}
public static void main(String[] args) throws Exception {
System.setProperty("mbrola.base", "C:\\lnx1\\home\\ggon\\git-projects\\mbrola");
SpeechUtils su = new SpeechUtils();
//have to be setup on your env
su.init("mbrola_us1");
//default
//su.init("kevin16");
//su.init("kevin");
//su.doSpeak("Hello world!");
su.doSpeak(SAMPLE);
su.terminate();
}
final static String SAMPLE = "Wiki said, Floyd Mayweather, Jr. is an American professional boxer. He is currently undefeated as a professional and is a five-division world champion, having won ten world titles and the lineal championship in four different weight classes";
}

API to read text from Image file using OCR

I am looking out for an example code or API name from OCR (Optical character recognition) in Java using which I can extract all text present from an image file. Without comparing it with any image which I am doing using below code.
public class OCRTest {
static String STR = "";
public static void main(String[] args) {
OCR l = new OCR(0.70f);
l.loadFontsDirectory(OCRTest.class, new File("fonts"));
l.loadFont(OCRTest.class, new File("fonts", "font_1"));
ImageBinaryGrey i = new ImageBinaryGrey(Capture.load(OCRTest.class, "full.png"));
STR = l.recognize(i, 1285, 654, 1343, 677, "font_1");
System.out.println(STR);
}
}
You can try Tess4j or JavaCPP Presets for Tesseract. I perfer later as its easier than the former.
Add the dependency to your pom `
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>tesseract-platform</artifactId>
<version>3.04.01-1.3</version>
</dependency>
`
And its simple to code
import org.bytedeco.javacpp.*;
import static org.bytedeco.javacpp.lept.*;
import static org.bytedeco.javacpp.tesseract.*;
public class BasicExample {
public static void main(String[] args) {
BytePointer outText;
TessBaseAPI api = new TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api.Init(null, "eng") != 0) {
System.err.println("Could not initialize tesseract.");
System.exit(1);
}
// Open input image with leptonica library
PIX image = pixRead(args.length > 0 ? args[0] : "/usr/src/tesseract/testing/phototest.tif");
api.SetImage(image);
// Get OCR result
outText = api.GetUTF8Text();
System.out.println("OCR output:\n" + outText.getString());
// Destroy used object and release memory
api.End();
outText.deallocate();
pixDestroy(image);
}
}
Tess4j is little complex as its requires specific VC++ redistributable package to be installed.
You can try javaocr on sourceforge: http://javaocr.sourceforge.net/
There is also a great example with an applet which uses Encog: http://www.heatonresearch.com/articles/42/page1.html
That said, OCR requires a lot of power, so it means that if you are looking for a heavy use, you should look after OCR libraries written in C and integrate that with Java.
OCR is hard. So be sure to qualify your needs before adventuring yourself in it.
Tesseract and opencv (with javacv for integration for instance) are common choices. There are also commercial solutions such as ABBYY FineReader Engine and ABBYY Cloud OCR SDK.
Open Source OCR engine is available from Google for OCR.
It can be processed using CMD. You can process the CMD using java for web applications easily. Please visit https://www.youtube.com/watch?v=Mjg4yyuqr5E
. You will get the step by step details to process OCR using CMD.

fannj library doesn't work

I'm trying to run project which uses fannj library, but I'm getting error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'fann_create_standard_array':
at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:347)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:327)
at com.sun.jna.Native.register(Native.java:1355)
at com.sun.jna.Native.register(Native.java:1032)
at com.googlecode.fannj.Fann.<clinit>(Fann.java:46)
at javaapplication9.JavaApplication9.main(JavaApplication9.java:14)
Java Result: 1
This is what I did:
I put fannfloat.dll to C:\Windows\System32
I added fannj-0.3.jar to project
I added newest jna.jar to project
here is code:
public static void main(String[] args) {
System.setProperty("jna.library.path", "C:\\Windows\\System32");
System.loadLibrary("fannfloat");
Fann fann=new Fann("D:\\SunSpots.net");
fann.close();
}
SunSpots.net is file from example package. fannfloat.dll: you can get from here.
The "#8" at the end of _fann_create_standard_array indicates that the library is using the stdcall calling convention, so your library interface needs to implement that interface (StdCallLibrary) and it will automatically get the function name mapper applied that converts your simple java name to the decorated stdcall one.
This is covered in the JNA documentation.
It was the first time I had to work with FANN and it took me some time to make it work.
Downloaded Fann 2.2.0. Extract (in my case "C:/FANN-2.2.0-Source") and check the path of the fannfloat.dll file. This is the library that we will use later.
Download fannj-0.6.jar from http://code.google.com/p/fannj/downloads/list.
The dll is compiled for 32 bit environment. So, make sure you have a 32 bit Java installed (even in 64 bit Windows).
I suppose you already have the .net file with your ANN. Write something like this in Java
public class FannTest {
public static void main(String[] args) {
System.setProperty("jna.library.path", "C:/FANN-2.2.0-Source/bin");
Fann fann = new Fann("C:/MySunSpots.net" );
float[] inputs = new float[]{0.686470295f, 0.749375936f, 0.555167249f, 0.816774838f, 0.767848228f, 0.60908637f};
float[] outputs = fann.run( inputs );
fann.close();
for (float f : outputs) {
System.out.print(f + ",");
}
}
}

How to set the runtime of JiST/SWANS within eclipse

This is my first post on the forum, hope all of you guys are well.
I've got a issue using JiST/SWANS, the ad hoc simulator in java within eclipse.
I managed to load the API, (as an external JAR ofcourse) but Im basically having a problem integrating the runtime of JiST within eclipse.
After running the hello world im usually getting a stackoverflowerror exception, since it may need modifications within the runtime.
import jist.runtime.JistAPI;
public class hello implements JistAPI.Entity {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("simulation start");
hello t = new hello();
t.myEvent();
}
public void myEvent()
{
JistAPI.sleep(1);
myEvent();
System.out.println("hello world, t=" + JistAPI.getTime());
}
}
the website is: http://jist.ece.cornell.edu/index.html
Thank you in advance!
Actually you need to run Main.java within jist.runtime. But before rigth click Main.java, properties, Run/Debug settings, New,Arguments and type your class name (plain name no .java needed) in Progam arguments. This will tell the jist interface to translate your code using the rewriter and run it.
Examples:
To run hello.java type "hello"
To run aodvsim.java type: "jist.swans.Main driver.aodvsim"
If there are arguments needed type them after the clas name like: "jist.swans.Main driver.aodvsim -n 25 -f 2000x2000 -a grid:5x5 -t 10,600,60"
Wilmer Arellano
How well does SWANS work? Given that the documentation and code date back to 2005, I am not sure if this is the best platform to use.

Categories