如何将我从语音到文本脚本收集的所有文本存储到变量中?

时间:2019-04-11 01:14:50

标签: javascript

它仅将语音记录的成绩单输出为文本脚本。我想将所有脚本保存为字符串,然后将其插入数据库(PHP,JS,MySQL)。

<div class="words" contenteditable>
  </div>

<script>
  window.SpeechRecognition = window.SpeechRecognition || 
window.webkitSpeechRecognition;
  const recognition = new SpeechRecognition();
  recognition.interimResults = true;
  recognition.lang = 'en-US';

  let p = document.createElement('p');
  const words = document.querySelector('.words');
  words.appendChild(p);
  recognition.addEventListener('result', e => {
    const transcript = Array.from(e.results)
      .map(result => result[0])
      .map(result => result.transcript)
      .join('');
      const poopScript = transcript.replace(/poop|poo|shit|dump/gi, '');
      p.textContent = poopScript;
      if (e.results[0].isFinal) {
        p = document.createElement('p');
        words.appendChild(p);
      }
  });
  recognition.addEventListener('end', recognition.start);
  recognition.start();
</script>

它仅将语音记录的成绩单输出为文本脚本。我想将所有脚本保存为字符串,然后将其插入数据库(PHP,JS,MySQL)。

0 个答案:

没有答案