Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent re
String body = request.getBody();
Map<String, String> requestBody = gson.fromJson(body, Map.class);
String text = requestBody.get("text");
String voice = requestBody.getOrDefault("voice", "FEMALE");

if (text == null || text.isEmpty()) {
return createResponse(400, ApiResponse.error("text is required"));
}

String audioUrl = pollyService.synthesizeSpeech(text);
String audioUrl = pollyService.synthesizeSpeech(text, voice);

return createResponse(200, ApiResponse.success("Speech synthesized", Map.of("audioUrl", audioUrl)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ public PollyService() {
}

public String synthesizeSpeech(String text) {
logger.info("Synthesizing speech for text");
return synthesizeSpeech(text, "FEMALE");
}

public String synthesizeSpeech(String text, String voice) {
VoiceId voiceId = resolveVoiceId(voice);
logger.info("Synthesizing speech with voice: {}", voiceId);

try {
SynthesizeSpeechRequest request = SynthesizeSpeechRequest.builder()
.text(text)
.voiceId(VoiceId.JOANNA) // 미국 영어 여성 (Neural 지원)
.engine("neural") // Neural 엔진 (더 자연스러운 발음)
.voiceId(voiceId)
.engine("neural")
.outputFormat(OutputFormat.MP3)
.build();

Expand Down Expand Up @@ -91,4 +96,11 @@ public String synthesizeSpeech(String text) {
throw new RuntimeException("Failed to synthesize speech", e);
}
}

private VoiceId resolveVoiceId(String voice) {
if ("MALE".equalsIgnoreCase(voice)) {
return VoiceId.MATTHEW; // 미국 영어 남성 (Neural 지원)
}
return VoiceId.JOANNA; // 미국 영어 여성 (Neural 지원, 기본값)
}
}