如何使用Web Audio API听到“ Yanny”和“ Laurel”的声音
by _haochuan
通过_haochuan
如何使用Web Audio API听到“ Yanny”和“ Laurel”的声音 (How you can hear both “Yanny” and “Laurel” using the Web Audio API)
Recently an audio clip asking listeners whether they hear the word “Yanny” or “Laurel” has been completely puzzling the world and pitting friend against friend in the online debate.
最近,一个音频片段询问听众是否听到“ Yanny”或“ Laurel”一词,这已经使整个世界迷惑不解,在网上辩论中让朋友与朋友对立。
The clip and the “Yanny or Laurel” poll were posted on Instagram, Reddit, and other sites by high school students who said that it had been recorded from a vocabulary website playing through the speakers on a computer. Now hundreds of thousands of people are engaged in a debate over what they hear. It’s been driving people crazy and leading to passionate defenses on both side.
该剪辑和“ Yanny or Laurel”民意测验由高中生在Instagram,Reddit和其他网站上发布,他们说这是从词汇网站上录制的,是通过计算机上的扬声器播放的。 现在,成千上万的人正在就他们所听到的进行辩论。 它使人们发疯,并导致双方都充满激情。
However, the magic behind this debate is quite simple. Different ears have different sensitive frequency zones for the same audio clip. Also, different speakers have different responses to different audio frequencies.
但是,这场辩论背后的魔术很简单。 对于相同的音频剪辑,不同的耳朵具有不同的敏感频率区域。 同样,不同的扬声器对不同的音频频率有不同的响应。
This tutorial will go through the details about how to use the Web Audio API and simple JavaScript to create to tool that will help you hear both “Yanny” and “Laurel.” Then you’ll be able to win any of those debates. :)
本教程将详细介绍如何使用Web Audio API和简单JavaScript创建工具,以帮助您听到“ Yanny” 和 “ Laurel”。 然后,您将可以赢得所有这些辩论。 :)
If you just want to try the tool, it is live HERE. Just open your browser, play the audio, and try to find the sweet spots for “Yanny” and “Laurel” while moving the frequency slider.
如果您只想尝试使用该工具,请点击这里 。 只需打开浏览器,播放音频,然后在移动频率滑块的同时尝试找到“ Yanny”和“ Laurel”的最佳位置。
这个怎么运作 (How it works)
Let’s talk about the key part first. In order to hear the different word, you need to somehow increase the volume for a specific frequency range which depends on your ears. Luckily the Web Audio API already has something ready for us: BiquadFilterNode
.
让我们先谈谈关键部分。 为了听到不同的单词,您需要以某种方式针对特定频率范围增加音量,具体取决于您的耳朵。 幸运的是,Web Audio API已经为我们准备了一些东西: BiquadFilterNode
。
There are different types of BiquadFilterNode
you can use. For this case, we will just go with the bandpass
filter.
您可以使用不同类型的BiquadFilterNode
。 对于这种情况,我们将只使用bandpass
滤波器。
A bandpass filter is an electronic device or circuit that allows signals between two specific frequencies to pass, but that discriminates against signals at other frequencies. (source)
带通滤波器是一种电子设备或电路,它允许两个特定频率之间的信号通过,但与其他频率的信号有所区别。 ( 来源 )
And for a bandpass filter, most of the time we just need to define the center frequency value we want to boost or cut, instead of the start and the end of the frequency range. We use a Q
value to control the width of the frequency range. The larger the Q
is, the narrower the frequency range will be. Check out Wikipedia for more details.
对于带通滤波器,大多数情况下,我们只需要定义要提高或降低的中心频率值即可,而不是定义频率范围的起点和终点。 我们使用Q
值来控制频率范围的宽度。 Q
越大,频率范围将越窄。 查阅Wikipedia了解更多详细信息。
That’s all the knowledge we need to know at this point. Now, let’s write the code.
这就是我们现在需要知道的所有知识。 现在,让我们编写代码。
网络音频API初始化 (Web Audio API Initialization)
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioContext = new AudioContext();
创建音频节点以及设置和信号链 (Create Audio Nodes along with setup and signal chain)
// the audio tag in HTML, where holds the original audio clipconst audioTag = document.getElementById('audioTag');
// create audio source in web audio apiconst sourceNode =
audioContext.createMediaElementSource(audioTag);
const filterNode = audioContext.createBiquadFilter();
filterNode.type = 'bandpass'; // bandpass filterfilterNode.frequency.value = 1000 // set the center frequency
// set the gain to the frequency rangefilterNode.gain.value = 100;
// set Q value, 5 will make a fair band width for this casefilterNode.Q.value = 5;
// connect nodessourceNode.connect(filterNode);filterNode.connect(gainNode);gainNode.connect(audioContext.destination);
样本HTML文件 (Sample HTML file)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Yanny vs Laurel Web Audio API</title></head><body> <div id="container"> <audio id='audioTag' crossorigin="anonymous" src="yanny-laurel.wav" controls loop></audio> <hr> <input type="range" min="20" max="10000" value="20" step="1" class="slider" id="freqSlider"> </div> <script src='script.js'></script></body></html>
添加频率滑块UI (Adding frequency slider UI)
To make it easier to adjust the center frequency of our bandpass filter, we should add a slider to control the value.
为了更容易地调整带通滤波器的中心频率,我们应该添加一个滑块来控制该值。
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Yanny vs Laurel Web Audio API</title></head><body> <div id="container"> <audio id='audioTag' src="yanny-laurel.wav" controls loop></audio> <hr> <input type="range" min="50" max="4000" value="1000" step="1" class="slider" id="freqSlider"> <br> <p id="freqLabel" >Frequency: 1000 Hz</p> </div> <script>; // add event listener for slider to change frequency value slider.addEventListener('input', e => {
filterNode.frequency.value = e.target.value; label.innerHTML = `Frequency: ${e.target.value}Hz`;
}, false); <script src='script.js'></script><;/body></html>
iOS Safari中的createMediaElementSource错误 (createMediaElementSource bug in iOS Safari)
I found that createMediaElementSource
won't work in iOS Safari and Chrome. To solve this, you have to use createBufferSource
to create an AudioBufferNode to store and play the audio instead of the HTML audio tag.Please see the code here for more detail.
我发现createMediaElementSource
在iOS Safari和Chrome中不起作用。 要解决此问题,您必须使用createBufferSource
创建一个AudioBufferNode来存储和播放音频,而不是HTML音频标签。有关更多详细信息,请参见此处的代码 。
Now you made yourself a tool so you can hear both “Yanny” and “Laurel.” Just open your browser, play the audio, and try to find the sweet spot while moving the frequency slider.
现在,您已经成为工具,可以同时听到“ Yanny”和“ Laurel”的声音。 只需打开浏览器,播放音频,然后尝试在移动频率滑块的同时找到最佳位置。
If you want to just try the tool, it is live HERE.
如果您只想尝试使用该工具,请点击这里 。
I write code for audio and web, and play guitar on YouTube. If you want to see more stuff from me or know more about me, you can always find me on:
我编写音频和网络代码,并在YouTube上弹吉他。 如果您想从我这里看到更多东西或对我有更多了解,可以随时在以下位置找到我:
Website:https://haochuan.io/
网址: https : //haochuan.io/
GitHub:https://github.com/haochuan
GitHub: https : //github.com/haochuan
Medium:https://medium.com/@haochuan
媒介: https : //medium.com/@haochuan
YouTube: https://www.youtube.com/channel/UCNESazgvF_NtDAOJrJMNw0g
YouTube: https : //www.youtube.com/channel/UCNESazgvF_NtDAOJrJMNw0g
翻译自: https://www.freecodecamp.org/news/how-you-can-hear-both-yanny-and-laurel-using-the-web-audio-api-306051cfcede/
相关文章:
SCARA——OpenGL入门学习一、二
参考博客:http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html 简介 最近开始一个机械手臂的安装调试,平面关节型机器人又称SCARA(Selective Compliance Assembly Robot Arm)型机器人,是一种应用于装配作业的机器人手臂。然后找资料学习一下…

