List of usage examples for com.amazonaws.services.polly.model SynthesizeSpeechRequest setOutputFormat
public void setOutputFormat(OutputFormat outputFormat)
The format in which the returned output will be encoded.
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);/*ww w.j a va 2 s . co m*/ ssRequest.setOutputFormat(outputFormat); ssRequest.setText(text); 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; }