아래 코드를보세요
TTSScript.js
function TTS()
{
var msg = new SpeechSynthesisUtterance("yohan");
var voices = window.speechSynthesis.getVoices();
this.speakText = function()
{
window.speechSynthesis.speak(msg);
}
}
index.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/scripts/TTSScript.js"></script>
<script>
function speak()
{
var msg = new SpeechSynthesisUtterance('Hello World');
window.speechSynthesis.speak(msg);
}
function speak2()
{
var TTS = new TTS();
TTS.speakText();
}
</script>
</head>
<body>
<div><button onclick="speak2()">Click me</button></div>
</body>
</html>
안타깝게도 html 페이지에서 버튼을 클릭하면 오류가 발생합니다. 아래에 있습니다.
Uncaught TypeError: undefined is not a function (13:42:13:817 | error, javascript)
at speak2 (public_html/index.html:23:26)
at onclick (public_html/index.html:31:126)
JavaScript에 익숙하지 않습니다.이 오류가 발생하는 이유와 해결 방법을 알려주세요.
문제를 해결했습니다 .. :
모든 대문자 이름을 변수로 사용하지 마십시오
var tts = new TTS (); tts.speakText ();
올바른 발언은 바이올린에 있습니다.
var msg = new SpeechSynthesisUtterance('Yohan');
window.speechSynthesis.speak(msg);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다