[.NET] 《Effective C#》快速笔记 - C# 中的动态编程
《Effective C#》快速笔记 - C# 中的动态编程 静态类型和动态类型各有所长,静态类型能够让编译器帮你找出更多的错误,因为编译器能够在编译时进行大部分的检查工作。C# 是一种静态类型的语言,不过它加入了动态类型的语言特性,可以…

阿里云https证书apache配置
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 一:下载证书; 二:安装证书 文件说明: 1. 证书文件1534884149377.pem,包含两段内容,请不要删除任何一段内容。…

vue css 应用变量_如何使用CSS Grid和CSS变量快速为应用创建原型
vue css 应用变量CSS Grid and CSS Variables are both huge wins for front-end developers. The former makes it dead simple to create website layouts, while the latter brings the power of variables to your stylesheets.CSS Grid和CSS变量对于前端开发人员都是巨大的…

linux--memcache的安装和使用(转)
memcache是高性能,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。据说官方所说,其用户包括twitter、digg、flickr等,都是些互联网大腕呀。目前用memcache解决互联网上的大用户读取是非常流行…

EF 调试跟踪生成的SQL语句
IQueryable query from x in appEntitieswhere x.id 10select x;var sql ((System.Data.Objects.ObjectQuery)query).ToTraceString(); 或者 EF6 : var sql ((System.Data.Entity.Core.Objects.ObjectQuery)query).ToTraceString(); 转载于:https://www.cnblogs…

