building

Building practices for the future

Sacred Groves in Auroville is being built using ecologically sensitive construction methods and material.




building

How green is my building

In the wake of the conference on building sustainability, architect Minni Sastry of TERI speaks to RANJANI GOVIND on the emerging thoughts relevant to the industry




building

Building digital trust with quantum tech

QNu Labs devises qubit-powered solutions for the ‘trillion-dollar cyber-attack problem’ 




building

‘Focused on building a high-conviction portfolio’

How fund house Cactus Partners ensures its capital goes toward growth rather than just keeping operations running




building

Building up an Arsenal

The autobiography of a coach who revolutionised English football




building

Building digital platforms

A book on digital players in the post-pandemic world




building

Building your personal brand

Your brand is also about how the world perceives you




building

T.N. CM Stalin inaugurates new buildings for rural local bodies




building

Building a Dictaphone Using Media Recorder and getUserMedia

Chris Mills brushes up his shorthand and shows how the MediaStream Recording API in modern browsers can be used to capture audio directly from the user’s device. Inching ever closer to the capabilities of native software, it truly is an exciting time to be a web developer.


The MediaStream Recording API makes it easy to record audio and/or video streams. When used with MediaDevices.getUserMedia(), it provides an easy way to record media from the user’s input devices and instantly use the result in web apps. This article shows how to use these technologies to create a fun dictaphone app.

A sample application: Web Dictaphone

To demonstrate basic usage of the MediaRecorder API, we have built a web-based dictaphone. It allows you to record snippets of audio and then play them back. It even gives you a visualisation of your device’s sound input, using the Web Audio API. We’ll just concentrate on the recording and playback functionality in this article, for brevity’s sake.

You can see this demo running live, or grab the source code on GitHub. This has pretty good support on modern desktop browsers, but pretty patchy support on mobile browsers currently.

Basic app setup

To grab the media stream we want to capture, we use getUserMedia(). We then use the MediaRecorder API to record the stream, and output each recorded snippet into the source of a generated <audio> element so it can be played back.

We’ll first declare some variables for the record and stop buttons, and the <article> that will contain the generated audio players:

const record = document.querySelector('.record');
const stop = document.querySelector('.stop');
const soundClips = document.querySelector('.sound-clips');

Next, we set up the basic getUserMedia structure:

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
   console.log('getUserMedia supported.');
   navigator.mediaDevices.getUserMedia (
      // constraints - only audio needed for this app
      {
         audio: true
      })

      // Success callback
      .then(function(stream) {

      })

      // Error callback
      .catch(function(err) {
         console.log('The following `getUserMedia` error occured: ' + err);
      }
   );
} else {
   console.log('getUserMedia not supported on your browser!');
}

The whole thing is wrapped in a test that checks whether getUserMedia is supported before running anything else. Next, we call getUserMedia() and inside it define:

  • The constraints: Only audio is to be captured for our dictaphone.
  • The success callback: This code is run once the getUserMedia call has been completed successfully.
  • The error/failure callback: The code is run if the getUserMedia call fails for whatever reason.

Note: All of the code below is found inside the getUserMedia success callback in the finished version.

Capturing the media stream

Once getUserMedia has created a media stream successfully, you create a new Media Recorder instance with the MediaRecorder() constructor and pass it the stream directly. This is your entry point into using the MediaRecorder API — the stream is now ready to be captured into a <Blob>, in the default encoding format of your browser.

const mediaRecorder = new MediaRecorder(stream);

There are a series of methods available in the MediaRecorder interface that allow you to control recording of the media stream; in Web Dictaphone we just make use of two, and listen to some events. First of all, MediaRecorder.start() is used to start recording the stream once the record button is pressed:

record.onclick = function() {
  mediaRecorder.start();
  console.log(mediaRecorder.state);
  console.log("recorder started");
  record.style.background = "red";
  record.style.color = "black";
}

When the MediaRecorder is recording, the MediaRecorder.state property will return a value of “recording”.

