I'm creating .wav
files using marytts.
The kpbs of .wav
files changing according to voice I'm using with the code below. I would like to write every audio file in 128 kpbs.
Due to the program I am planning to use generated .wav
files and only supports 128 kpbs, is there a way to write the .wav
files always 128kpbs?
This is my code:
AudioInputStream audio = marytts.generateAudio(text); //generate audio from text
AudioSystem.write(audio, AudioFileFormat.Type.WAVE, new File("F:\\temp\\" + filename + ".wav"));//save audio as .wav to the static location with filename
return true;//function completed so return true
I managed to find an answer to my question.
Maybe later someone also ask the same so I'm giving my solution.
Under the class I wrote these global variables as I wanted my wav
static AudioFormat.Encoding defaultEncoding = AudioFormat.Encoding.PCM_SIGNED;
static float fDefaultSampleRate = 8000;
static int nDefaultSampleSizeInBits = 16;
static int nDefaultChannels = 1;
static int frameSize = 2;
static float frameRate= 8000;
static boolean bDefaultBigEndian = false;
And changed my code like this.
I created a format as I wanted, generated audio from text, changed audio in my format and wrote it.
AudioFormat defaultFormat = new AudioFormat(defaultEncoding,fDefaultSampleRate,nDefaultSampleSizeInBits,nDefaultChannels,frameSize,frameRate,bDefaultBigEndian);
AudioInputStream GeneratedAudio = marytts.generateAudio(text); //generate audio from text
AudioInputStream audio = AudioSystem.getAudioInputStream(defaultFormat, GeneratedAudio);
AudioSystem.write(audio, AudioFileFormat.Type.WAVE, new File("F:\\temp\\" + filename + ".wav"));//save audio as .wav to the static location with filename
return true;//function completed so return true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With