added TTS audio node, and included it in BaseGame

This commit is contained in:
DaniTheSkunk 2022-11-27 07:14:12 +00:00
parent eb9671a51a
commit 2d002f3632
4 changed files with 52 additions and 35 deletions

View File

@ -15,6 +15,9 @@
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jna/jna-platform-5.12.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/lwjgl/lwjgl-openal-natives-windows.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/lwjgl/lwjgl-openal.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/marytts/marytts-lang-en-5.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/marytts/marytts-runtime-5.2-jar-with-dependencies.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/marytts/voice-cmu-slt-hsmm-5.2.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@ -5,6 +5,7 @@ import com.danitheskunk.skunkworks.audio.ISample;
import com.danitheskunk.skunkworks.audio.nodes.Mixer;
import com.danitheskunk.skunkworks.audio.nodes.Node;
import com.danitheskunk.skunkworks.audio.nodes.SamplePlayer;
import com.danitheskunk.skunkworks.audio.nodes.TTS;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
import com.danitheskunk.skunkworks.gfx.ITexture;
@ -31,6 +32,7 @@ public abstract class BaseGame {
protected final Mixer mixer;
protected final NodeRoot rootNode;
protected final SamplePlayer samplePlayer;
protected final TTS tts;
protected final IWindow window;
/**
@ -43,7 +45,9 @@ public abstract class BaseGame {
audioEngine = new AudioEngine(48000, 256, 8);
mixer = new Mixer(audioEngine, 2);
samplePlayer = new SamplePlayer(audioEngine);
tts = new TTS(audioEngine);
Node.connect(samplePlayer, 0, mixer, 0);
Node.connect(tts, 0, mixer, 1);
audioEngine.setNode(mixer);
engine = new Engine();

View File

@ -18,42 +18,8 @@ public class Test extends BaseGame {
public Test() {
super(new Vec2i(40 * 12, 22 * 12), "Skunkworks");
tts.say("Welcome to the world of speech synthesis!");
LocalMaryInterface mary;
try {
mary = new LocalMaryInterface();
} catch(MaryConfigurationException e) {
throw new RuntimeException(e);
}
var voices = mary.getAvailableVoices();
var text = "Welcome to the world of speech synthesis!";
AudioInputStream audio = null;
try {
audio = mary.generateAudio(text);
Util.time(() -> {
try {
mary.generateAudio(text);
} catch(SynthesisException e) {
throw new RuntimeException(e);
}
});
} catch(SynthesisException e) {
throw new RuntimeException(e);
}
var format = audio.getFormat();
//var aa = MaryAudioUtils.getSamplesAsDoubleArray(audio);
var ds = MaryAudioUtils.getSamplesAsDoubleArray(audio);
//var sample = audioEngine.loadSample(audio);
var sample = Samplei.fromMonoDoubleArray(ds);
System.out.println(sample.getLength());
//System.out.println(aa.length);
samplePlayer.play(sample, false);
var path = "C:\\Program Files (x86)" +

View File

@ -0,0 +1,44 @@
package com.danitheskunk.skunkworks.audio.nodes;
import com.danitheskunk.skunkworks.audio.AudioBuffer;
import com.danitheskunk.skunkworks.audio.AudioEngine;
import com.danitheskunk.skunkworks.audio.Samplei;
import marytts.LocalMaryInterface;
import marytts.exceptions.MaryConfigurationException;
import marytts.exceptions.SynthesisException;
import marytts.util.data.audio.MaryAudioUtils;
import javax.sound.sampled.AudioInputStream;
public class TTS extends Node {
SamplePlayer samplePlayer;
LocalMaryInterface mary;
public TTS(AudioEngine engine) {
super(engine, 0, 1);
samplePlayer = new SamplePlayer(engine);
try {
mary = new LocalMaryInterface();
} catch(MaryConfigurationException e) {
throw new RuntimeException(e);
}
}
public void say(String text) {
AudioInputStream ais;
try {
ais = mary.generateAudio(text);
} catch(SynthesisException e) {
throw new RuntimeException(e);
}
//todo: use AudioInputStream directly... see why not work atm
var ds = MaryAudioUtils.getSamplesAsDoubleArray(ais);
var sample = Samplei.fromMonoDoubleArray(ds);
samplePlayer.play(sample);
}
@Override
public AudioBuffer getBuffer(int slot) {
return samplePlayer.getBuffer(slot);
}
}