{"id":308,"date":"2017-09-01T13:47:40","date_gmt":"2017-09-01T13:47:40","guid":{"rendered":"https:\/\/blog.mozilla.org\/webrtc\/?p=308"},"modified":"2018-03-23T19:21:51","modified_gmt":"2018-03-23T19:21:51","slug":"channelcount-microphone-constraint","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/","title":{"rendered":"channelCount constraint for microphone input"},"content":{"rendered":"<p>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MediaTrackConstraints\/channelCount\"><code>channelCount<\/code><\/a> microphone constraint is now available in <a href=\"https:\/\/beta.mozilla.org\/\">Firefox Beta<\/a>. If you want to control the number of channels of audio input from a <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MediaDevices\/getUserMedia\"><code>getUserMedia<\/code><\/a> call, this post is for you.<\/p>\n<p><!--more--><\/p>\n<p>Previously, just one channel (mono sound) was possible. But as of Firefox 55, two channels (stereo sound) is the default. Now, the <code>channelCount<\/code> constraint allows you to control the number of channels that your microphone will deliver.<\/p>\n<p>The constraint can be specified in the initial <code>getUserMedia()<\/code> request, as well as changed later using the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MediaStreamTrack\/applyConstraints\"><code>track.applyConstraints()<\/code><\/a> method. If set, Firefox will try to obtain media closest to the requested value according to the capabilities of the hardware.<\/p>\n<p>A channel count equal to 1 corresponds to mono audio, 2 to stereo, and so forth.<\/p>\n<h4>Working example<\/h4>\n<p>The following example assumes that a stereo capable input device is available &#8211; which is common these days &#8211; and that you&#8217;re using Firefox 56 or newer. Please note that, due to <a href=\"https:\/\/bugzil.la\/1392837\">bug 1392837<\/a>, some microphones (particularly on new mac books) may not work correctly if they are configured to output 4 channels at the OS level.<\/p>\n<p><strong>Warning: Put on headphones or lower volume, or this may feedback<\/strong><\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/jsfiddle.net\/achronop\/2jgob190\/embedded\/js,result,html\/\" allow=\"camera; microphone\" width=\"100%\" height=\"600px\" frameborder=\"0\"><\/iframe><\/p>\n<p>In the example above you can use one of the buttons, on the top, to make the initial <code>getUserMedia<\/code> request. You can chose either default (channel count not specified), mono, stereo or 4 channels. With web audio we split the audio into individual channels to get a visual representation per channel. Pressing mono button you see only one visualizer, corresponding to a single channel. On the other hand, pressing stereo (or default using a stereo capable device) button you see two visualizers. Each one corresponds to a different channel. Now, if you request 4 channels on a stereo device the result will be stereo. This is because 2 channels is the closest to the requested value. Finally, you can demand 4 channels by using the <strong>exact\u00a0<\/strong>keyword. In this case, the request fails and the result is an OverConstraint error.<\/p>\n<p>On the active stream, you can switch between mono and stereo, on the fly, using the radio buttons on the bottom. This is done using <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MediaDevices\/getUserMedia\"><code>applyConstraints<\/code><\/a> and the changes are again reflected visually.<\/p>\n<p>Enjoy &#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"The channelCount microphone constraint is now available in Firefox Beta. If you want to control the number of channels of audio input from a getUserMedia call, this post is for you.","protected":false},"author":1392,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"coauthors":[301099],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>channelCount constraint for microphone input - 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\/channelcount-microphone-constraint\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"channelCount constraint for microphone input - Advancing WebRTC\" \/>\n<meta property=\"og:description\" content=\"The channelCount microphone constraint is now available in Firefox Beta. If you want to control the number of channels of audio input from a getUserMedia call, this post is for you.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/\" \/>\n<meta property=\"og:site_name\" content=\"Advancing WebRTC\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-01T13:47:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-23T19:21:51+00:00\" \/>\n<meta name=\"author\" content=\"achronopoulos@mozilla.com\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"achronopoulos@mozilla.com\" \/>\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\/channelcount-microphone-constraint\/\",\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/\",\"name\":\"channelCount constraint for microphone input - Advancing WebRTC\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#website\"},\"datePublished\":\"2017-09-01T13:47:40+00:00\",\"dateModified\":\"2018-03-23T19:21:51+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/5fa2bc388df8299d2dfb5e8dac60c406\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/webrtc\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"channelCount constraint for microphone input\"}]},{\"@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\/5fa2bc388df8299d2dfb5e8dac60c406\",\"name\":\"achronopoulos@mozilla.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/image\/54a696ca397e1c5d62673fb7f687d492\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cf9db0d25d70cea6f2027acf4e9ae15b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cf9db0d25d70cea6f2027acf4e9ae15b?s=96&d=mm&r=g\",\"caption\":\"achronopoulos@mozilla.com\"},\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/author\/achronopoulosmozilla-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"channelCount constraint for microphone input - 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\/channelcount-microphone-constraint\/","og_locale":"en_US","og_type":"article","og_title":"channelCount constraint for microphone input - Advancing WebRTC","og_description":"The channelCount microphone constraint is now available in Firefox Beta. If you want to control the number of channels of audio input from a getUserMedia call, this post is for you.","og_url":"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/","og_site_name":"Advancing WebRTC","article_published_time":"2017-09-01T13:47:40+00:00","article_modified_time":"2018-03-23T19:21:51+00:00","author":"achronopoulos@mozilla.com","twitter_card":"summary_large_image","twitter_misc":{"Written by":"achronopoulos@mozilla.com","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/","url":"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/","name":"channelCount constraint for microphone input - Advancing WebRTC","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/#website"},"datePublished":"2017-09-01T13:47:40+00:00","dateModified":"2018-03-23T19:21:51+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/5fa2bc388df8299d2dfb5e8dac60c406"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/webrtc\/channelcount-microphone-constraint\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/webrtc\/"},{"@type":"ListItem","position":2,"name":"channelCount constraint for microphone input"}]},{"@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\/5fa2bc388df8299d2dfb5e8dac60c406","name":"achronopoulos@mozilla.com","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/image\/54a696ca397e1c5d62673fb7f687d492","url":"https:\/\/secure.gravatar.com\/avatar\/cf9db0d25d70cea6f2027acf4e9ae15b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf9db0d25d70cea6f2027acf4e9ae15b?s=96&d=mm&r=g","caption":"achronopoulos@mozilla.com"},"url":"https:\/\/blog.mozilla.org\/webrtc\/author\/achronopoulosmozilla-com\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts\/308"}],"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\/1392"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/tags?post=308"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/coauthors?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}