{"id":297,"date":"2017-06-02T14:02:57","date_gmt":"2017-06-02T14:02:57","guid":{"rendered":"https:\/\/blog.mozilla.org\/webrtc\/?p=297"},"modified":"2018-03-23T19:41:21","modified_gmt":"2018-03-23T19:41:21","slug":"fiddle-of-the-week-audio-constraints","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/","title":{"rendered":"Fiddle-of-the-week: microphone constraints"},"content":{"rendered":"<p>Two new microphone constraints got <a href=\"https:\/\/rawgit.com\/w3c\/mediacapture-main\/master\/getusermedia.html#def-constraint-autoGainControl\">standardized<\/a> last week, available now with <a href=\"https:\/\/github.com\/webrtc\/adapter\">adapter.js<\/a> or Firefox Nightly:<\/p>\n<pre>{ autoGainControl: true, noiseSuppression: false }<\/pre>\n<p>Handy if you&#8217;re a musician or a doctor (or both), since audio in WebRTC, unsurprisingly, is tuned for talking heads by default, not guitar riffs or\u00a0<a href=\"https:\/\/tokbox.com\/blog\/telehealth-can-you-hear-my-heart-now\/\">listening to heartbeats remotely<\/a>.<\/p>\n<p>Basically, Firefox and Chrome have had these since forever with vendor prefixes, but they&#8217;ve remained underappreciated. Maybe hearing the difference will help?<\/p>\n<p>The following shows off other bits of the media capture spec as well. This demo <strong><em>only works in <a href=\"https:\/\/www.mozilla.org\/en-US\/firefox\/\">Firefox<\/a><\/em><\/strong> right now because it uses <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MediaStreamTrack\/applyConstraints\"><code>applyConstraints<\/code><\/a>, which Chrome doesn&#8217;t support just yet.<!--more--><\/p>\n<p><strong>Warning: Put on some headphones before you hit the &#8220;Result&#8221; tab, or it may feedback!<\/strong><\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/jsfiddle.net\/jib1\/n7bmkjnf\/embedded\/js,result,html\/\" allow=\"camera; microphone\" width=\"100%\" height=\"600px\" frameborder=\"0\"><\/iframe><\/p>\n<p>After mic permission is granted, we use <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MediaStreamTrack\/getSettings\"><code>track.getSettings()<\/code><\/a> to make the checkboxes reflect current settings:<\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0 \u2611<\/strong> echoCancellation <strong>\u2611<\/strong> noiseSuppression <strong>\u2610<\/strong> autoGainControl <strong>\u2610<\/strong> mute<\/p>\n<p>The first two will likely be on by default in Firefox. However, like all device settings, defaults can vary from browser to browser<sup>1<\/sup>, device to device, or even the situation, so never rely on them. If you care about a setting, <em>constrain it<\/em>.<\/p>\n<p>The best way to test they&#8217;re working is probably a headset and background noise:<\/p>\n<ul>\n<li>With \u2610 noiseSuppression you should hear background noise noticeably appear.<\/li>\n<li>Then with \u2611 autoGainControl you should hear the background noise amplified a bit.<\/li>\n<li>Finally, with \u2611 noiseSuppression back on: amplification without the noise.<\/li>\n<\/ul>\n<p>Even without audio, you should be able to see the difference, thanks to the wonderfully simple spectrum visualizer originally written by Adam Roach!<\/p>\n<h3>What to set them to<\/h3>\n<p>Historically, the most common use has been to turn off all filtering, on the basis that filters sacrifice fidelity. Especially with stereo, where some implementations may revert to mono when particular filters are used.<\/p>\n<p>But tailor them to what you&#8217;re recording: talking heads vs. music performances, nature sounds (beating hearts), ambient noise, a recording booth. Also consider the sink (local playback, peer connection, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MediaRecorder\">MediaRecorder<\/a>, etc.). E.g. if it will go through <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_Audio_API\">Web Audio<\/a>, you may want the raw signal and do your own filtering.<\/p>\n<p>Next, we&#8217;re working on the <a href=\"https:\/\/bugzil.la\/1213414\">channelCount<\/a> constraint, so you&#8217;ll know when you&#8217;re getting stereo!<\/p>\n<hr \/>\n<p><sub>1) For instance, Chrome <a href=\"http:\/\/stackoverflow.com\/questions\/37326846\/disabling-auto-gain-conctrol-with-webrtc-app\">turns off all audio processing<\/a> in response to <code>echoCancellation<\/code>.<\/sub><\/p>\n","protected":false},"excerpt":{"rendered":"Two new microphone constraints got standardized last week, available now with adapter.js or Firefox Nightly: { autoGainControl: true, noiseSuppression: false } Handy if you&#8217;re a musician or a doctor (or both), since audio in WebRTC, unsurprisingly, is tuned for talking heads by default, not guitar riffs or\u00a0listening to heartbeats remotely. Basically, Firefox and Chrome have [&hellip;]","protected":false},"author":1399,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"coauthors":[301098],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Fiddle-of-the-week: microphone constraints - Advancing WebRTC<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fiddle-of-the-week: microphone constraints - Advancing WebRTC\" \/>\n<meta property=\"og:description\" content=\"Two new microphone constraints got standardized last week, available now with adapter.js or Firefox Nightly: { autoGainControl: true, noiseSuppression: false } Handy if you&#8217;re a musician or a doctor (or both), since audio in WebRTC, unsurprisingly, is tuned for talking heads by default, not guitar riffs or\u00a0listening to heartbeats remotely. Basically, Firefox and Chrome have [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/\" \/>\n<meta property=\"og:site_name\" content=\"Advancing WebRTC\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-02T14:02:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-23T19:41:21+00:00\" \/>\n<meta name=\"author\" content=\"Jan-Ivar Bruaroey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jan-Ivar Bruaroey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/\",\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/\",\"name\":\"Fiddle-of-the-week: microphone constraints - Advancing WebRTC\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#website\"},\"datePublished\":\"2017-06-02T14:02:57+00:00\",\"dateModified\":\"2018-03-23T19:41:21+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/webrtc\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fiddle-of-the-week: microphone constraints\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/\",\"name\":\"Advancing WebRTC\",\"description\":\"Committed to moving Firefox and WebRTC forward\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/webrtc\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd\",\"name\":\"Jan-Ivar Bruaroey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/image\/5f3d49a61b032619d0d33c4cc7c7433f\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g\",\"caption\":\"Jan-Ivar Bruaroey\"},\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/author\/jbruaroeymozilla-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Fiddle-of-the-week: microphone constraints - Advancing WebRTC","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/","og_locale":"en_US","og_type":"article","og_title":"Fiddle-of-the-week: microphone constraints - Advancing WebRTC","og_description":"Two new microphone constraints got standardized last week, available now with adapter.js or Firefox Nightly: { autoGainControl: true, noiseSuppression: false } Handy if you&#8217;re a musician or a doctor (or both), since audio in WebRTC, unsurprisingly, is tuned for talking heads by default, not guitar riffs or\u00a0listening to heartbeats remotely. Basically, Firefox and Chrome have [&hellip;]","og_url":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/","og_site_name":"Advancing WebRTC","article_published_time":"2017-06-02T14:02:57+00:00","article_modified_time":"2018-03-23T19:41:21+00:00","author":"Jan-Ivar Bruaroey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jan-Ivar Bruaroey","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/","url":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/","name":"Fiddle-of-the-week: microphone constraints - Advancing WebRTC","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/#website"},"datePublished":"2017-06-02T14:02:57+00:00","dateModified":"2018-03-23T19:41:21+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-of-the-week-audio-constraints\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/webrtc\/"},{"@type":"ListItem","position":2,"name":"Fiddle-of-the-week: microphone constraints"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/webrtc\/#website","url":"https:\/\/blog.mozilla.org\/webrtc\/","name":"Advancing WebRTC","description":"Committed to moving Firefox and WebRTC forward","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/webrtc\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd","name":"Jan-Ivar Bruaroey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/image\/5f3d49a61b032619d0d33c4cc7c7433f","url":"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g","caption":"Jan-Ivar Bruaroey"},"url":"https:\/\/blog.mozilla.org\/webrtc\/author\/jbruaroeymozilla-com\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts\/297"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/users\/1399"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/comments?post=297"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts\/297\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/media?parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/categories?post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/tags?post=297"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/coauthors?post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}