-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>WebSocket Audio Stream</title> | ||
</head> | ||
<body> | ||
<h1>WebSocket Audio Stream</h1> | ||
<button onclick="connectWebSocket()">Connect WebSocket</button> | ||
<script> | ||
let socket; | ||
|
||
function connectWebSocket() { | ||
socket = new WebSocket("ws://localhost:8000/ws"); | ||
socket.onopen = function(event) { | ||
console.log("Connected to WebSocket server."); | ||
socket.send("start"); | ||
}; | ||
|
||
socket.onmessage = function(event) { | ||
console.log("Received audio data:", event.data); | ||
// Blob으로 변환하여 오디오 재생 | ||
let audioBlob = new Blob([event.data], { type: 'audio/wav' }); | ||
let audioUrl = URL.createObjectURL(audioBlob); | ||
let audio = new Audio(audioUrl); | ||
audio.play(); | ||
}; | ||
|
||
socket.onclose = function(event) { | ||
console.log("Disconnected from WebSocket server."); | ||
}; | ||
|
||
socket.onerror = function(error) { | ||
console.log("WebSocket error:", error); | ||
}; | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
""" |