Java FreeTTS Missing Voice
I wrote a small program that should just do text to speech in Java.
My class looks like this:
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TalkResource {
private static final String VOICENAME_kevin = "kevin16";
private final String text; // string to speech
public TalkResource(String text) {
this.text = text;
}
public void speak() {
Voice voice;
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(VOICENAME_kevin);
voice.allocate();
String newText = "example";
voice.speak(newText);
}
}
I'm sure the syntax (and stuff) is correct, but mine is voice
always mine null
.
I am assuming "kevin16" is not found and is not included in the project, but I just cannot figure out how to add any voice to my project. To get dependencies I use maven
.
<dependency>
<groupId>net.sf.sociaal</groupId>
<artifactId>freetts</artifactId>
<version>1.2.2</version>
</dependency>
Everything is there, except for the voices. From what I've read, I am guessing that "kevin16" should be included in FreeTTS. Any ideas how to proceed? How do I add a voice? Also I found something about MBROLA
, but that just made me even more obscure: /
Thanks for any help.
source to share
I had exactly the same problem. I was getting an empty list when I tried to call voiceManager.getVoices()
. The problem was that the system property was freetts.voices
not set. So adding the following line fixed my problem:
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
Now I can use kevin or kevin16 .
Hope it helps.
source to share
Have you ever named your speaking method somewhere?
Try something like this:
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TalkResource {
private static final String VOICENAME_kevin = "kevin16";
public TalkResource(String sayText) {
Voice voice;
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(VOICENAME_kevin);
voice.allocate();
voice.speak(sayText);
}
public static void main(String []args) {
new TalkResource("hello");
}
}
I'm going to take a stab at it and say that you are more familiar with Maven servers than I am, however I play around with the FreeTTS and MBROLA voices a lot and I never had a problem with just linking the freetts library in my project.
If you feel like checking out MBROLA I have a decent thread on how to set it up here
source to share
It didn't work either. I used a different repository (you need to modify the POM file). I used the following dependencies:
<dependencies>
<dependency>
<groupId>org.mobicents.external.freetts</groupId>
<artifactId>freetts</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.mobicents.external.freetts</groupId>
<artifactId>en_us</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.mobicents.external.freetts</groupId>
<artifactId>cmu_us_kal</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.mobicents.external.freetts</groupId>
<artifactId>cmu_time_awb</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.mobicents.external.freetts</groupId>
<artifactId>cmulex</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.mobicents.external.freetts</groupId>
<artifactId>cmutimelex</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.mobicents.external.freetts</groupId>
<artifactId>cmudict04</artifactId>
<version>1.2.2</version>
</dependency>
For this I used the following repositories:
<repository>
<id>sonatype-oss-public</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
source to share
Just add the first line to your main
enter code here
public static void main(String[] args) throws Exception{
// TODO code application logic here
System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
String message = "Hello world! This is a test program";
Mehrunisa mehrunisa = new Mehrunisa(message);
mehrunisa.speak();
}
source to share