From 2d002f363247d91cfbe17a7cc022499ab4a20a91 Mon Sep 17 00:00:00 2001 From: DaniTheSkunk <> Date: Sun, 27 Nov 2022 07:14:12 +0000 Subject: [PATCH] added TTS audio node, and included it in BaseGame --- .idea/artifacts/skunkworks_jar.xml | 3 ++ com/danitheskunk/skunkworks/BaseGame.java | 4 ++ com/danitheskunk/skunkworks/Test.java | 36 +-------------- .../skunkworks/audio/nodes/TTS.java | 44 +++++++++++++++++++ 4 files changed, 52 insertions(+), 35 deletions(-) create mode 100644 com/danitheskunk/skunkworks/audio/nodes/TTS.java diff --git a/.idea/artifacts/skunkworks_jar.xml b/.idea/artifacts/skunkworks_jar.xml index ce8ca44..ec0bfd3 100644 --- a/.idea/artifacts/skunkworks_jar.xml +++ b/.idea/artifacts/skunkworks_jar.xml @@ -15,6 +15,9 @@ + + + \ No newline at end of file diff --git a/com/danitheskunk/skunkworks/BaseGame.java b/com/danitheskunk/skunkworks/BaseGame.java index cd1cff5..cd1e4c4 100644 --- a/com/danitheskunk/skunkworks/BaseGame.java +++ b/com/danitheskunk/skunkworks/BaseGame.java @@ -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(); diff --git a/com/danitheskunk/skunkworks/Test.java b/com/danitheskunk/skunkworks/Test.java index 671d0b9..5cc5c67 100644 --- a/com/danitheskunk/skunkworks/Test.java +++ b/com/danitheskunk/skunkworks/Test.java @@ -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)" + diff --git a/com/danitheskunk/skunkworks/audio/nodes/TTS.java b/com/danitheskunk/skunkworks/audio/nodes/TTS.java new file mode 100644 index 0000000..8146706 --- /dev/null +++ b/com/danitheskunk/skunkworks/audio/nodes/TTS.java @@ -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); + } +}