모르스_부호_변환기
문서의 이전 판입니다!
모르스 부호 변환기
자바스크립트, 파이썬, port 3040 으로 웹 접속
# pip3 instasll flask jamo
from flask import Flask, request, render_template_string
from jamo import h2j, j2hcj
app = Flask(__name__)
MORSE_DICT = {
'ㄱ': '.-..', 'ㄴ': '..-.', 'ㄷ': '-...', 'ㄹ': '...-', 'ㅁ': '--',
'ㅂ': '.--.', 'ㅅ': '--.', 'ㅇ': '-.-', 'ㅈ': '.---', 'ㅊ': '-.-.',
'ㅋ': '-..-', 'ㅌ': '--..', 'ㅍ': '---.', 'ㅎ': '.---.',
'ㄺ' : '.-....-', 'ㄻ' : '.-..--', 'ㄼ' : '.-.....-', 'ㅀ' : '.-..--..',
'ㄲ': '.-...-..', 'ㄸ' : '..--', 'ㅃ' : '..--..', 'ㅆ' : '......',
'ㅄ' : '---.--.-', 'ㄶ' : '.--...--.', 'ㄵ' : '.---.', 'ㄳ' : '--....',
'ㅉ' : '..-...-.',
'ㅏ' : '.', 'ㅑ' : '..',
'ㅓ' : '-', 'ㅕ' : '...', 'ㅗ' : '.-', 'ㅛ' : '-.', 'ㅜ' : '....',
'ㅠ' : '.-.', 'ㅡ' : '-..', 'ㅣ' : '..-', 'ㅐ' : '.---', 'ㅔ' : '--..',
'ㅙ' : '.-..-', 'ㅝ' : '..--', 'ㅚ' : '--..', 'ㅒ' : '..--.-','ㅘ' : '.-.-.-',
'ㅖ' : '..--', 'ㅟ' : '----.-', 'ㅢ' : '...-.-..',
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..',
'1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----',
' ': '/'
}
HTML_TEMPLATE = """
<!DOCTYPE html>
<html>
<head>
<title>한글/영문/숫자 모르스 변환기 (Port 3040)</title>
<style>
body { font-family: 'Segoe UI', sans-serif; text-align: center; background-color: #eef2f3; margin-top: 50px; }
.container { width: 60%; margin: auto; padding: 30px; background: white; border-radius: 15px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); }
textarea { width: 95%; height: 120px; padding: 15px; font-size: 16px; border: 2px solid #ddd; border-radius: 10px; resize: none; margin-bottom: 15px; }
button { background-color: #4CAF50; color: white; padding: 12px 30px; border: none; border-radius: 8px; font-size: 18px; cursor: pointer; transition: 0.3s; }
button:hover { background-color: #45a049; }
.box { text-align: left; margin-top: 25px; padding: 15px; border-radius: 8px; border-left: 5px solid #2196F3; background-color: #f9f9f9; }
.morse-box { background: #2d2d2d; color: #ffeb3b; font-family: 'Courier New', monospace; word-break: break-all; font-size: 20px; letter-spacing: 2px; border-left: 5px solid #ff9800; min-height: 60px; }
h4 { margin-bottom: 5px; color: #555; }
</style>
</head>
<body>
<div class="container">
<h1>📟 사운드 모르스 변환기</h1>
<form method="POST">
<textarea name="text" placeholder="입력하세요...">{{ input_text }}</textarea><br>
<button type="submit">변환 및 재생</button>
</form>
{% if result %}
<div class="box">
<h4>📝 입력 데이터 :</h4>
<div style="font-size: 18px;">{{ input_text }}</div>
</div>
<div class="box morse-box">
<h4>⚡ 모르스 부호 변환 결과 :</h4>
<div id="typing-result"></div>
</div>
<script>
const fullText = {{ result | tojson }};
const displayElement = document.getElementById('typing-result');
let index = 0;
// Web Audio API 설정
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
function playBeep(isDash) {
const oscillator = audioCtx.createOscillator();
const gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(600, audioCtx.currentTime); // 주파수 600Hz
const duration = isDash ? 0.2 : 0.07; // 대시(-)는 길게, 도트(.)는 짧게
gainNode.gain.setValueAtTime(0.1, audioCtx.currentTime);
oscillator.start();
oscillator.stop(audioCtx.currentTime + duration);
}
function typeAndPlay() {
if (index < fullText.length) {
const char = fullText.charAt(index);
displayElement.innerHTML += char;
if (char === '.') {
playBeep(false);
} else if (char === '-') {
playBeep(true);
}
index++;
setTimeout(typeAndPlay, 100); // 0.1초 간격
}
}
window.onload = () => {
if (fullText.length > 0) {
typeAndPlay();
}
};
</script>
{% endif %}
</div>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
result = ""
input_text = ""
if request.method == 'POST':
input_text = request.form.get('text', '')
processed = j2hcj(h2j(input_text.upper()))
morse_list = [MORSE_DICT.get(char, char) for char in processed]
result = " ".join(morse_list)
return render_template_string(HTML_TEMPLATE, result=result, input_text=input_text)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3040, debug=False)
적당한 파일이름(여기서는 morse.py)으로 저장하고, python3 morse.py 로 실행
————-
2026.03.18 akpil
모르스_부호_변환기.1773894060.txt.gz · 마지막으로 수정됨: 저자 akpil