微信小程序图片自适应宽高比例显示解决方法
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 解决方案一:写固定宽度,然后使用 image 组件中 mode 属性的 widthFix ; 先看效果图: 实现代码: <image classmy_img mo…

初创公司面试要问什么_聘请初创公司的产品设计师时要问的问题
初创公司面试要问什么by Bohdan Kit通过Bohdan Kit 聘请初创公司的产品设计师时要问的问题 (Questions to ask when hiring a product designer for a startup) 在人群中寻找隐藏宝石的方法指南 (A how-to guide on finding hidden gems in the crowd) Finding the right pers…

Select Top在不同数据库中的使用
1. oracle数据库 SELECT * FROM TABLE1 WHERE ROWNUM<N 2. Infomix数据库 SELECT FIRST N * FROM TABLE1 3. DB2数据库 SELECT * ROW_NUMBER() OVER(ORDER BY COL1 DESC) AS ROWNUM WHERE ROWNUM<N 或者 SELECT COLUMN FROM TABLE FETCH FIRST N ROWS ONLY 4. SQL Server…
bat+sqlcmd 批量执行脚本
Hello,此BAT脚本能够帮助开发者将某目录下全部SQL脚本按文件名称依次在指定数据库中批量执行。不用忍受powershell invoke-sqlcmd 的笨重。在指执行时多一种选择。 bat文件 echo off REM ******** ******** General Batch for Starting SQL ******** ******** REM %1 is the n…

突破微信小程序五层层级限制的解决方案
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 五层的限制只是针对 navigateTo,redirectTo 不受此限制。 navigateTo :保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以…

react-dnd-dom_我如何使用react-dnd和react-flip-move构建React游戏
react-dnd-domby Nicholas Vincent-Hill尼古拉斯文森特希尔(Nicholas Vincent-Hill) 我如何使用react-dnd和react-flip-move构建React游戏 (How I built a React game with react-dnd and react-flip-move) This is a high level overview of my implementation of a puzzle/w…

web应用程序和web网站_Web应用程序和移动应用程序的基本启动清单
web应用程序和web网站by Ben Cheng通过本诚 Web应用程序和移动应用程序的基本启动清单 (The Essential Launch Checklist for Web Apps and Mobile Apps) This is a simple launch checklist for web and mobile apps that I’ve prepared for product and project managers t…

javascript禁止修改对象
禁止扩展 Object.preventExtensions(obj);var me {name: "xiaowtz" }; console.log(Object.isExtensible(me)); //true,对象默认都是可扩展的Object.preventExtensions(me); //禁止对象扩展后,不可以给对象添加新的属性console.log(Object.isExtensible(…

webpack入门之简单例子跑起来
webpack入门之简单例子跑起来 webpack介绍 Webpack是当下最热门的前端资源模块化管理和打包工具,它可以将很多松散的模块按照依赖和规则打包成符合生产环境部署的前端资源,还可以将按需加载的模块进行代码分割,等到实际需要的时候再异步加载。…

微信小程序 scroll-view 根据内容的高度自适应
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 1 <video autoplay src"{{videoPlayUrl}}" controls></video> <scroll-view scroll-y style"height: {{height?heightpx:auto}}"><view c…

