Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Speech Detection</title>
  6. </head>
  7. <body>
  8.  
  9. <div class="words" contenteditable>
  10. </div>
  11.  
  12. <script>
  13. window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
  14.  
  15. const recognition = new SpeechRecognition();
  16. recognition.interimResults = true;
  17. recognition.lang = 'en-US';
  18.  
  19. let p = document.createElement('p');
  20. const words = document.querySelector('.words');
  21. words.appendChild(p);
  22.  
  23. recognition.addEventListener('result', e => {
  24. var transcript = Array.from(e.results)
  25. .map(result => result[0])
  26. .map(result => result.transcript)
  27. .join('');
  28.  
  29. // const poopScript = transcript.replace(/poop|poo|shit|dump/gi, '💩');
  30. // p.textContent = poopScript;
  31.  
  32.  
  33.  
  34. var mySpeechShortcuts = [{found: "smile", substitute: '🤑'}, {found: "poop", substitute: '💩'}];
  35. var finalTxt = '';
  36. mySpeechShortcuts.map((shortcut) => {
  37. finalTxt += transcript.replace(shortcut.found, shortcut.substitute);
  38.  
  39. })
  40. p.textContent = finalTxt;
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. if (e.results[0].isFinal) {
  51. p = document.createElement('p');
  52. words.appendChild(p);
  53. }
  54. });
  55.  
  56.  
  57.  
  58. recognition.addEventListener('end', recognition.start);
  59.  
  60. recognition.start();
  61.  
  62. </script>
  63.  
  64.  
  65. <style>
  66. html {
  67. font-size: 10px;
  68. }
  69.  
  70. body {
  71. background: #ffc600;
  72. font-family: 'helvetica neue';
  73. font-weight: 200;
  74. font-size: 20px;
  75. }
  76.  
  77. .words {
  78. max-width: 500px;
  79. margin: 50px auto;
  80. background: white;
  81. border-radius: 5px;
  82. box-shadow: 10px 10px 0 rgba(0,0,0,0.1);
  83. padding: 1rem 2rem 1rem 5rem;
  84. background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px;
  85. background-size: 100% 3rem;
  86. position: relative;
  87. line-height: 3rem;
  88. }
  89.  
  90. p {
  91. margin: 0 0 3rem;
  92. }
  93.  
  94. .words:before {
  95. content: '';
  96. position: absolute;
  97. width: 4px;
  98. top: 0;
  99. left: 30px;
  100. bottom: 0;
  101. border: 1px solid;
  102. border-color: transparent #efe4e4;
  103. }
  104. </style>
  105.  
  106. </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement