javascript - 如何进行语音提示回复

标签 javascript api response prompt voice

如何让输入的文本(在本例中为名称)自动说出您插入的名称?因此,在这个示例代码中,让一些人输入他们的名字,哈利·波特可以说,而不是文本,响应将是口头的,“你好哈利·波特,你今天好吗?”

我在文本输入代码下方插入了示例音频代码作为特定点。 如果可能的话使用视频

{name:"美国英语女",flag:"us",gender:"f",voiceIDs:[39, 40,41,42,43,173,205,204,235,283,339,44]}而不是下拉

我对 javascript 真的很糟糕,所以请只写代码,不要提出建议,因为我不知道它们的意思。

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>eve_</title>
<link rel="icon" rel="preload" href="images/evecircle.png" />


<style>

#video {
    margin-left:-10px;
    margin-top:-10px;



}

</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<style type="text/css">

body {
    overflow:hidden;
}

</style>

<body onload="delayedAlert();">

<script>
function myText() {
    var txt;
    var person = prompt("What's your name?", "");
    if (person == null || person == "") {
        txt = "User cancelled the prompt.";
    } else {
        txt = "Hello " + person + "! How are you today?";
    }
    document.getElementById("demo").innerHTML = txt;
}

var timeoutID;

function delayedAlert() {
  timeoutID = window.setTimeout(slowAlert, 14999);
  then.getElementsByTagName('audiotwo')[0];
}

function slowAlert() {
 var audio= document.getElementsByTagName('audio')[0];
 const audio2 = document.getElementsByTagName('audio')[1];
 const audio3 = document.getElementsByTagName('audio')[2];


audio.play(); 
var myvar1;alert('...Hello?')

audio2.play();
var myvar2;alert('Hello?');

audio3.play();
var sign = prompt("What's your sign?");

if (person == null || person == "") {
  alert("Hello " + person + "! How are you today?");
}
}


</script>

 <audio>
  <source src="images/hellllloooo.wav" type="audio/wav" preload=true>
 </audio>

 <audio>
  <source src="images/sorry.wav?.wav?.wav" type="audio/wav" preload=true>
 </audio>

 <audio>
  <source src="images/sorry.wav?.wav?.wav" type="audio/wav" preload=true>
 </audio>






        <video autoplay="autoplay" preload="auto" id="video" src="images/secondnew.mp4" width="1300px" height="auto" style="position:absolute; z-index:-1;" >
        Video not supported.
         </video>






</body>
</html>
//////////////////////




  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>
    JavaScript

    <script src="https://code.responsivevoice.org/responsivevoice.js"></script>
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

    <textarea id="text" cols="45" rows="3">Hello world</textarea>

    <select id="voiceselection"></select> 

    <input 
      onclick="responsiveVoice.speak($('#text').val(),$('#voiceselection').val());" 
      type="button" 
      value="Play" 
    />

    <script>
            //Populate voice selection dropdown
            var voicelist = responsiveVoice.getVoices();
            var vselect = $("#voiceselection");
            $.each(voicelist, function() {
                    vselect.append($("<option />").val(this.name).text(this.name));
            });
    </script>

    <script src="https://code.responsivevoice.org/responsivevoice.js"></script>
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

    <textarea id="text" cols="45" rows="3">What's your name?</textarea>

    <select id="voiceselection"></select> 

    <input 
      onclick="responsiveVoice.speak($('#text').val(),$('#voiceselection').val());" 
    />

    <script>
            //Populate voice selection dropdown
            var voicelist = responsiveVoice.getVoices();
            var vselect = $("#voiceselection");
            $.each(voicelist, function() {
                    vselect.append($("<option />").val(this.name).text(this.name));
            });
    </script>

    <body>
    </body>
    </html>

最佳答案

像这样:

const name = prompt('What is your name?')
const sentence = 'Hello ' + name + '! How are you today?';
responsiveVoice.speak(sentence);
<script src="https://code.responsivevoice.org/responsivevoice.js"></script>

关于javascript - 如何进行语音提示回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49594757/

相关文章:

javascript - 捕获 .bs.dropdown 事件

javascript - 如何从 JSON 响应中获取数据?

javascript - 响应 header 中不包含“Set-Cookie”

filter - 在 jMeter 中输入

javascript - jquery animate() 函数没有在表单上触发

javascript - 如果在索引路由 React JS 上则渲染内容

javascript - 如何在 Javascript 中编辑属性节点

java - 为什么 Feedly API 没有返回类别流中的所有 id 条目?

android - 如何使用 retrofit2 将列表发送到 API

java - 为什么在 REST API 中为应用程序(android 端)使用身份验证 token 而不是 session_id