From 668db79b96335d46942be370a011cd8762941717 Mon Sep 17 00:00:00 2001 From: ddingjoo Date: Tue, 6 Jan 2026 19:22:48 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Polly=20TTS=20=EC=9D=8C=EC=84=B1=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(=EB=82=A8=EC=84=B1/=EC=97=AC=EC=84=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PollyService에 voice 파라미터 추가 (MALE/FEMALE) - ChatVoiceHandler에서 voice 파라미터 파싱 - 기본값: FEMALE (Joanna), MALE: Matthew - 기존 API 하위 호환성 유지 Closes #5 --- .../chatting/handler/ChatVoiceHandler.java | 3 ++- .../chatting/service/PollyService.java | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) 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 지원, 기본값) + } }