As recording progresses, we need to collect the audio data. We register an event handler to do this using mediaRecorder.ondataavailable:

let chunks = [];

mediaRecorder.ondataavailable = function(e) {
  chunks.push(e.data);
}

Last, we use the MediaRecorder.stop() method to stop the recording when the stop button is pressed, and finalize the Blob ready for use somewhere else in our application.

stop.onclick = function() {
  mediaRecorder.stop();
  console.log(mediaRecorder.state);
  console.log("recorder stopped");
  record.style.background = "";
  record.style.color = "";
}

Note that the recording may also stop naturally if the media stream ends (e.g. if you were grabbing a song track and the track ended, or the user stopped sharing their microphone).

Grabbing and using the blob

When recording has stopped, the state property returns a value of “inactive”, and a stop event is fired. We register an event handler for this using mediaRecorder.onstop, and construct our blob there from all the chunks we have received:

mediaRecorder.onstop = function(e) {
  console.log("recorder stopped");

  const clipName = prompt('Enter a name for your sound clip');

  const clipContainer = document.createElement('article');
  const clipLabel = document.createElement('p');
  const audio = document.createElement('audio');
  const deleteButton = document.createElement('button');

  clipContainer.classList.add('clip');
  audio.setAttribute('controls', '');
  deleteButton.innerHTML = "Delete";
  clipLabel.innerHTML = clipName;

  clipContainer.appendChild(audio);
  clipContainer.appendChild(clipLabel);
  clipContainer.appendChild(deleteButton);
  soundClips.appendChild(clipContainer);

  const blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
  chunks = [];
  const audioURL = window.URL.createObjectURL(blob);
  audio.src = audioURL;

  deleteButton.onclick = function(e) {
    let evtTgt = e.target;
    evtTgt.parentNode.parentNode.removeChild(evtTgt.parentNode);
  }
}

Let’s go through the above code and look at what’s happening.

First, we display a prompt asking the user to name their clip.

Next, we create an HTML structure like the following, inserting it into our clip container, which is an <article> element.

<article class="clip">
  <audio controls></audio>
  <p>_your clip name_</p>
  <button>Delete</button>
</article>

After that, we create a combined Blob out of the recorded audio chunks, and create an object URL pointing to it, using window.URL.createObjectURL(blob). We then set the value of the <audio> element’s src attribute to the object URL, so that when the play button is pressed on the audio player, it will play the Blob.

Finally, we set an onclick handler on the delete button to be a function that deletes the whole clip HTML structure.

So that’s basically it — we have a rough and ready dictaphone. Have fun recording those Christmas jingles! As a reminder, you can find the source code, and see it running live, on the MDN GitHub.


This article is based on Using the MediaStream Recording API by Mozilla Contributors, and is licensed under CC-BY-SA 2.5.


About the author

Chris Mills manages the MDN web docs writers’ team at Mozilla, which involves spreadsheets, meetings, writing docs and demos about open web technologies, and occasional tech talks at conferences and universities. He used to work for Opera and W3C, and enjoys playing heavy metal drums and drinking good beer.

More articles by Chris




building

Building a ‘perfect meal’

Is it possible to have that balanced meal with the right amount of protein, starch and veggies? Read on and find out.




building

Reflections on Practice : Relationship Building / directed by: Nettie Wild ; production agencies: National Film Board of Canada (Montreal), British Columbia Centre for Disease Control. Street Nurse Program (Vancouver)

Montreal : National Film Board of Canada, 2019




building

Naidu sets June deadline for completion of new terminal building at Vijayawada airport

Chief Minister suggests changes in the design of the expansion works to reflect Andhra Pradesh’s culture and heritage




building

Storm building in the Bay of Bengal?

Most forecasting agencies indicate the possibility of a storm building in the Southwest Bay of Bengal, just ahead of the onset of Southwest monsoon in these parts. What it holds for onset dynamics over mainland India has crucial signifcance for onward progress of seasonal rains.




