Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Amazon Polly在Java中启用神经文本到语音(NTTS)_Java_Amazon Web Services_Text To Speech_Amazon Polly - Fatal编程技术网

如何使用Amazon Polly在Java中启用神经文本到语音(NTTS)

如何使用Amazon Polly在Java中启用神经文本到语音(NTTS),java,amazon-web-services,text-to-speech,amazon-polly,Java,Amazon Web Services,Text To Speech,Amazon Polly,我正在尝试使用AmazonPolly使用JavaAPI将文本转换为语音。正如亚马逊所描述的,有几种美式英语语音支持神经网络 我下面要在Java应用程序中运行的代码如下: package com.amazonaws.demos.polly; import java.io.IOException; import java.io.InputStream; import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.Defa

我正在尝试使用AmazonPolly使用JavaAPI将文本转换为语音。正如亚马逊所描述的,有几种美式英语语音支持神经网络

我下面要在Java应用程序中运行的代码如下:

package com.amazonaws.demos.polly;

import java.io.IOException;
import java.io.InputStream;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.polly.AmazonPollyClient;
import com.amazonaws.services.polly.model.DescribeVoicesRequest;
import com.amazonaws.services.polly.model.DescribeVoicesResult;
import com.amazonaws.services.polly.model.OutputFormat;
import com.amazonaws.services.polly.model.SynthesizeSpeechRequest;
import com.amazonaws.services.polly.model.SynthesizeSpeechResult;
import com.amazonaws.services.polly.model.Voice;

import javazoom.jl.player.advanced.AdvancedPlayer;
import javazoom.jl.player.advanced.PlaybackEvent;
import javazoom.jl.player.advanced.PlaybackListener;

public class PollyDemo {

    private final AmazonPollyClient polly;
    private final Voice voice;
    private static final String JOANNA="Joanna"; 
    private static final String KENDRA="Kendra"; 
    private static final String MATTHEW="Matthew"; 
    private static final String SAMPLE = "Congratulations. You have successfully built this working demo of Amazon Polly in Java. Have fun building voice enabled apps with Amazon Polly (that's me!), and always look at the AWS website for tips and tricks on using Amazon Polly and other great services from AWS";

    public PollyDemo(Region region) {
        // create an Amazon Polly client in a specific region
        polly = new AmazonPollyClient(new DefaultAWSCredentialsProviderChain(), 
        new ClientConfiguration());
        polly.setRegion(region);

        // Create describe voices request.
        DescribeVoicesRequest describeVoicesRequest = new DescribeVoicesRequest();

        // Synchronously ask Amazon Polly to describe available TTS voices.
        DescribeVoicesResult describeVoicesResult = polly.describeVoices(describeVoicesRequest);
        //voice = describeVoicesResult.getVoices().get(0);
        voice = describeVoicesResult.getVoices().stream().filter(p -> p.getName().equals(MATTHEW)).findFirst().get();
    }

    public InputStream synthesize(String text, OutputFormat format) throws IOException {
        SynthesizeSpeechRequest synthReq = 
        new SynthesizeSpeechRequest().withText(text).withVoiceId(voice.getId())
                .withOutputFormat(format);
        SynthesizeSpeechResult synthRes = polly.synthesizeSpeech(synthReq);

        return synthRes.getAudioStream();
    }

    public static void main(String args[]) throws Exception {
        //create the test class
        PollyDemo helloWorld = new PollyDemo(Region.getRegion(Regions.US_WEST_1));
        //get the audio stream
        InputStream speechStream = helloWorld.synthesize(SAMPLE, OutputFormat.Mp3);

        //create an MP3 player
        AdvancedPlayer player = new AdvancedPlayer(speechStream,
                javazoom.jl.player.FactoryRegistry.systemRegistry().createAudioDevice());

        player.setPlayBackListener(new PlaybackListener() {
            @Override
            public void playbackStarted(PlaybackEvent evt) {
                System.out.println("Playback started");
                System.out.println(SAMPLE);
            }

            @Override
            public void playbackFinished(PlaybackEvent evt) {
                System.out.println("Playback finished");
            }
        });


        // play it!
        player.play();

    }
} 
默认情况下,它采用马太福音的标准。请建议需要改变什么,以使马修之声的演讲神经化


谢谢

我假设您使用的是AWS Java SDK 1.11

AWS文档说明,您需要将语音系统请求中的
引擎
参数设置为
神经
。AWS Java SDK文档描述了使用Engine将其设置为神经的
方法


PS:文档页面似乎没有提供方法URL,因此您必须搜索它。

我假设您使用的是AWS Java SDK 1.11

AWS文档说明,您需要将语音系统请求中的
引擎
参数设置为
神经
。AWS Java SDK文档描述了使用Engine将其设置为神经的
方法


PS:文档页面似乎没有提供方法URL,因此您必须搜索它。

感谢@ASR提供您的反馈

我能够按照您的建议找到引擎参数

我解决这个问题的方法是:

  • 在pom.xml中,将aws java sdk polly版本从1.11.77(如文档中所示)更新为最新的1.11.762,并构建Maven项目。这带来了SynthesizeSpeechRequest类的最新类定义。对于1.11.77,我无法在其定义中看到With engine功能
  • 正如《神经语音》中所定义的,它只在特定区域可用。因此,我不得不选择如下:

  • 在这之后,神经系统的声音工作得非常好。

    谢谢@ASR的反馈

    我能够按照您的建议找到引擎参数

    我解决这个问题的方法是:

  • 在pom.xml中,将aws java sdk polly版本从1.11.77(如文档中所示)更新为最新的1.11.762,并构建Maven项目。这带来了SynthesizeSpeechRequest类的最新类定义。对于1.11.77,我无法在其定义中看到With engine功能
  • 正如《神经语音》中所定义的,它只在特定区域可用。因此,我不得不选择如下:
  • 在这之后,神经系统的声音工作得非常好

    <dependency>
     <groupId>com.amazonaws</groupId>
     <artifactId>aws-java-sdk-polly</artifactId>
     <version>1.11.762</version>
    </dependency>
    
    SynthesizeSpeechRequest synthReq = 
            new SynthesizeSpeechRequest().withText(text).withVoiceId(voice.getId())
                    .withOutputFormat(format).withEngine("neural");
    
    PollyDemo helloWorld = new PollyDemo(Region.getRegion(Regions.US_WEST_2));