use of com.amazonaws.services.polly.model.SynthesizeSpeechRequest in project openhab-addons by openhab.
the class PollyTTSCloudImpl method getTextToSpeech.
/**
* This method will return an input stream to an audio stream for the given
* parameters.
* Get the given text in specified locale and audio format as input stream.
*
* @param text
* the text to translate into speech
* @param label
* the voice Label to use
* @param audioFormat
* the audio format to use
* @return an InputStream to the audio data in specified format
* @throws IOException
* will be raised if the audio data can not be retrieved from
* cloud service
*/
public InputStream getTextToSpeech(String text, String label, String audioFormat) {
String voiceID = labelToID.get(label);
String format = audioFormat.toLowerCase();
if ("ogg".equals(format)) {
format = "ogg_vorbis";
}
TextType textType = text.startsWith("<speak>") ? TextType.Ssml : TextType.Text;
SynthesizeSpeechRequest request = new SynthesizeSpeechRequest().withTextType(textType).withText(text).withVoiceId(voiceID).withOutputFormat(OutputFormat.fromValue(format));
return client.synthesizeSpeech(request).getAudioStream();
}
use of com.amazonaws.services.polly.model.SynthesizeSpeechRequest in project aws-java-reference-pocs by hardikSinghBehl.
the class AudioGenerationService method generate.
public InputStream generate(final String inputText) {
final var synthesizeSpeechRequest = new SynthesizeSpeechRequest().withText(inputText).withVoiceId(getDefaultVoice().getId()).withOutputFormat(OutputFormat.Mp3);
final var synthesizeSpeechResult = amazonPolly.synthesizeSpeech(synthesizeSpeechRequest);
return synthesizeSpeechResult.getAudioStream();
}
use of com.amazonaws.services.polly.model.SynthesizeSpeechRequest 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.SynthesizeSpeechRequest 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