chrome麦克风权限

by Palash Taneja

由Palash Taneja

如何在Chrome扩展程序中处理麦克风输入权限和语音识别 (How to handle mic input permissions and speech recognition in Chrome extensions)

This tutorial assumes that you have a basic understanding of Chrome extensions and the associated configuration files. If not, then you can refer to this article which sets up the files for this tutorial.

本教程假定您对Chrome扩展程序和相关的配置文件有基本的了解。 如果不是,那么您可以参考本文 , 该文章为本教程设置了文件。

Setting up microphone recording permissions in a Chrome extension is a gray area. There is no officially documented way to do it, and developers are forced to use a “hack” to get mic permissions for their Chrome extension.

在Chrome扩展程序中设置麦克风录制权限为灰色区域。 目前尚无正式记录的方法,开发人员被迫使用“ hack”来获取其Chrome扩展程序的麦克风权限。

In this short article, we use the options.html page to get microphone permissions and use the popular annyang.js library for detecting speech from the user.

在这篇简短的文章中,我们使用options.html页面获取麦克风权限,并使用流行的annyang.js 库检测用户的语音。

1.创建权限触发脚本和页面 (1. Creating a permissions trigger script and page)

To get around Chrome’s restrictions, we use a web page from our extension like options.html andpopup.html to get mic permissions for the entire extension.

