JSPM

uupaa.speech.js

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q11789F
  • License MIT

Speech Synthesis and Recognition.

Package Exports

  • uupaa.speech.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (uupaa.speech.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Speech.js Build Status

npm

Speech Synthesis and Recognition.

This module made of WebModule.

Documentation

Browser, NW.js and Electron

<script src="<module-dir>/lib/WebModule.js"></script>
<script src="<module-dir>/lib/Speech.js"></script>
<script>

var speech = new Speech().load({ name: /Kyoko/i, lang: /ja/i });
var recognizer = new Speech().createRecognizer();
var voiceCommandMap = {
    "clear":    _clearBuffer,
    "stop":     _stopRecognition,
    "クリア":   _clearBuffer,
    "ストップ": _stopRecognition,
    "終了":     _stopRecognition,
    "しゅうりょう": _stopRecognition,
};

function _startRecognition() {
    console.info("start");
    if (speech.ready) { speech.say("お話しください"); }

    recognizer.start(function(event) {
        switch (event.type) {
        case "result":
            if (this.ended) {
                console.log("ok: ", this.result.join(","));
                _processVoiceCommand(this.result[this.result.length - 1].trim(), voiceCommandMap);
                alert(this.result.join(","));
            } else {
                console.log("...", this.buffer.join(","));
            }
            break;
        }
    });
}

function _processVoiceCommand(command, voiceCommandMap) {
    for (var keyword in voiceCommandMap) {
        if (keyword === command) {
            var fn = voiceCommandMap[keyword];
            if (fn) {
                fn();
            }
        }
    }
}
function _stopRecognition() {
    if (speech.ready) { speech.say("音声認識を終了しました"); }
    recognizer.stop();
    console.info("stopped");
}
function _clearBuffer() {
    if (speech.ready) { speech.say("バッファをクリアしました"); }
    recognizer.clear();
    console.info("buffer cleared");
}

</script>