building

Interarch Building Products plans to double turnover to ₹2,500 cr by 2028

The company, which got listed recently, clocked a turnover of ₹1,293 crore in FY24




building

The building and breaching of Fortress India: chronicling a cycle of cricket dominance

India was invincible at home for 12 years, winning 18 consecutive Test series before New Zealand snapped the record streak in a historic clean sweep. What went into the making of the unbeaten run, what are the consequences of defeat and what does the future look like?




building

Gujarat HC asks why illegal building in Rajkot game zone was not demolished for a year

‘Demolition order proves that officials knew the structure was illegal,’ the Chief Justice said




building

Visva-Bharati teaches young volunteers how to preserve old buildings

Visva-Bharati is concluding a two-week workshop called Heritage Awareness Camp




building

India building up gold reserves, says Das

Per official data, the value of gold in the forex reserves stood at $51.487 billion as on March 22, which is $6.287 billion higher than the value as at end-March 2023




building

RBI steadily building up gold reserves

The RBI held about 60 per cent of its gold reserves in safe custody in India as at September-end 2024 against about 50 per cent as at March-end 2024




building

Building mental reserves

Treat mental health like an “account” with regular deposits of nurturing habits, thoughts, and actions




building

‘The question of building stakeholder trust can have more airtime in the boardroom’




building

Newer building blocks of organisational culture 

O.C. Tanner’s latest report lists out the increasing responsibilities of corporate leaders in building a positive and productive workplace




building

Building your space brick by brick

The writer on why the humble brick scores over the much-cheaper block masonry




building

HC directs officials to inspect GRH building




building

CM Stalin inaugurates 13 school buildings in Tenkasi district




building

Grievances redressal meeting to be held at new Collectorate building in Virudhunagar on Monday




building

HC directs authorities to file status report on decision taken to demolish dilapidated library building and construct new one

A PIL petition complains about the dilapidated condition of the building and seeks a direction to authorities to construct a new one in its place.




building

New panchayat union buildings inaugurated at Thoothukudi and Kanniyakumari




building

Building Pune: Elevated e-way from Pune to Sambhajinagar to expedite travel by 2 hrs




building

A building rich in history

Kolkata’s Town Hall, where the swadeshi movement formally began and which had a strong association with the Indian nationalist movement, will be opened to public soon



  • History &amp; Culture

building

How Buildings Learn


Anyone interested in architecture should read this book by Stewart Brand. Brand won a National Book Award for the Whole Earth Catalog, and is a co-founder of Global Business Network, a futurist research organization fostering "the art of the long view." How Buildings Learn features a lot of illustrations and insights about building and buildings. I especially enjoy the comparison of two structures on the campus of MIT:

The legendary Building 20 (1943) was an artifact of wartime haste. Designed in an afternoon by MIT grad Don Whiston, it was ready for occupancy by radar researchers six months later... In an undertaking similar in scope to the Manhattan Project that created the atomic bomb, the emergency development of radar employed the nation's best physicists in an intense collaboration that changed the nature of science. Unlike Los Alamos, the MIT radar project was not run by the military, and unlike Los Alamos, no secrets got out. The verdict of scientists afterward was, "The atom bomb only ended the war. Radar won it." ... Author Fred Hapgood wrote in 1993 of Building 20, "The edifice is so ugly that it is impossible not to admire it, if that makes sense; it has ten times the righteous nerdly swagger of any other building on campus... Although Building 20 was built with the intention to tear it down after... World War II, it has remained... providing a special function... Not assigned to any one school, department, or center, it seems to always have had space for the beginning project, the graduate student's experiment, the interdisciplinary research center.

In a later chapter, Brand describes famous architect I.M. Pei's third MIT building, known informally as the Media Lab and formally as the Wiesner Building:

