问题描述
环境
- Angular11.2
- Spring Boot2.4.5
- 带有 snd-aloop 的 EC2(Ubuntu20.04)
我基于 AWS sdk for java 2.0 实现了 Amazon Polly。它在本地环境中说话,但在生产(EC2)中虽然没有发生错误,但它却没有。来源如下:
@GetMapping("/sound/{chinese}")
public void getSound(@PathVariable("chinese") String chinese) throws IOException {
ResourceBundle rb = ResourceBundle.getBundle(RESOURCE_NAME);
final String accessKey = rb.getString("pollyAccessKey");
final String secretKey = rb.getString("pollySecretKey");
AwsBasicCredentials awsCreds = AwsBasicCredentials.create(accessKey,secretKey);
final String REGION = rb.getString("region");
try {
PollyClient polly = PollyClient.builder()
.credentialsProvider(StaticCredentialsProvider.create(awsCreds))
.region(Region.of(REGION))
.build();
DescribeVoicesRequest describeVoiceRequest = DescribeVoicesRequest.builder()
.languageCode("cmn-CN")
.engine("standard")
.build();
DescribeVoicesResponse describeVoicesResult = polly.describeVoices(describeVoiceRequest);
Voice voice = describeVoicesResult.voices().get(0);
InputStream stream = synthesize(polly,chinese,voice,OutputFormat.MP3);
Advancedplayer player = new Advancedplayer(stream,javazoom.jl.player.FactoryRegistry.systemRegistry().createAudioDevice());
player.play();
polly.close();
} catch (PollyException | JavaLayerException | IOException e) {
System.out.println(e.getStackTrace());
System.exit(1);
}
}
public static InputStream synthesize(PollyClient polly,String text,Voice voice,OutputFormat format) throws IOException {
SynthesizeSpeechRequest synthReq = SynthesizeSpeechRequest.builder()
.text(text)
.voiceId(voice.id())
.outputFormat(format)
.build();
ResponseInputStream<SynthesizeSpeechResponse> synthRes = polly.synthesizeSpeech(synthReq);
return synthRes;
}
我花了大约一周的时间试图解决这个问题,但它不起作用。 我不知道了。提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)