【问题标题】:How to do a Speech Prompt Response [closed]如何进行语音提示响应[关闭]
【发布时间】:2018-09-10 16:41:09
【问题描述】:

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

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

{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>

【问题讨论】:

    标签: javascript api response prompt voice


    【解决方案1】:

    像这样:

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

    【讨论】:

    • 是的,但是如何将这是一个订单插入到当前代码中?
    • 我不知道你在用剩下的代码做什么 - 如果你正在寻找如何提示某人的名字然后使用库说出它,请替换整个 HTML使用上面的 sn-p。
    • 在两个警报之后,我将提示放在那里,或者至少我正在尝试
    • 我没有看到任何关于“我这里有什么东西吗?”在您的问题中(由于某种原因,这似乎将两个 HTML 文档 + 脚本合并为一个?)。但是,如果您想在“我有什么东西吗?”之后运行该提示并说出代码。警报,然后将我的 JS 粘贴到警报之后,然后将库添加到您的 HTML。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    相关资源
    最近更新 更多