webkitSpeechRecognition实现chrome识别语音指令改变背景颜色效果代码

代码语言:html

所属分类:多媒体

代码描述:webkitSpeechRecognition实现chrome识别语音指令改变背景颜色效果代码

代码标签: 识别 语音 指令 改变 背景 颜色 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width">

    <title>Speech color changer</title>

    <style>
        body, html {
            margin: 0;
        }

        html {
            height: 100%;
        }

        body {
            height: inherit;
            overflow: hidden;
            max-width: 800px;
            margin: 0 auto;
        }

        h1, p {
            font-family: sans-serif;
            text-align: center;
            padding: 20px;
        }

        div {
            height: 100px;
            overflow: auto;
            position: absolute;
            bottom: 0px;
            right: 0;
            left: 0;
            background-color: rgba(255,255,255,0.2);
        }

        ul {
            margin: 0;
        }

        .hints span {
            text-shadow: -1px 1px 0px rgb(254 254 254 / 90%);
            margin: 10px;
            display: block;
            height: 40px;
            line-height: 40px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <h1>用英文说出以下颜色</h1>
    <p>需要您的网络能够访问google提供的服务</p>

    <p class="hints"></p>
    <div>
        <p class="output">
            <em>指令识别中.....</em>
        </p>
    </div>

    <script>
    //
      

        var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
        var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList
        var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent

        var colors = ['aqua', 'azure', 'beige', 'bisque', 'black', 'blue', 'brown', 'chocolate', 'coral', 'crimson', 'cyan', 'fuchsia', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'indigo', 'ivory', 'khaki', 'lavender', 'lime', 'linen', 'magenta', 'maroon', 'moccasin', 'navy', 'olive', 'orange', 'orchid', 'peru', 'pink', 'plum', 'purple', 'red', 'salmon', 'sienna', 'silver', 'snow', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'white', 'yellow'];
        var grammar = '#JSGF V1.0; grammar colors; public <color> = .........完整代码请登录后点击上方下载按钮下载查看

网友评论0