0

Here is my code :

/*
* This Java source file was generated by the Gradle 'init' task.
*/
package speech;    
import java.util.* ; 
// import marytts . modules . synthesis . voice . * ;
import marytts.MaryInterface;
import marytts.modules.synthesis.Voice;
import javax.sound.sampled.AudioInputStream;
import marytts.LocalMaryInterface;
import marytts.util.data.audio.AudioPlayer;
public class App   {        
    // variable to hold the text that will be audible  
  
    public static void main( String args[ ] )        
    {        
        try {
        // creating an object of the class TexttoSpeech  
        MaryInterface marytts = new LocalMaryInterface();
        Set<String> voices = marytts.getAvailableVoices();

        System.out.println(marytts.getAvailableVoices());
        //marytts.setLocale(Locale.FRENCH);
        //marytts.setVoice("enst-camille-hsmm");
        AudioInputStream audio = marytts.generateAudio("Good luck Alexandre, Self Destruction in 5, 4, 3, 2, 1");
        AudioPlayer player = new AudioPlayer(audio);
        player.start();
        player.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
    }        
}   

It works fine

i have a libs folder where i put a jar file with a french voice for marytts :

libs/marytts-lang-fr-5.2.jar

Here is my build.gradle file :

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'

configurations.implementation.setCanBeResolved(true)



// tag::repositories[]
repositories{
    mavenCentral()
   flatDir name: 'localRepository',dirs: '.libs/'

   exclusiveContent {
      forRepository {
         maven {
            url 'https://mlt.jfrog.io/artifactory/mlt-mvn-releases-local'
         }
      }
      filter {
         includeGroup 'de.dfki.lt.jtok'
      }
   }
}
// end::repositories[]

// tag::dependencies[]
sourceCompatibility = 1.8
targetCompatibility = 1.8



dependencies {
    implementation fileTree(dir: '.libs/', include: '*.jar')
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
    implementation "joda-time:joda-time:2.2"
    implementation "junit:junit:4.12"
    implementation 'com.google.code.gson:gson:2.9.0'
    implementation 'org.apache.commons:commons-lang3:3.5'
    testImplementation 'junit:junit:4.13'
  implementation 'org.apache.logging.log4j:log4j-api:2.18.0'
  implementation 'org.apache.logging.log4j:log4j-core:2.18.0'
   implementation group: 'de.dfki.mary', name: 'voice-cmu-slt-hsmm', version: '5.2.1', {
      exclude group: 'com.twmacinta', module: 'fast-md5'
      exclude group: 'gov.nist.math', module: 'Jampack'
   }
    //compile 'commons-cli:commons-cli:1.3.1'
    //compile 'de.dfki.mary:voice-cmu-slt-hsmm:5.2-beta3'


}


sourceSets.main.java.srcDirs = ['src']

mainClassName = 'speech.App'

run {
    //jvmArgs = ['-D java.library.path=./lib/']
    systemProperty 'java.library.path','.libs/'
}
tasks.withType(Tar){
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks.withType(Zip){
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.withType(Jar){
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}


task fatJar(type: Jar) {
  archiveVersion =  '0.1.0'
  
    manifest {
    attributes('Implementation-Title': 'Gradle Jar File Example', 'Implementation-Version': archiveVersion,'Main-Class': mainClassName )
    }
    archiveBaseName  = project.name + '-all'
    from { configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

// tag::jar[]
jar {
    archiveBaseName = 'speech'
    archiveVersion =  '0.1.0'
    manifest {
    attributes(
      'Class-Path': configurations.implementation.collect { it.getName() }.join(' '),
      'Main-Class': mainClassName 
    )
  }
}

test {
    useJUnitPlatform()
}

How can i add the new voice from the marytts-lang-fr-5.2.jar to marytts ?

I would like to know how to do that it seems that now marytts can add new voice from a jar very easily, but i didn't found how to do that.

edit : there is a test project here : https://github.com/bussiere/SpeechTest Regards

Bussiere
  • 500
  • 13
  • 60
  • 119

1 Answers1

0

I hope you are doing well.

Although I was not able to create a maven project at first and then, I had to build a Java Project. Nonetheless, I have resolved your problem. So, here it goes for nothing or maybe everything.

  1. I downloaded the marytts-5.2.zip from this link. [Scroll down to the very bottom of the link]
  2. I extracted it at a location. Let's call it MARYTTS_HOME. Open the file $MARYTTS_HOME\download\marytts-components.xml and check out the download link for the voice you need for your project. I downloaded the voice named dfki-poppy for this demo. Also, remember that each voice name belongs to a locale.
  3. Also, note that there is a lib directory where a couple of jar files are already available. Majorly there are 3 types of jar files needed for the project. (a) Some lang jar file (b) a runtime jar file (c) a default voice named cmu-slt-hsmm (locale: en)
  4. Now after downloading and extracting the new voice (dfki-poppy), I got a jar file and a voice directory.
  5. After all this, I created a java project and created a directory named lib and copied all the jar files from the location: $MARYTTS_HOME\lib and also the jar & voice directory from the newly downloaded & extracted voice (dfki-poppy) directory. After this, my lib directory looks like this. Java Project Libraries
  6. I added these jar files into the build path of my project. Only jar files but nothing from the voices directory.
  7. At last, I tweaked your App.java class to generate audio in 2 voices and the newly edited class is given below.
/*
 * This Java source file was generated by the Gradle 'init' task.
 */
package speech;

import java.util.Set;
import javax.sound.sampled.AudioInputStream;
import marytts.LocalMaryInterface;
// import marytts . modules . synthesis . voice . * ;
import marytts.MaryInterface;
import marytts.util.data.audio.AudioPlayer;

public class App
{
    // variable to hold the text that will be audible
    public static void main(String args[])
    {
        try
        {
            // creating an object of the class TexttoSpeech
            MaryInterface marytts = new LocalMaryInterface();
            Set<String> voices = marytts.getAvailableVoices();

            System.out.println("Available voice are " + marytts.getAvailableVoices());
            // marytts.setLocale(Locale.FRENCH);
            marytts.setVoice("dfki-poppy");
            System.out.println("Playing audio in \"" + marytts.getVoice() + "\" voice ");
            AudioInputStream audio = marytts.generateAudio("Good luck Alexandre, Self Destruction in 5, 4, 3, 2, 1");
            AudioPlayer player = new AudioPlayer(audio);
            player.start();
            player.join();

            marytts.setVoice("cmu-slt-hsmm");
            System.out.println("Playing audio in \"" + marytts.getVoice() + "\" voice ");
            audio = null;
            player = null;
            audio = marytts.generateAudio("Good luck Alexandre, Self Destruction in 5, 4, 3, 2, 1");
            player = new AudioPlayer(audio);
            player.start();
            player.join();
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

Now, this code generates the audio in 2 types of voice namely dfki-poppy and cmu-slt-hsmm

If this resolves your problem then accept this as the answer or let me know if it does not work for you.

P.S. I was not able to insert the App.java class here as it was getting pasted in unformatted text due to the StackOverflow's editor.

Varun Jain
  • 1,371
  • 12
  • 26