use of com.amazonaws.services.polly.AmazonPollyClient in project myrobotlab by MyRobotLab.
the class Polly method getPolly.
private AmazonPollyClient getPolly() {
if (polly == null) {
try {
// BasicAWSCredentials("AKIAJGL6AEN37LDO3N7A", "secret-access-key");
if (credentials == null) {
// try credential chain - in case they have set env vars
credentials = new BasicAWSCredentials(keyId, keyIdSecret);
}
// polly = (AmazonPollyClient)
// AmazonPollyClientBuilder.standard().withCredentials(new
// AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_EAST_1).build();
polly = (AmazonPollyClient) AmazonPollyClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_WEST_2).build();
processVoicesRequest();
} catch (Exception e) {
try {
log.error("could not get client with keys supplied - trying default chain", e);
polly = new AmazonPollyClient(new DefaultAWSCredentialsProviderChain(), new ClientConfiguration());
// polly.setRegion(Region.getRegion(Regions.US_EAST_1));
polly.setRegion(Region.getRegion(Regions.US_WEST_2));
processVoicesRequest();
} catch (Exception e2) {
credentialsError = true;
error("could not get Polly client - did you setKeys ?");
error("Environment variables – AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY or");
error("check http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html");
log.error("giving up", e2);
}
}
}
return polly;
}
use of com.amazonaws.services.polly.AmazonPollyClient 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