org.hibernate.hibernate.connection.release_mode
org.hibernate.connection包的主要封装了通过JDBC来连接数据库的操作,用户可以以数据源的方式,或者通过特定数据库驱动的方式,甚至是自己定义连接类的方式来完成数据库的连接操作,包下面的代码文件并不多,只有5个&…

添加百度地图最简单的办法
http://map.baidu.com/?newmap1&ieutf-8&ss%26wd%3D%E4%B8%8A%E6%B5%B7%E9%9D%92%E6%B5%A6%E5%8C%BA%E5%BE%90%E9%BE%99%E8%B7%AF77%E5%8F%B7后面加上地址就好了 比方说:http://map.baidu.com/?newmap1&ieutf-8&ss%26wd%3D%E4%B8%8A%E6%B5%B7%E9%…

微信小程序的数字有部分会自动加粗的解决方法
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: bug图: 能看到,0和1是一个标签里面的,但是不统一显示 此时的代码: <view>2018-08-01</view> 修改后的代码:…

ux设计_从UX设计人员的角度来看Microsoft Build 2018
ux设计by Samuele Dassatti通过萨穆尔达萨蒂 从UX设计人员的角度来看Microsoft Build 2018 (Microsoft Build 2018 from the perspective of a UX designer) I recently attended Microsoft Build 2018 in Seattle, because one of my apps was nominated for Design Innovato…

DFS template and summary
最近一直在学习Deep Frist Search,也在leetcode上练习了不少题目。从最开始的懵懂,到现在遇到问题基本有了思路。依然清晰的记得今年2月份刚开始刷题的时做subsets的那个吃力劲,脑子就是转不过来到底该如何的递归,甚至试过使用deb…

linux gcc安装
2004年4月20日最新版本的GCC编译器3.4.0发布了。目前,GCC可以用来编译C/C、FORTRAN、java、OBJC、ADA等语言的程序,可根据需要选择安装支持的语言。GCC 3.4.0比以前版本更好地支持了C标准。本文以在Redhatlinux上安装GCC3.4.0为例,介绍了GCC的…

js中 let var const 的差异和使用场景
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 建议使用的优先级:const > let > var ES6 提出了两个新的声明变量的命令:let和const。其中,let完全可以取代var,因为两…

bulma.css_如何建立一个? 具有Bulma CSS的特斯拉响应页面
bulma.cssby ZAYDEK由ZAYDEK 0-60 in 1.9s? (0-60 in 1.9s ?) 如何建立一个? 具有Bulma CSS的特斯拉响应页面 (How To Build A ? Responsive Tesla Launch Page With Bulma CSS) 加速可持续网页设计的到来 (To accelerate the advent of sustainable …

hdu 5099 Comparison of Android versions 枚举题意
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid5099 卡读题,实际上题目中表述的题意并不完整,所以要认真读并且加上一些现实的“常识” 关于枚举题意,感觉应该三个人分别看,然后讨论出最有可能的题意是什么 为了…

去除按钮的样式
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 去除按钮默认点击效果: 在button标签里面添加属性: hover-class"none"; 为了方便大家,下面列出微信请求服务器常用的几种方…

移动应用程序和网页应用程序_您的移动应用程序运行缓慢的主要原因以及如何修复它...
移动应用程序和网页应用程序by Rajput Mehul通过拉杰普特梅胡尔(Rajput Mehul) 您的移动应用程序运行缓慢的主要原因以及如何修复它 (Top Reasons Why Your Mobile App is Slow and How to Fix it) At a time when technology is moving ahead at an express pace and people …

邮箱验证功能原理 语法 属性
邮箱验证功能原理 1 [已解决问题] 浏览: 3508次 很多地方都在注册账号的时候使用邮箱验证功能。注册后发送一封邮件到注册邮箱里面。然后点击 邮箱里面的链接 激活邮箱。 还有手机验证 这些的原理是 怎么样的。忘指点 .NET技术 ASP.NETyzy | 菜鸟二级 | 园豆:295 提…

直接通过OptionalAttribute, DefaultParameterValueAttribute定义缺省参数
转载于:https://www.cnblogs.com/liuxiaoji/p/4519266.html

微信小程序学习做动画效果
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 微信扫码学习,在线指导微信小程序动画效果的实现