首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将MaryTTS的声音改为法语

将MaryTTS的声音改为法语
EN

Stack Overflow用户
提问于 2022-08-01 11:53:31
回答 1查看 65关注 0票数 1

我开始在一个java项目中使用MaryTTS,它运行得很好,但使用的是英语语音:

代码语言:javascript
复制
public static void main(String[] args) throws MaryConfigurationException, InterruptedException, SynthesisException {
        // init CLI options, args
        MaryInterface marytts = new LocalMaryInterface();
        Set<String> voices = marytts.getAvailableVoices();
        System.out.println(marytts.getAvailableVoices());
        marytts.setVoice(voices.iterator().next());
        AudioInputStream audio = marytts.generateAudio("Hello world");
        AudioPlayer player = new AudioPlayer(audio);
        player.start();
        player.join();

我要把声音调成法语。这是我的pom.xml:

代码语言:javascript
复制
<dependencies>
    <dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>1.5.0</version>
    </dependency>
    <dependency>
        <groupId>de.dfki.mary</groupId>
        <artifactId>voice-cmu-slt-hsmm</artifactId>
        <version>5.2.1</version>
    </dependency>
    <dependency>
        <groupId>de.dfki.mary</groupId>
        <artifactId>marytts-lang-fr</artifactId>
        <version>5.2.1</version>
    </dependency>
</dependencies>

这些都是我的依赖,所以我有一个maryTTS的,和一个应该给我带来法语的声音,我对MavenSearch:https://search.maven.org/artifact/de.dfki.mary/marytts-lang-fr/5.2.1/jar

法语似乎没有实现,因为如果我这样做:

代码语言:javascript
复制
Set<String> voices = maryTTS.getAvailableVoices();
for(String v : voices){
    System.out.println("Voice available: " + v);
}

这就是我在控制台中得到的:cmu-slt

我还能做些什么来设置法语的声音呢?

marytts.lang.fr编辑:好的,我正在接近一个答案,我下载了两个jar:voice-enst-camille-hsmm和,这是我添加到我的项目中的,如果我这样做的话:

代码语言:javascript
复制
        MaryInterface marytts = new LocalMaryInterface();   marytts.setLocale(Locale.FRENCH);
        marytts.setVoice("upmc-pierre-hsmm");
        AudioInputStream audio = marytts.generateAudio("Bonjour TEST TEST TEST ");
        AudioPlayer player = new AudioPlayer(audio);
        player.start();
        player.join();

它工作,我有我想要的法语声音,但我也希望当我发送一个txt文件,我的程序创建一个wav文件并读取它。这是可行的,但只能用英语:

代码语言:javascript
复制
Options options = new Options();
        Option outputOption = Option.builder("o").longOpt(OUT_OPT).hasArg().argName("FILE").desc("Write output to FILE")
                .required().build();
        Option inputOption = Option.builder("i").longOpt(IN_OPT).hasArg().argName("FILE")
                .desc("Read input from FILE\n(otherwise, read from command line argument)").build();
        options.addOption(outputOption);
        options.addOption(inputOption);
        HelpFormatter formatter = new HelpFormatter();
        CommandLineParser parser = new DefaultParser();
        CommandLine line = null;
        try {
            line = parser.parse(options, args);
        } catch (ParseException e) {
            System.err.println("Error parsing command line options: " + e.getMessage());
            formatter.printHelp(NAME, options, true);
            System.exit(1);
        }

        // get output option
        String outputFileName = null;
        if (line.hasOption(OUT_OPT)) {
            outputFileName = line.getOptionValue(OUT_OPT);
            if (!FilenameUtils.getExtension(outputFileName).equals("wav")) {
                outputFileName += ".wav";
            }
        } else {
            System.err.println("Please provide an output wav filename.");
            formatter.printHelp(NAME, options, true);
            System.exit(1);
        }

        // get input
        String inputText = null;
        if (line.hasOption(IN_OPT)) {
            String inputFileName = line.getOptionValue(IN_OPT);
            File file = new File(inputFileName);
            try {
                inputText = FileUtils.readFileToString(file);
            } catch (IOException e) {
                System.err.println("Could not read from file " + inputFileName + ": " + e.getMessage());
                System.exit(1);
            }
        } else {
            try {
                inputText = line.getArgList().get(0);
            } catch (IndexOutOfBoundsException e) {
                // ignore
            }
        }
        if (inputText == null) {
            System.err.println("Please provide an input text.");
            formatter.printHelp(NAME, options, true);
            System.exit(1);
        }

        // init mary
        MaryInterface mary = new LocalMaryInterface();


        // synthesize
        AudioInputStream audio = null;
        try {
            audio = mary.generateAudio(inputText);
        } catch (SynthesisException e) {
            System.err.println("Synthesis failed: " + e.getMessage());
            System.exit(1);
        }

        // write to output
        double[] samples = MaryAudioUtils.getSamplesAsDoubleArray(audio);
        try {
            MaryAudioUtils.writeWavFile(samples, outputFileName, audio.getFormat());
            System.out.println("Output written to " + outputFileName);
        } catch (IOException e) {
            System.err.println("Could not write to file: " + outputFileName + "\n" + e.getMessage());
            System.exit(1);
        }

因此,要用法语发言,我刚才补充说:

代码语言:javascript
复制
mary.setLocale(Locale.FRENCH);
mary.setVoice("upmc-pierre-hsmm");

在……下面

代码语言:javascript
复制
MaryInterface mary = new LocalMaryInterface();

但是,当我在终端中试用我的应用程序时,我会收到以下错误信息:

代码语言:javascript
复制
Exception in thread "main" java.lang.IllegalArgumentException: No such voice: upmc-pierre-hsmm
        at marytts.LocalMaryInterface.setVoice(LocalMaryInterface.java:182)
        at de.dfki.mary.Txt2Wav.main(Txt2Wav.java:94)

编辑:如果我在我的intellij而不是我的终端上这样做,它就能正常工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-02 06:44:47

因此,法语maryTTS的解决方案是在项目中添加那些Jar:-https://gitlab.istic.univ-rennes1.fr/amucheri/avatar-beta2/-/blob/9f1027251cefa136f34e96d30789319aafec5625/lib/marytts-lang-fr-5.2.jar

这个要有法国本土的。

对于声音,您可以添加jar,或者我认为添加这个maven依赖项也可以:

-https://mvnrepository.com/artifact/de.dfki.mary/voice-enst-camille-hsmm/5.2

您可以更改URL以找到您想要的声音。

通过传递我的论点:

代码语言:javascript
复制
-i hello.txt -o hello.wav

在我在IntelliJ中的项目的论据中:

起作用了。

如果有人知道为什么它是这样工作,而不是在我的终端,我很高兴听到它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73193244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档