Example usage for com.amazonaws.services.polly.model SynthesizeSpeechRequest setVoiceId

List of usage examples for com.amazonaws.services.polly.model SynthesizeSpeechRequest setVoiceId

Introduction

In this page you can find the example usage for com.amazonaws.services.polly.model SynthesizeSpeechRequest setVoiceId.

Prototype


public void setVoiceId(VoiceId voiceId) 

Source Link

Document

Voice ID to use for the synthesis.

Usage

From source file:com.github.gregwhitaker.awspolly.example.PollyReadHandler.java

License:Apache License

@Override
public void handle(Context ctx) throws Exception {
    String voiceId = ctx.getRequest().getQueryParams().get("voiceId");
    String text = ctx.getRequest().getQueryParams().get("text");
    String outputFormat = ctx.getRequest().getQueryParams().get("outputFormat");

    SynthesizeSpeechRequest ssRequest = new SynthesizeSpeechRequest();
    ssRequest.setVoiceId(voiceId);
    ssRequest.setOutputFormat(outputFormat);
    ssRequest.setText(text);/*from  w w  w.j  a v  a2  s. co  m*/

    SynthesizeSpeechResult result = polly.synthesizeSpeech(ssRequest);

    ctx.getResponse().contentType(result.getContentType());
    ctx.getResponse().sendStream(s -> s.onSubscribe(new Subscription() {
        @Override
        public void request(long n) {
            try {
                byte[] data = new byte[1024];
                int bytesRead = result.getAudioStream().read(data);

                while (bytesRead != -1) {
                    s.onNext(Unpooled.wrappedBuffer(data));
                    bytesRead = result.getAudioStream().read(data);
                }
            } catch (IOException e) {
                ctx.getResponse().status(500);
                ctx.getResponse().send();
            } finally {
                s.onComplete();
            }
        }

        @Override
        public void cancel() {

        }
    }));
}

From source file:com.waltercedric.tvprogram.plugins.reader.PollyTTSReader.java

License:Open Source License

private SynthesizeSpeechRequest newRequest() {
    SynthesizeSpeechRequest tssRequest = new SynthesizeSpeechRequest();
    tssRequest.setVoiceId(config.getVoiceid());
    tssRequest.setOutputFormat(OutputFormat.Mp3);

    return tssRequest;
}