use of com.amazonaws.services.polly.model.SynthesizeSpeechResult in project aws-sdk-android by aws-amplify.
the class SynthesizeSpeechResultJsonUnmarshaller method unmarshall.
@Override
public SynthesizeSpeechResult unmarshall(JsonUnmarshallerContext context) throws Exception {
final SynthesizeSpeechResult synthesizeSpeechResult = new SynthesizeSpeechResult();
final java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
final byte[] bytes = IOUtils.toByteArray(is);
final java.io.ByteArrayInputStream bis = new java.io.ByteArrayInputStream(bytes);
synthesizeSpeechResult.setAudioStream(bis);
}
if (context.getHeader("Content-Type") != null) {
synthesizeSpeechResult.setContentType(context.getHeader("Content-Type"));
}
if (context.getHeader("x-amzn-RequestCharacters") != null) {
synthesizeSpeechResult.setRequestCharacters(Integer.valueOf(context.getHeader("x-amzn-RequestCharacters")));
}
return synthesizeSpeechResult;
}
use of com.amazonaws.services.polly.model.SynthesizeSpeechResult in project amplify-android by aws-amplify.
the class AWSPollyService method synthesizeSpeech.
private InputStream synthesizeSpeech(String text, AWSVoiceType voiceType) throws PredictionsException {
final String languageCode;
final String voiceId;
if (AWSVoiceType.UNKNOWN.equals(voiceType)) {
// Obtain voice + language from plugin configuration by default
SpeechGeneratorConfiguration config = pluginConfiguration.getSpeechGeneratorConfiguration();
languageCode = config.getLanguage();
voiceId = config.getVoice();
} else {
// Override configuration defaults if explicitly specified in the options
languageCode = voiceType.getLanguageCode();
voiceId = voiceType.getName();
}
SynthesizeSpeechRequest request = new SynthesizeSpeechRequest().withText(text).withTextType(TextType.Text).withLanguageCode(languageCode).withVoiceId(voiceId).withOutputFormat(OutputFormat.Mp3).withSampleRate(Integer.toString(MP3_SAMPLE_RATE));
// Synthesize speech from given text via Amazon Polly
final SynthesizeSpeechResult result;
try {
result = polly.synthesizeSpeech(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("AWS Polly encountered an error while synthesizing speech.", serviceException, "See attached service exception for more details.");
}
return result.getAudioStream();
}
use of com.amazonaws.services.polly.model.SynthesizeSpeechResult in project myrobotlab by MyRobotLab.
the class Polly method cacheFile.
/*
* Proxy works in 3 modes
* client - consumer of mrl services
* relay - proxy (running as cloud service)
* direct - goes direct to service
* In Polly's case -
* client - would be an end user using a client key
* relay - is the mrl proxy service
* direct would be from a users, by-passing mrl and going directly to Amazon with amazon keys
* cache file - caches file locally (both client or relay)
*/
public byte[] cacheFile(String toSpeak, OutputFormat format) throws IOException {
byte[] mp3File = null;
// cache it begin -----
String localFileName = getLocalFileName(this, toSpeak, "mp3");
// localFileName;
if (!audioFile.cacheContains(localFileName)) {
log.info("retrieving speech from Amazon - {}", localFileName);
AmazonPollyClient polly = getPolly();
SynthesizeSpeechRequest synthReq = new SynthesizeSpeechRequest().withText(toSpeak).withVoiceId(awsVoice.getId()).withOutputFormat(format);
SynthesizeSpeechResult synthRes = polly.synthesizeSpeech(synthReq);
InputStream data = synthRes.getAudioStream();
mp3File = FileIO.toByteArray(data);
audioFile.cache(localFileName, mp3File, toSpeak);
} else {
log.info("using local cached file");
mp3File = FileIO.toByteArray(new File(AudioFile.globalFileCacheDir + File.separator + getLocalFileName(this, toSpeak, "mp3")));
}
// log.info("Finished waiting for completion.");
return mp3File;
}
Aggregations