It may have been my familiarity with MIT's homely, accommodating Building 20 just across the street that made the $45 million pretentiousness, ill-functionality, and non-adaptability of the Media Lab building so shocking to me... Nowhere in the whole building is there a place for casual meetings, except for a tiny, overused kitchen. Corridors are narrow and barren. Getting new cabling through the interior concrete walls - a necessity in such a laboratory - requires bringing in jackhammers. You can't even move office walls around, thanks to the overhead fluorescent lights being at a Pei-signature 45-degree angle to everything else.

The Media Lab building, I discovered, is not unusually bad. Its badness is the norm in new buildings overdesigned by architects...


Brand finishes How Buildings Learn with a list of good books, writing, "They are the texts I would reach for if I was going to work on a building..."





building

EPA awards City of Rockford $275,000 to clean up former Rockford Watch Factory, Lloyds Hearing Building

For Immediate Release No. 20-OPA-042




building

Building beautiful little keycap watercolor vibrobots

My friend Steve Davee posted this fun project to Instructables. It's a perfect project for shut-in parents and kids to do together.

The main body parts of the bots are keyboard keycaps and Q-tips/cotton swabs. An eccentric weight (pager) motor provides the bouncy movement that makes your vibrobots go.

Dip the swabs in watercolor paints, place the little critter on some paper, and watch your little tabletop Jackson Pollockbot go to town.

Image: YouTube Read the rest




building

Building an Integration System: Policies to Support Immigrants’ Progression in the Czech Labor Market

This report presents an overview of Czech integration policies, with a special focus on economic integration. It focuses on policies designed to support migrants’ incorporation in the Czech labor market, and assesses the extent to which these policies facilitate migrants’ upward mobility into more skilled work.




building

Securing the Border: Building on the Progress Made

Testimony of Doris Meissner, Director of MPI's U.S. Immigration Policy Program, before the Senate Homeland Security and Governmental Affairs Committee.




building

New students in a new building

The OM Russia Discipleship Centre opens its doors to 13 new students in September and opens a second OM building on the site.




building

Rebuilding lives in a new city

OM Russia partners with local churches to respond to the needs of Ukrainian refugees in Novosibirsk, Siberia.




building

Building more than muscles

“I have always wanted to do more than coach specific sport skills,” Joseph said. “This approach touches all areas of fitness: physical, emotional and spiritual–all aspects of a human being.”




building

Building on

From doing their lessons on the ground to learning at desks in classrooms, the students at Makwati Community School have come a long way.




building

Building a bridge to reconciliation

Teens attending TeenStreet Europe in July will raise money for a project to bring reconciliation to the ethnically divided youth of Mostar, Bosnia and Herzegovina.




building

One on One: Building Loyalty On Mobile With Jack Philbin, CEO, Vibes

What's up with Apple Wallet?




building

One on One: Building Loyalty On Mobile With Jack Philbin, CEO, Vibes

What's up with Apple Wallet?




building

Building a resilient India: COVID-19 crisis is an opportunity to redefine tax policy and law

The Covid 19 crisis is an opportunity to redefine tax policy and law. A calibrated approach to balance welfare economics with a vision to pioneer economic activity and national growth is needed.




building

A building used largely as offices cannot be a ‘house’

A building that was built 150 years ago as a house, but that has been used predominantly as offices for the past 60 years, is not a 'house' for the purpose of the Leasehold Reform Act 1967. The Court of Appeal in Grosvenor Estates Ltd v Prospect Es...




building

Building a Leader: The Right Results (Peter)

The twelve apostles included "Simon, who is called Peter" (Matt. 10:2).

God knows how to get results.

God makes leaders by taking people with the right raw material, putting them through the right experiences, and teaching them the right lessons. That's how he trained Peter, and the results were astonishing. In the first twelve chapters of Acts we see Peter initiating the move to replace Judas with Matthias, preaching powerfully on the Day of Pentecost, healing a lame man, standing up to the Jewish authorities, confronting Ananias and Sapphira, dealing with Simon the magician, healing Aeneas, raising Dorcas from the dead, and taking the gospel to the Gentiles. In addition, he wrote two epistles that pass on to us all the lessons he learned from Jesus. What a leader!

