LoginSignup
0
0

More than 3 years have passed since last update.

Scrapbox to Speech (Web Speech APIでScrapboxの内容を喋らせる)

Last updated at Posted at 2019-06-23

Demo

デモはこちら

機能

スクラップボックスで選択したテキストを喋らせる。喋っている最中に中断すること可能(動画の2回目の再生は途中でキャンセルしてる)

コード

script.js
 // 選択した文章に対してボタンを追加
 scrapbox.PopupMenu.addButton({
    title: 'Speach',
    // ボタンをクリックして選択した文章の内容を取得(Plain textで取得するのが望ましい)
    onClick: text => {
        // https://qiita.com/hmmrjn/items/be29c62ba4e4a02d305c
        // https://app.codegrid.net/entry/2016-web-speech-api-1
        // こちらを参考にWeb Speech APIを使う
        const uttr = new SpeechSynthesisUtterance(text);
        if (speechSynthesis.speaking == false) {
            speechSynthesis.speak(uttr);
        } else {
            speechSynthesis.cancel();
        }
    }
 })
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0