使用多个变量打开不同的链接 [英] using multiple variables to open different links
问题描述
编辑、更新
看到我的主要目标是首先让用户通过语音(语音到文本)请求特定的(书名),然后打开书大声阅读(文本到语音),最后一步是将这本书打印到盲文,我的难点是我没有找到以 pdf 格式打开这本书的方法,所以我只是将他作为文本区域,我不知道如何使用此代码将文本转换为盲文字母 https://gist.github.com/meh/141520
<小时>我的目标是在调用不同的变量时打开不同的页面但是代码没有反应,只有一个变量打开一页
if (speechresult ) {//这里我添加了 Speechrecognizer.stop 以使命令不被中断语音识别器.停止();var yourValue = 'Book 1';window.open("http://localhost/introductiontonetworking.html");responseVoice.speak(bookstart, "英国英语女性", {//SpeechSynthesisUtterance 接口的pitch 属性获取和设置说话的音调.默认 1音高:1}, {//默认为1比率:1});}else if (speechresult == book2) {语音识别器.停止();var yourValue = 'Book 2';window.open("http://localhost/ethicalhacking.html");responseVoice.speak(bookstart, "英国英语女性", {音高:1}, {比率:1});}
我打算使用多本书,所以当说 = book1 打开第一本书和 book2 = 打开第二本书等等时?我的代码有什么问题
SpeechSynthesis.speak()
需要字符串或 SpeechSynthesisUtterance
对象,而不是普通对象
您可以使用 Array.prototype.map()
将书的章节文本转换为盲文.
在 HTML 中使用 data-*
属性来设置预期被服务识别的章节的 JSON
表示,例如 "chapter one"
和 chapter 1"
和 chapter 2"
和 chapter 2"
分别.
在SpeechSynthesisUtterance
过滤 元素的
result
事件中选择书籍的相应章节作为文本.重新启动识别服务,例如 SpeechReconitionUtterance
实例的 end
事件中的 webkitSpeechRecognition
.
<头><title>道德黑客书籍</title><style type="text/css">身体 {字体系列:verdana;}.按钮 {显示:内联块;背景:#f6f6f6;填充:10px 20px;颜色:#000;边框:1px 实心 #ccc;光标:指针;边距顶部:20px;}.button:悬停{框阴影:4px 4px 10px 0 #ccc;}.container 文本区域,.container .brailleResult {宽度:1333px;高度:1000px;调整大小:无;大纲:无;边框:1px 实心 #ccc;框阴影:0 0 10px 0 #ddd;字体大小:14px;}</风格>头部><身体><div class="容器"><h3>道德黑客</h3><textarea class="myText" data-chapter='["chapter one", "chapter 1"]'>Chapter 1. 黑客简介.黑客有很多定义.从方阵上问这个问题,每次都会得到新的答案,因为嘴多就会说话多,这就是定义不同的原因的黑客,在我看来这是非常合理的,因为每个人都有权以不同的方式思考.在 1990 年代初期,hacker 这个词被用来描述一个伟大的程序员,一个能够构建复杂逻辑的人.</textarea><div class="brailleResult"></div><textarea class="myText" data-chapter='["chapter two", "chapter 2"]'>第 2 章 Linux 基础.为了成为一名优秀的道德黑客或渗透测试员,您需要熟悉 Linux,它是迄今为止最强大的操作系统之一.Linux 非常适合道德黑客攻击和渗透测试因为它兼容各种相关的工具和软件,而其他操作系统如 Mac 和 Windows 支持的这些软件和工具较少.在本章中,我将教你一些非常基础的操作一个 Linux 操作系统.如果您已经熟悉 Linux 基础知识,则可以跳过本章.</textarea><div class="brailleResult"></div>
<script type="text/javascript">var 盲文 = [['1', '⠼⠁'],['2', '⠼⠃'],['3', '⠼⠉'],['4', '⠼⠙'],['5', '⠼⠑'],['6', '⠼⠋'],['7', '⠼⠛'],['8', '⠼⠓'],['9', '⠼⠊'],['0', '⠼⠚'],['A', '⠠⠁'],['B', '⠠⠃'],['C', '⠠⠉'],['D', '⠠⠙'],['E', '⠠⠑'],['F', '⠠⠋'],['G', '⠠⠛'],['H', '⠠⠓'],['我', '⠠⠊'],['J', '⠠⠚'],['K', '⠠⠅'],['L', '⠠⠇'],['M', '⠠⠍'],['N', '⠠⠝'],['O', '⠠⠕'],['P', '⠠⠏'],['Q', '⠠⠟'],['R', '⠠⠗'],['S', '⠠⠎'],['T', '⠠⠞'],['U', '⠠⠥'],['V', '⠠⠧'],['W', '⠠⠺'],['X', '⠠⠭'],['Y', '⠠⠽'],['Z', '⠠⠵'],['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', '⠵'],['\\.', '⠲'],[',', '⠂'],['\\?', '⠦'],[';', '⠆'],['!', '⠖'],['<', '⠦'],['>', '⠴'],['\\[', '⠶'],['-', '⠤'],["'", '⠄'],];功能检查兼容性(){if (!('speechSynthesis' in window)) {alert('您的浏览器不支持,如果是谷歌浏览器,请升级!');}};检查兼容性();var Chapters = document.querySelectorAll('.myText');var brailleResult = document.querySelectorAll(".brailleResult");var 识别 = new webkitSpeechRecognition();识别.continuous = true;识别.interimResults = false;识别.maxAlternatives = 1;识别.onresult = handleRecognition;识别开始();var book = new SpeechSynthesisUtterance();book.onend = 重置识别;book.default = false;var voiceselect = window.speechSynthesis.getVoices();book.voice = voiceselect.filter(function(voice) {返回 voice.name == 'Google 英国英语男';})[0];book.lang = 'en-EN';book.volume = 1;书率 = 1;book.pitch = 1;函数 textToBraille(章节){返回 Array.prototype.map.call(chapter, function(text) {var result = braille.find(([key, prop]) => text === key);返回结果 &&结果[1] ||文本}).加入("")}函数句柄识别(事件){识别.停止();var Chapter = event.results[event.results.length - 1][0].transcript.trim();控制台日志(章节);for (var i = 0; i < Chapters.length; i++) {如果 (JSON.parse(chapters[i].dataset.chapter).some(function(ch) {返回 ch === 章节})) {说话(章节[i].值);brailleResult[i].innerHTML = textToBraille(chapters[i].value)}}}功能重置识别(){识别开始();}功能说话(章节){book.text = 章节;window.speechSynthesis.speak(book);};</html>
plnkr https://plnkr.co/edit/Xwc5iFtgbTnz13DDKC3z?p=preview
Edit, Updated
see my main goal is first to let the user request a specific (book_name) by the voice (speech to text) then the book open to read it loudly (text to speech) and the last step is to print this book to braille, my stuck points is I didn't found a way to open the book as pdf so I just left him as a text area, and I don't know how to convert the text to braille letters with this code https://gist.github.com/meh/141520
My goal is to open different pages when calling different variables but the code doesn't respond, only one variable open one page
if (speechresult ) {
//here I added speechrecognizer.stop for the commands to not get interrupted
speechRecognizer.stop();
var yourValue = 'Book 1';
window.open("http://localhost/introductiontonetworking.html");
responsiveVoice.speak(bookstart, "UK English Female", {
//The pitch property of the SpeechSynthesisUtterance interface gets and sets the pitch at which the utterance will be spoken at. by default 1
pitch: 1
}, {
//rate by default 1
rate: 1
});
}
else if (speechresult == book2) {
speechRecognizer.stop();
var yourValue = 'Book 2';
window.open("http://localhost/ethicalhacking.html");
responsiveVoice.speak(bookstart, "UK English Female", {
pitch: 1
}, {
rate: 1
});
}
I plan to use multiple books, so when said = book1 open the first book and book2 = open the second and so on?what is the problem of my code
SpeechSynthesis.speak()
expects either a string or a SpeechSynthesisUtterance
object, not a plain object
You can use Array.prototype.map()
to convert the text of chapters of book to Braille.
Use data-*
attribute at HTML to set JSON
representation of chapters expected to be recognized by the service, for example both "chapter one"
and "chapter 1"
and "chapter two"
and "chapter 2"
respectively.
At result
event of SpeechSynthesisUtterance
filter <textarea>
elements to select the corresponding chapter of the book as text. Restart the recognition service, e.g., webkitSpeechRecognition
at end
event of SpeechReconitionUtterance
instance.
<!DOCTYPE html>
<html>
<head>
<title>Ethical Hacking book</title>
<style type="text/css">
body {
font-family: verdana;
}
.button {
display: inline-block;
background: #f6f6f6;
padding: 10px 20px;
color: #000;
border: 1px solid #ccc;
cursor: pointer;
margin-top: 20px;
}
.button:hover {
box-shadow: 4px 4px 10px 0 #ccc;
}
.container textarea,
.container .brailleResult {
width: 1333px;
height: 1000px;
resize: none;
outline: none;
border: 1px solid #ccc;
box-shadow: 0 0 10px 0 #ddd;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h3>Ethical Hacking</h3>
<textarea class="myText" data-chapter='["chapter one", "chapter 1"]'>Chapter 1. Introduction to Hacking. There are many definitions for hacker. Ask this question from a phalanx, and you will get a new answer every time, because more mouths will have more talks, and this is the reason behind the different definitions
of hackers, which in my opinion is quite justified for everyone has a right to think differently. In the early 1990s, the word hacker was used to describe a great programmer, someone who was able to build complex logics.
</textarea>
<div class="brailleResult"></div>
<textarea class="myText" data-chapter='["chapter two", "chapter 2"]'>Chapter 2. Linux Basics. In order to become a good ethical hacker or penetration tester, you need to be conversant with Linux, which is by far one of the most powerful operating systems. Linux is really good for ethical hacking and penetration testing
because it is compatible with a wide variety of related tools and software, whereas other operating systems such as Mac and Windows support fewer of these software and tools. In this chapter, I will teach you some of the very basics of operating
a Linux OS. If you are already familiar with Linux basics, you can skip this chapter.</textarea>
<div class="brailleResult"></div>
</div>
<script type="text/javascript">
var braille = [
['1', '⠼⠁'],
['2', '⠼⠃'],
['3', '⠼⠉'],
['4', '⠼⠙'],
['5', '⠼⠑'],
['6', '⠼⠋'],
['7', '⠼⠛'],
['8', '⠼⠓'],
['9', '⠼⠊'],
['0', '⠼⠚'],
['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', '⠠⠵'],
['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', '⠵'],
['\\.', '⠲'],
[',', '⠂'],
['\\?', '⠦'],
[';', '⠆'],
['!', '⠖'],
['<', '⠦'],
['>', '⠴'],
['\\[', '⠶'],
['-', '⠤'],
["'", '⠄'],
];
function checkCompatibilty() {
if (!('speechSynthesis' in window)) {
alert('Your browser is not supported. If google chrome, please upgrade!');
}
};
checkCompatibilty();
var chapters = document.querySelectorAll('.myText');
var brailleResult = document.querySelectorAll(".brailleResult");
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.onresult = handleRecognition;
recognition.start();
var book = new SpeechSynthesisUtterance();
book.onend = resetRecognition;
book.default = false;
var voiceselect = window.speechSynthesis.getVoices();
book.voice = voiceselect.filter(function(voice) {
return voice.name == 'Google UK English Male';
})[0];
book.lang = 'en-EN';
book.volume = 1;
book.rate = 1;
book.pitch = 1;
function textToBraille(chapter) {
return Array.prototype.map.call(chapter, function(text) {
var result = braille.find(([key, prop]) => text === key);
return result && result[1] || text
}).join("")
}
function handleRecognition(event) {
recognition.stop();
var chapter = event.results[event.results.length - 1][0].transcript.trim();
console.log(chapter);
for (var i = 0; i < chapters.length; i++) {
if (JSON.parse(chapters[i].dataset.chapter).some(function(ch) {
return ch === chapter
})) {
speak(chapters[i].value);
brailleResult[i].innerHTML = textToBraille(chapters[i].value)
}
}
}
function resetRecognition() {
recognition.start();
}
function speak(chapter) {
book.text = chapter;
window.speechSynthesis.speak(book);
};
</script>
</body>
</html>
plnkr https://plnkr.co/edit/Xwc5iFtgbTnz13DDKC3z?p=preview
这篇关于使用多个变量打开不同的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!