为了解决Chrome的限制,我们使用扩展程序中的网页(如options.htmlpopup.html来获取整个扩展程序的麦克风权限。

First, we need to create a JavaScript file to get mic permissions on a web page. I created a minimal file that requests permission to use the mic from chrome.

首先,我们需要创建一个JavaScript文件来获取网页上的麦克风权限。 我创建了一个最小文件,该文件请求允许使用Chrome中的麦克风。

If you’re not a fan of using JQuery, then you can embed this JS code at the end of the HTML page file that you intend to use as a permission trigger.

如果您不喜欢使用JQuery,则可以将此JS代码嵌入打算用作权限触发器HTML页面文件的末尾。

For our extension, TalkToMe, we used options.html as our permission trigger page.

对于我们的扩展程序TalkToMe,我们使用options.html作为权限触发页面。

2.自动打开触发页面 (2. Opening the trigger page automagically)

The mic permission popup will only be opened if the trigger page was opened in the current browser session. Having the user manually open it everytime is bad UX. We created a background script to get around this.

仅当在当前浏览器会话中打开了触发页面时,才会打开“麦克风”权限弹出窗口。 用户每次手动打开它都是糟糕的UX。 我们创建了一个后台脚本来解决这个问题。

It tries to access the mic every 100 ms, and opens the permission-trigger page if the request is denied by Chrome.

它会尝试每100毫秒访问一次麦克风,如果Chrome拒绝了该请求,则会打开权限触发页面。

For the script to work, you need to add it to your manifest.json with other background scripts.

为了使脚本正常工作,您需要将其与其他后台脚本一起添加到manifest.json

3.连接安阳进行语音识别 (3. Hooking up Annyang for speech recognition)

Annyang provides a versatile library for speech recognition, and it is 100% free to use.

安阳提供了用于语音识别的多功能库,并且100%免费使用。

It works on a command-based structure, in that it calls functions based on the user’s speech. This feature made it a perfect fit for TalkToMe.

它在基于命令的结构上工作,它基于用户的语音来调用函数。 此功能使其非常适合TalkToMe。

You can add the annyang.js code to a background script and start using it. Here I am showing you the Hello World example from the docs.

您可以将annyang.js代码添加到后台脚本中并开始使用它。 在这里,我向您展示文档中的Hello World示例。

And ta-da, just like that you have replicated our hours of searching StackOverflow for adding mic permissions to your chrome extension.

和ta-da一样,就像您已经复制了我们在搜索StackOverflow上花费了数小时来为chrome扩展程序添加麦克风权限一样。

If this tutorial helped you, we’d really ❤️ if you could give your thoughts on our extension TalkToMe, even if you may not be a visually impaired user.

如果本教程对您有帮助,即使您可能不是视力障碍的用户,也可以对我们的扩展TalkToMe提出您的想法,我们真的会❤️。

翻译自: https://www.freecodecamp.org/news/handling-mic-input-permissions-and-speech-recognition-in-chrome-extensions-ff7e3ca84cb0/

chrome麦克风权限

chrome麦克风权限_如何在Chrome扩展程序中处理麦克风输入权限和语音识别相关推荐

  1. 在中国使用谷歌语音识别_如何在Google文档中使用语音输入

    在中国使用谷歌语音识别 Google Docs lets you use voice typing to dictate using your computer's microphone. It's ...

  2. react 交互_如何在React应用程序中跟踪用户交互

    react 交互 by Faouzi Oudouh 通过Faouzi Oudouh 如何在React应用程序中跟踪用户交互 (How to track user interactions in you ...

  3. kotlin数据库_如何在Kotlin应用程序中使用Xodus数据库

    kotlin数据库 I want to show you how to use one of my favorite database choices for Kotlin applications. ...

  4. angular发布代码有缓存_如何在Angular应用程序中执行请求?

    全文共5358字,预计学习时长16分钟 来源:Pexels 本文将讨论如何在Angular应用程序中执行请求. 1. 使用拦截器来装饰请求 2. HttpClient 与HttpBackend的对比 ...

  5. chrome修改摄像头权限_如何在Chrome中更改网站的摄像头和麦克风权限

    chrome修改摄像头权限 Google Chrome lets you manage which individual sites can have access to your microphon ...

  6. chrome添加主题_如何在Chrome中添加和删除主题

    chrome添加主题 Google Chrome lets you personalize your experience with themes to make things a little mo ...

  7. chrome硬件加速_如何在Chrome中打开和关闭硬件加速

    chrome硬件加速 Google Chrome comes equipped with hardware acceleration, a feature which takes advantage ...

  8. chrome 保存密码_如何在Chrome中管理保存的密码

    chrome 保存密码 Google Chrome comes with a handy password manager already built in. You can have your br ...

  9. chrome启用插件_如何在Chrome中启用离线浏览

    chrome启用插件 When you visit a webpage in a browser, all the resources, such as images, style sheets, a ...

最新文章

  1. 为什么项目经理很难有节操的选举
  2. 从Docker 到Jenkins 到Ansible的部署经验
  3. python语言编程入门先学什么-自学编程入门,先学什么语言好?
  4. mysql 5.1.17 redis_redis作为mysql的缓存服务器(读写分离)
  5. php 正则分隔_探讨PHP函数split()如何使用正则表达式切割字符串
  6. Makefile使用及多文件gdb 调试
  7. C# 打开文件/跳转链接
  8. C++类的继承与派生
  9. 1、数据结构的基本逻辑结构、存储结构和运算
  10. Swift和Object-C的区别和优缺点
  11. 如何更新一台计算机的驱动程序,怎样更新电脑最新驱动程序? -电脑资料
  12. mzy git学习,分支冲突,以及冲突解决(五)
  13. Java消息队列--ActiveMQ 实战
  14. 数据防泄密-新时代公司发展的必须
  15. 全球及中国装配式建筑行业发展现状及应用价值分析报告2021版
  16. python在excel应用实例视频-超简单:用Python让Excel飞起
  17. 「数据结构」普林斯顿算法课第二周作业
  18. 1005.E. Maximize Sum Of Array After K Negations
  19. 递归判断一个数是不是回文数
  20. GKCTF domo

热门文章

  1. Redis有几种数据类型?文末领取面试资料
  2. 如何化身BAT面试收割机?不吃透都对不起自己
  3. 我三年开发经验,从字节跳动抖音离职后,满满干货指导
  4. install npm 到某个文件下执行_你可能不知道的 npm 依赖管理那些事
  5. Ubuntu中NS2安装详细教程
  6. IOS上传文件给java服务器,返回报错unacceptable context-type:text/plain
  7. JAVA程序员面试必知32个知识点
  8. DW 在onload运行recordset find.html时 发生了以下javascript错误
  9. PHP起点 - 运算符
  10. 搜索引擎怎么收集的那么多内容?