Skip to content

Commit

Permalink
tts 웹소켓 방식으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
MinSang22Kim committed Oct 25, 2024
1 parent 188fced commit 753716d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Binary file modified __pycache__/main.cpython-312.pyc
Binary file not shown.
4 changes: 0 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
# 정적 파일 제공 설정 (HTTP 요청 처리)
app.mount("/static", StaticFiles(directory=".", html=True), name="static")





@app.websocket("/ws/tts")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
Expand Down
17 changes: 15 additions & 2 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,32 @@
</head>
<body>
<input id="textInput" type="text" placeholder="Enter text to speak...">
<button onclick="sendMessage()">Send</button>
<button onclick="startAutoSend()">Start Auto Send</button>
<button onclick="stopAutoSend()">Stop Auto Send</button>

<script>
const socket = new WebSocket("ws://127.0.0.1:5000/ws/tts");
let intervalId;

socket.onopen = () => console.log("WebSocket connected");
socket.onmessage = (event) => console.log("Message from server:", event.data);
socket.onclose = () => console.log("WebSocket disconnected");

function sendMessage() {
const text = document.getElementById("textInput").value;
const text = document.getElementById("textInput").value || "Default message";
socket.send(text);
}

function startAutoSend() {
if (!intervalId) {
intervalId = setInterval(sendMessage, 3000); // 3초마다 메시지 전송
}
}

function stopAutoSend() {
clearInterval(intervalId);
intervalId = null;
}
</script>
</body>
</html>

0 comments on commit 753716d

Please sign in to comment.