* INITIAL POPULATIONS OF THIS REPO

This commit is contained in:
2021-12-23 13:04:01 +08:00
parent 3165defa2e
commit ed70cad6ea
182 changed files with 22964 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-tts</artifactId>
<version>2.0</version>
<licenses>
<license>
<name>The software is only allowed to be used in Four Elements - no license is given to any other parties</name>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>net.sf.sociaal</groupId>
<artifactId>freetts</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib</artifactId>
<version>${revision}</version>
</parent>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-tts</artifactId>
<name>lib-tts</name>
<url>http://www.fourelementscapital.com</url>
<dependencies>
<dependency>
<groupId>net.sf.sociaal</groupId>
<artifactId>freetts</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,46 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fourelementscapital.tts;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Config {
/**
* Get the value of a property defined in config file
* @param propertyName - the name or key of the property you want to retrieve
* @return the string value
* @throws IOException
*/
protected static String getConfigValue(String propertyName) throws IOException
{
Properties prop = new Properties();
String propFileName = "config_tts.properties";
InputStream inputStream = Config.class.getClassLoader().getResourceAsStream(propFileName);
if (inputStream != null) {
prop.load(inputStream);
} else {
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
}
// get the property value and print it out
String value = prop.getProperty(propertyName);
return value;
}
}
+71
View File
@@ -0,0 +1,71 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fourelementscapital.tts;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.util.Locale;
import javax.speech.AudioException;
import javax.speech.Central;
import javax.speech.EngineException;
import javax.speech.EngineStateError;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.Voice;
/**
* A Text-To-Speech libraries using Free TTS & MBROLA voices
*/
public class TTS {
private SynthesizerModeDesc desc;
private Synthesizer synthesizer;
private Voice voice;
public static final String VOICE_MBROLA_US1 = "mbrola_us1";
public void init(String voiceName) throws EngineException, AudioException, EngineStateError, PropertyVetoException, IOException {
//TODO : to properties file
System.setProperty("mbrola.base", Config.getConfigValue("mbrola_path"));
if (desc == null) {
System.setProperty("freetts.voices", "de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory");
desc = new SynthesizerModeDesc(Locale.US);
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
SynthesizerModeDesc smd = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = smd.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++) {
if (voices[i].getName().equals(voiceName)) {
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
}
}
public void terminate() throws EngineException, EngineStateError {
synthesizer.deallocate();
}
public void doSpeak(String speakText) throws EngineException, AudioException, IllegalArgumentException, InterruptedException {
synthesizer.speakPlainText(speakText, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
}
}
+2
View File
@@ -0,0 +1,2 @@
#mbrola_path=C:\\iMonitor2\\mbrola\\
mbrola_path=/usr/share/mbrola
@@ -0,0 +1,67 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fourelementscapital.tts;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for App
*/
public class AppTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Empty Test
*/
public void testApp()
{
assertTrue( true );
}
/**
* Test text to speech
*/
public void testTTS()
{
try {
// Remove the comment tag to test. The code are commented out to prevent executing text to speech (setup MBROLA & edit properties file first) :
/*
TTS tts = new TTS();
tts.init(TTS.VOICE_MBROLA_US1);
tts.doSpeak("This is just a test");
//tts.terminate(); // don't terminate, to prevent java.lang.IllegalThreadStateException
*/
}
catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
assertTrue( true );
}
}