diff --git a/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/handler/ChatVoiceHandler.java b/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/handler/ChatVoiceHandler.java index 2c8306c5..2d97c11b 100644 --- a/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/handler/ChatVoiceHandler.java +++ b/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/handler/ChatVoiceHandler.java @@ -36,12 +36,13 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent re String body = request.getBody(); Map 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))); diff --git a/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/service/PollyService.java b/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/service/PollyService.java index c9e96179..b11e2134 100644 --- a/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/service/PollyService.java +++ b/chatting/ChatFunction/src/main/java/com/mzc/secondproject/serverless/chatting/service/PollyService.java @@ -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(); @@ -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 지원, 기본값) + } }