chrome Web Speech API实现全球语言转文字效果代码
代码语言:html
所属分类:多媒体
代码描述:chrome Web Speech API实现全球语言转文字效果代码,主要需要您的网络能够访问google服务
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html> <head> <meta charset='utf-8'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <title>Web Speech APIU</title> <meta name='viewport' content='width=device-width, initial-scale=1'> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/bootstrap.4.3.1.min.css"> <style> #info a { color: darkred; text-decoration: underline; } .final { color: black; padding-right: 3px; } .interim { color: gray; } #results { font-size: 14px; font-weight: bold; border: 1px solid #ddd; padding: 15px; text-align: left; min-height: 150px; margin: 0 0 20px 0; } #start_button { border: 0; background-color: transparent; padding: 0; cursor: pointer; } #start_img { width: 50px; height: 50px; } .btn-primary { width: 100px; margin: auto; } select { padding: 5px 5px; } @media screen and (max-width: 767px) { #select_dialect { position: absolute; right: 0; } } @media screen and (min-width: 768px) { select { margin-right: 10px; } } </style> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> </head> <body> <main> <div class="container mt-3"> <h3 class="text-center">Web Speech API Demo</h3> <p>需要你的网络能访问google服务</p> <div id="info"></div> <div class="float-right"> <button id="start_button"> <img id="start_img" src="//repo.bfw.wiki/bfwrepo/icon/60ff82091152a.gif" alt="Start"></button> </div> <div id="results"> <span id="final_span" class="final"></span> <span id="interim_span" class="interim"></span> <p> </div> <div class="row col-12 p-0 m-0"> <div class="row col-12 col-md-8 col-lg-6 p-0 m-0"> <select id="select_language"></select> <select id="select_dialect"></select> </div> <div class="col-12 col-md-4 col-lg-6 mt-3 mt-md-0 p-0 m-0"> <div class="float-right"> <button id="copy_button" class="btn btn-primary ">Copy</button> </div> </div> </div> </div> </main> <script> var langs = [ ['中文', ['cmn-Hans-CN', '普通话 (中国大陆)'], ['cmn-Hans-HK', '普通话 (中国香港)'], ['cmn-Hant-TW', '中文 (中国台灣)'], ['yue-Hant-HK', '粵語 (中国香港)']], ['Afrikaans', ['af-ZA']], ['Bahasa Indonesia', ['id-ID']], ['Bahasa Melayu', ['ms-MY']], ['Català', ['ca-ES']], ['Čeština', ['cs-CZ']], ['Deutsch', ['de-DE']], ['English', ['en-AU', 'Australia'], ['en-CA', 'Canada'], ['en-IN', 'India'], ['en-NZ', 'New Zealand'], ['en-ZA', 'South Africa'], ['en-GB', 'United Kingdom'], ['en-US', 'United States']], ['Español', ['es-AR', 'Argentina'], ['es-BO', 'Bolivia'], ['es-CL', 'Chile'], ['es-CO', 'Colombia'], ['es-CR', 'Costa Rica'], ['es-EC', 'Ecuador'], ['es-SV', 'El Salvador'], ['es-ES', 'España'], ['es-US', 'Estados Unidos'], ['es-GT', 'Guatemala'], ['es-HN', 'Honduras'], ['es-MX', 'México'], ['es-NI', 'Nicaragua'], ['es-PA', 'Panamá'], ['es-PY', 'Paraguay'], ['es-PE', 'Perú'], ['es-PR', 'Puerto Rico'], ['es-DO', 'República Dominicana'], ['es-UY', 'Uruguay'], ['es-VE', 'Venezuela']], ['Euskara', ['eu-ES']], ['Français', ['fr-FR']], ['Galego', ['gl-ES']], ['Hrvatski', ['hr_HR']], ['IsiZulu', ['zu-ZA']], ['Íslenska', ['is-IS']], ['Italiano', ['it-IT', 'Italia'], ['it-CH', 'Svizzera']], ['Magyar', ['hu-HU']], ['Nederlands', ['nl-NL']], ['Norsk bokmål', ['nb-NO']], ['Polski', ['pl-PL']], ['Português', ['pt-BR', 'Brasil'], ['pt-PT', 'Portugal']], ['Română', ['ro-RO']], ['Slovenčina', ['sk-SK']], ['Suomi', ['fi-FI']], ['Svenska', ['sv-SE']], ['Türkçe', ['tr-TR']], ['български', ['bg-BG']], ['Pусский', ['ru-RU']], ['Српски', ['sr-RS']], ['한국어', ['ko-KR']], ['日本語', ['ja-JP']], ['Lingua latīna', ['la']]]; </script> <script> var messages = { "start": { msg: '点击右边的麦克风开始说话', class: 'alert-success' }, "speak_now": { msg: '请说话.', class: 'alert-success' }, "no_speech": { msg: 'No speech was detected. You may need to adjust your <a href="//support.google.com/chrome/answer/2693767" target="_blank">microphone settings</a>.', class: 'alert-danger' }, "no_microphone": { msg: 'No microphone was found. Ensure that a microphone is installed and that <a href="//support.google.com/chrome/answer/2693767" target="_blank">microphone settings</a> are configured correctly.', class: 'alert-danger' }, "allow": { msg: '点击允许使用您的麦克风', class: 'alert-warning' }, "denied": { msg: 'Permission to use microphone was denied.', .........完整代码请登录后点击上方下载按钮下载查看
网友评论0