Trying to write FreeTTS to file
in
Contributed Library Questions
•
3 years ago
Hi,
I have been using this class code to access the FreeTTS API and can access some of the features of voice manipulation. I would like to save the synth stream to file but I'm struggling to do this.
I know I have all the FreeTTS files and Mbrola correctly installed as I can hear the speech synth working.
But when I try to save to file by using SingleFileAudioPlayer I cant seem to find the wave file - it doesn't seem to be saving it.
Here is the code, I have highlighted the suspect code in red:
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
import javax.sound.sampled.AudioFileFormat;
public class Basnik {
String voiceName = "us2";
float Pitch = 20.0;
float pitchShift = 20.0;
VoiceManager voiceManager;
Voice voice;
Basnik(String name, float pitch, float pitchshift){
pitchShift = pitchshift;
Pitch = pitch;
voiceName = name;
this.setup();
}
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)");
}
}
void setup() {
listAllVoices();
System.out.println();
System.out.println("Using voice: " + voiceName);
voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(voiceName);
voice.setAudioPlayer(new SingleFileAudioPlayer("C:\\max.wav",javax.sound.sampled.AudioFileFormat.Type.WAVE));
voice.setRate(30.0);
voice.setPitch(Pitch);
voice.setPitchShift(pitchShift);
voice.setPitchRange(200.1); //mutace
voice.setStyle("casual"); //"business", "casual", "robotic", "breathy"
if (voice == null) {
System.err.println(
"Cannot find a voice named "
+ voiceName + ". Please specify a different voice.");
System.exit(1);
}
voice.allocate();
}
void mluv(String _a){
if(_a==null){
_a= "nothing";
}
voice.speak(_a);
}
void exit(){
voice.deallocate();
}
}
The main code for the programme is then
Basnik verlaine ;
void setup(){
System.setProperty("mbrola.base","C:\\mbrola");
verlaine = new Basnik("mbrola_us3",20.0,20.0);
verlaine.mluv("I'm finding this difficult") ;
}
Why is the file not saving? I have tried various permutations of the file name C:\max, C:\max.wav etc..
Please help!
I have been using this class code to access the FreeTTS API and can access some of the features of voice manipulation. I would like to save the synth stream to file but I'm struggling to do this.
I know I have all the FreeTTS files and Mbrola correctly installed as I can hear the speech synth working.
But when I try to save to file by using SingleFileAudioPlayer I cant seem to find the wave file - it doesn't seem to be saving it.
Here is the code, I have highlighted the suspect code in red:
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
import javax.sound.sampled.AudioFileFormat;
public class Basnik {
String voiceName = "us2";
float Pitch = 20.0;
float pitchShift = 20.0;
VoiceManager voiceManager;
Voice voice;
Basnik(String name, float pitch, float pitchshift){
pitchShift = pitchshift;
Pitch = pitch;
voiceName = name;
this.setup();
}
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)");
}
}
void setup() {
listAllVoices();
System.out.println();
System.out.println("Using voice: " + voiceName);
voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(voiceName);
voice.setAudioPlayer(new SingleFileAudioPlayer("C:\\max.wav",javax.sound.sampled.AudioFileFormat.Type.WAVE));
voice.setRate(30.0);
voice.setPitch(Pitch);
voice.setPitchShift(pitchShift);
voice.setPitchRange(200.1); //mutace
voice.setStyle("casual"); //"business", "casual", "robotic", "breathy"
if (voice == null) {
System.err.println(
"Cannot find a voice named "
+ voiceName + ". Please specify a different voice.");
System.exit(1);
}
voice.allocate();
}
void mluv(String _a){
if(_a==null){
_a= "nothing";
}
voice.speak(_a);
}
void exit(){
voice.deallocate();
}
}
The main code for the programme is then
Basnik verlaine ;
void setup(){
System.setProperty("mbrola.base","C:\\mbrola");
verlaine = new Basnik("mbrola_us3",20.0,20.0);
verlaine.mluv("I'm finding this difficult") ;
}
Why is the file not saving? I have tried various permutations of the file name C:\max, C:\max.wav etc..
Please help!
1