修改,更新
看我的主要目标是首先让用户通过语音(语音到文本)请求特定的(book_name)然后将书打开以大声朗读(文本到语音),最后一步是将这本书打印到盲文,我的卡住点是我没有找到以PDF格式打开这本书的方法,所以我只是将他留作文本区域,我不知道如何使用此代码将文本转换为盲文字母https://gist.github.com/meh/141520
我的目标是在调用不同的变量时打开不同的页面 但代码没有响应,只有一个变量打开一页
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
});
}
我计划使用多本书,所以当说= book1打开第一本书而book2 =打开第二本书等等?我的代码有什么问题
答案 0 :(得分:0)
Foundation.MonoTouchException has been thrown
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: *** -[AVAssetExportSession setOutputFileType:] Invalid output file type
Native stack trace:
0 CoreFoundation 0x0000000181fc9d1c <redacted> + 148
1 libobjc.A.dylib 0x0000000181218528 objc_exception_throw + 56
2 AVFoundation 0x000000018787fcc0 <redacted> + 0
3 BattleSpeak.Platform 0x00000001012276d0 BattleSpeak.Platform + 13596368
..........................................
要求字符串或SpeechSynthesis.speak()
对象,而不是普通对象
您可以使用SpeechSynthesisUtterance
将书籍章节的文本转换为盲文。
在HTML上使用Array.prototype.map()
属性设置预期会被服务识别的章节的data-*
表示,例如JSON
和"chapter one"
以及"chapter 1"
和"chapter two"
分别。
在"chapter 2"
事件result
过滤SpeechSynthesisUtterance
元素时,选择相应的图书章节作为文字。重新启动识别服务,例如<textarea>
webkitSpeechRecognition
次end
次事件的SpeechReconitionUtterance
。
<!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>
答案 1 :(得分:0)
您可以尝试将数组关联到商店图书名称&amp;链接为
link_arr [ 'BOOK1'] = 'linkforbook1'; link_arr [ '第二册'] = 'linkforbook2'; 。 。
通过
获取相应图书的链接链接= link_arr [bookVal];