Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ALFA
Alfa Backend
Commits
05caf83c
Commit
05caf83c
authored
3 years ago
by
Marcelo de Souza
Browse files
Options
Download
Email Patches
Plain Diff
Credencials alteradas para a do projeto AGES
parent
2dd04d8c
feat/amazon-polly
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/main/java/ages/alfa/config/AmazonPollyConfig.java
+22
-21
src/main/java/ages/alfa/config/AmazonPollyConfig.java
src/main/java/ages/alfa/service/impl/TextToToSpeechImpl.java
+2
-17
src/main/java/ages/alfa/service/impl/TextToToSpeechImpl.java
src/main/resources/TextToSpeech.http
+8
-0
src/main/resources/TextToSpeech.http
src/main/resources/application.properties
+3
-1
src/main/resources/application.properties
with
35 additions
and
39 deletions
+35
-39
src/main/java/ages/alfa/config/AmazonPollyConfig.java
View file @
05caf83c
package
ages.alfa.config
;
import
com.amazonaws.ClientConfiguration
;
import
com.amazonaws.auth.AWSStaticCredentialsProvider
;
import
com.amazonaws.auth.BasicAWSCredentials
;
import
com.amazonaws.auth.DefaultAWSCredentialsProviderChain
;
import
com.amazonaws.regions.Region
;
import
com.amazonaws.regions.Regions
;
import
com.amazonaws.services.polly.AmazonPolly
;
import
com.amazonaws.services.polly.AmazonPollyClient
;
import
com.amazonaws.services.polly.AmazonPollyClientBuilder
;
import
com.amazonaws.services.polly.model.DescribeVoicesRequest
;
import
com.amazonaws.services.polly.model.DescribeVoicesResult
;
import
com.amazonaws.services.polly.model.SynthesizeSpeechRequest
;
import
com.amazonaws.services.polly.model.Voice
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -21,29 +17,34 @@ public class AmazonPollyConfig {
public
static
final
String
REGION
=
"SA_EAST_1"
;
// TODO Solicitar para Cássio Key e Secret do usuário
/*@Bean
public AmazonPolly getAmazonPolly() {
return AmazonPollyClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials("acessKey", "secretAcessKey")))
.withRegion(REGION).build();
}*/
@Value
(
"${amazon.credentials.idkey}"
)
private
String
idKey
;
@Bean
public
AmazonPolly
getAmazonPolly
()
{
AmazonPollyClient
pollyClient
=
new
AmazonPollyClient
(
new
DefaultAWSCredentialsProviderChain
(),
new
ClientConfiguration
());
pollyClient
.
setRegion
(
Region
.
getRegion
(
Regions
.
SA_EAST_1
));
@Value
(
"${amazon.credentials.secretkey}"
)
private
String
secretKey
;
return
pollyClient
;
@Bean
public
AmazonPolly
getAmazonCredentials
()
{
return
AmazonPollyClientBuilder
.
standard
()
.
withCredentials
(
new
AWSStaticCredentialsProvider
(
new
BasicAWSCredentials
(
idKey
,
secretKey
)))
.
withRegion
(
Regions
.
SA_EAST_1
)
.
build
();
}
// @Bean
// public AmazonPolly getAmazonPolly() {
// AmazonPollyClient pollyClient = new AmazonPollyClient(
// new DefaultAWSCredentialsProviderChain(),
// new ClientConfiguration());
// pollyClient.setRegion(Region.getRegion(Regions.SA_EAST_1));
//
// return pollyClient;
// }
@Bean
public
Voice
getVoice
()
{
DescribeVoicesRequest
describeVoicesRequest
=
new
DescribeVoicesRequest
().
withLanguageCode
(
"pt-BR"
);
DescribeVoicesResult
describeVoicesResult
=
getAmazon
Polly
().
describeVoices
(
describeVoicesRequest
);
DescribeVoicesResult
describeVoicesResult
=
getAmazon
Credentials
().
describeVoices
(
describeVoicesRequest
);
return
describeVoicesResult
.
getVoices
().
get
(
0
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/ages/alfa/service/impl/TextToToSpeechImpl.java
View file @
05caf83c
...
...
@@ -6,8 +6,6 @@ import com.amazonaws.services.polly.model.*;
import
com.amazonaws.util.IOUtils
;
import
javazoom.jl.decoder.JavaLayerException
;
import
javazoom.jl.player.advanced.AdvancedPlayer
;
import
javazoom.jl.player.advanced.PlaybackEvent
;
import
javazoom.jl.player.advanced.PlaybackListener
;
import
lombok.RequiredArgsConstructor
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -44,14 +42,14 @@ public class TextToToSpeechImpl implements TextToSpeechService {
InputStream
speechStream
=
synthRes
.
getAudioStream
();
String
audioBase64
=
inputStreamToBase64
(
text
,
speechStream
);
String
audioBase64
=
inputStreamToBase64
(
speechStream
);
playSound
(
audioBase64
);
return
audioBase64
;
}
@SneakyThrows
private
String
inputStreamToBase64
(
String
text
,
final
InputStream
inputStream
)
{
private
String
inputStreamToBase64
(
final
InputStream
inputStream
)
{
byte
[]
bytes
=
IOUtils
.
toByteArray
(
inputStream
);
return
Base64
.
getEncoder
().
encodeToString
(
bytes
);
}
...
...
@@ -63,19 +61,6 @@ public class TextToToSpeechImpl implements TextToSpeechService {
AdvancedPlayer
player
=
new
AdvancedPlayer
(
targetStream
,
javazoom
.
jl
.
player
.
FactoryRegistry
.
systemRegistry
().
createAudioDevice
());
player
.
setPlayBackListener
(
new
PlaybackListener
()
{
@Override
public
void
playbackStarted
(
PlaybackEvent
evt
)
{
System
.
out
.
println
(
"Playback started"
);
}
@Override
public
void
playbackFinished
(
PlaybackEvent
evt
)
{
System
.
out
.
println
(
"Playback finished"
);
}
});
player
.
play
();
}
}
This diff is collapsed.
Click to expand it.
src/main/resources/TextToSpeech.http
0 → 100644
View file @
05caf83c
###
GET http://localhost:8082/api/modo-assistente/pelos poderes de greiscom
Accept: application/json
###
GET http://localhost:8082/api/modo-assistente/audio
Accept: application/json
This diff is collapsed.
Click to expand it.
src/main/resources/application.properties
View file @
05caf83c
server.port
=
8082
\ No newline at end of file
server.port
=
8082
amazon.credentials.idkey
=
AKIAQNTVEQCND3UD22FY
amazon.credentials.secretkey
=
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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help