Peter was as much a model of spiritual leadership in death as he was in life. Jesus told him he would be crucified for God's glory, and early church tradition tells us that Peter was in fact crucified. But before putting him to death, his executioners forced him to watch the crucifixion of his wife. As he stood at the foot of her cross, he encouraged her by saying over and over, "Remember the Lord, remember the Lord." When it was time for his own crucifixion, he requested that he be crucified upside down because he felt unworthy to die as his Lord had died. His request was granted.

Just as God transformed Peter from a brash and impulsive fisherman into a powerful instrument for His glory, so He can transform everyone who is yielded to Him.

You will never be an apostle, but you can have the same depth of character and know the same joy of serving Christ that Peter knew. There's no higher calling in the world than to be an instrument of God's grace. Peter was faithful to that calling—you be faithful too!

Suggestions for Prayer

  • Praise God for the assurance that He will perfect the work He has begun in you (Phil. 1:6).
  • Ask Him to use the experiences you have today as instruments that shape you more into the image of Christ.

For Further Study

Read John 21:18-23.

  • How did Jesus describe Peter's death?
  • What was Peter's reaction to Christ's announcement?
  • What misunderstanding was generated by their conversation?



From Drawing Near by John MacArthur Copyright © 1993. Used by permission of Crossway Books, a division of Good News Publishers, Wheaton, IL 60187, www.crossway.com.

Additional Resources




building

Biden Campaign Is Secretly Building a Republican Group

Saul Loeb/AFP/Getty

Appearing in an Instagram live chat with soccer star Megan Rapinoe on April 30, presumptive Democratic nominee Joe Biden made a spontaneous, vague statement about how he’s been “speaking to a lot of Republicans,” including “former colleagues, who are calling and saying Joe, if you win, we’re gonna help.”

Then he showed his hand: “Matter of fact, there’s some major Republicans who are already forming ‘Republicans for Biden,’” the former vice president said. “Major officeholders.”

The comment hardly received any attention at the time. But in declaring it, Biden ended up tipping off the earliest stages of a brewing effort that’s starting to get underway in certain Republican circles behind-the-scenes. 

Read more at The Daily Beast.




building

Darrell Issa Appears to Flee to Building Roof to Avoid Protesters

Rep. Darrell Issa (R-Calif.) was seen taking refuge on the roof of his office building in Vista, California, Tuesday, taking photos of angry constituents who had gathered below to protest the congressman's voting record. The incident comes before a much-anticipated town hall meeting this Saturday at San Juan Hills High School, where the nine-term congressman is expected to face a hostile crowd because of his support for various Trump administration policies, including the Republican plan to repeal and replace Obamacare.

Democrat Mike Levin, an environmental lawyer who recently announced his bid to challenge Issa in 2018, shared an image of the congressman appearing to avoid demonstrators on social media, where it was roundly mocked.

Others saw his retreating to a rooftop as reminiscent of Michael Scott, Steve Carrell's character in The Office who memorably took to the roof in the episode titled "Safety Training."

Issa, on the other hand, described his trip to the roof a bit differently. Shortly after the criticism, he took to Twitter to offer this narrative. We recommend zooming in to take a closer look at the signs:

For more on Levin and the fight to defeat Issa, the richest man in Congress, head to our profile here.




building

Statistical Model Building for Large, Complex Data: Five New Directions in SAS/STAT Software

This paper provides a high-level tour of five modern approaches to model building that are available in recent releases of SAS/STAT.




building

The Shipbuilding Industry in Turkey

This report on the shipbuilding industry in Turkey is one of a series studies covering various OECD countries and non-OECD economies, and has been prepared to inform OECD’s Council Working Party on Shipbuilding (WP6) on the status and future prospects of that industry.