2017-11-04 3 views
1

[編集]を開くには、複数の変数を使用して、更新異なるリンク

は(私の主な目標は大声でそれを読んで、その後の本を開いて音声でユーザの要求の特定(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 =その上の第二を開くと、複数のブックを使用する予定の1ページだけ一つの変数開き、コードを応答しない?問題は何であります私のコードの

答えて

0

SpeechSynthesis.speak()はあなたが点字への本の章のテキストを変換するためにArray.prototype.map()を使用することができます文字列またはSpeechSynthesisUtteranceオブジェクトではなく、プレーンなオブジェクト


のいずれかを期待しています。 HTMLで

使用data-*属性は、サービスによって認識されると予想章のJSON表現、例えば両方"chapter one""chapter 1""chapter two""chapter 2"それぞれを設定します。

resultイベントのSpeechSynthesisUtteranceフィルタ<textarea>の要素で、書籍の対応する章をテキストとして選択します。認識サービスを再起動します。たとえばwebkitSpeechRecognitionendイベント、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> 

あなたは

link_arr [ 'BOOK1'] = 'linkforbook1' として書籍名&リンクを格納する連想配列を試すことができますplnkr https://plnkr.co/edit/Xwc5iFtgbTnz13DDKC3z?p=preview

+0

私はこれらの部分をどこに置き換えるべきか、何に置き換えるべきですか? –

+0

http://jsfiddle.net/1vv7n14h/ – guest271314

+0

@SamarDahan jsfiddleでコードを試しましたか? 「英国の女性」は定義された声ですか? – guest271314

0

。 link_arr ['book2'] = 'linkforbook2'; 。 。 。

リンク= link_arr [bookVal]でそれぞれのブックへのリンクを取得します。

関連する問題