|
|
|
|
|
window.addEventListener('DOMContentLoaded', function() |
|
|
{ |
|
|
let voiceForm = document.getElementById("voiceForm"); |
|
|
|
|
|
|
|
|
voiceForm.addEventListener("submit", (e) => { |
|
|
e.preventDefault(); |
|
|
|
|
|
let sentence = document.getElementById("sentence"); |
|
|
|
|
|
if (sentence == "") { |
|
|
alert("๋ฌธ์ฅ์ ์
๋ ฅํด์ฃผ์ธ์!"); |
|
|
} else { |
|
|
|
|
|
alert(sentence.value + " ๋ฌธ์ฅ์ด ์
๋ ฅ๋์์ต๋๋ค!"); |
|
|
console.log("getPost() ํจ์ ํธ์ถ") |
|
|
getVoice(sentence.value) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
}); |
|
|
|
|
|
function getVoice(sentence){ |
|
|
$.ajax({ |
|
|
type:"get", |
|
|
url: "/voice/"+sentence, |
|
|
timeout:10000, |
|
|
|
|
|
success:function(audio_src){ |
|
|
console.log("success " + audio_src); |
|
|
print_voice(audio_src); |
|
|
}, |
|
|
error:function(request,error){ |
|
|
alert("fail " + sentence); |
|
|
} |
|
|
}) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function print_voice(audio_src){ |
|
|
let voice_tag = document.querySelector("#voice"); |
|
|
voice_tag_html = `<h1>๋ฌธ์ฅ์ด ์์ต๋๋ค~ ${sentence.value} </h1><br> |
|
|
<audio src="../${audio_src}" controls autoplay></audio>`; |
|
|
voice_tag.insertAdjacentHTML("beforeend", voice_tag_html); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |