<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cliff Aw on Medium]]></title>
        <description><![CDATA[Stories by Cliff Aw on Medium]]></description>
        <link>https://medium.com/@cliff.aw?source=rss-244bd6293cbf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*5sjfL67qawmgTpOAg2hUvw.jpeg</url>
            <title>Stories by Cliff Aw on Medium</title>
            <link>https://medium.com/@cliff.aw?source=rss-244bd6293cbf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:53:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cliff.aw/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating immersive product experiences with audio and animated text highlighting in React]]></title>
            <link>https://medium.com/engineered-publicis-sapient/creating-immersive-product-experiences-with-audio-and-animated-text-highlighting-in-react-9a88c9b2acd2?source=rss-244bd6293cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a88c9b2acd2</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Cliff Aw]]></dc:creator>
            <pubDate>Mon, 02 Mar 2020 09:41:57 GMT</pubDate>
            <atom:updated>2020-03-02T09:47:48.445Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFdeU4usaJPVAiEakros8A.png" /></figure><p>E-commerce is a competitive land, one where making your product stand out from the competition is vital. Today’s web technologies offer some interesting methods to tackle this. This article aims to explain and demonstrate how my project team at <a href="https://www.publicissapient.com/">Publicis Sapient</a> utilized technology to deliver powerful customer experiences for <a href="https://www.bang-olufsen.com/en">Bang &amp; Olufsen</a>.</p><figure><img alt="Publicis Sapient and Bang &amp; Olufsen logos" src="https://cdn-images-1.medium.com/max/600/1*edRBxYau983TFhhxyEjezQ.jpeg" /></figure><h4>The task</h4><p>Bang &amp; Olufsen are a Danish designer and manufacturer of high-end audio products and televisions, synonymous with quality and innovation. Our task was to envision, design and build a way for B&amp;O to tell the stories around their products in an entertaining, creative and immersive way.</p><h4>The concept</h4><p>Storytelling is most commonly seen as an audible experience, something that is not regularly found on the web without video. There is, however, the ability to use audio as a medium to connect with a user, adding an extra sensory layer to what usually is only a visual-led experience.</p><p>With this in mind, the creative team presented a concept for, what we liked to call, “Immersive stories”. These were pages featuring linear flowing content of various forms of contrasting media. This could include audio (the focus of this article), video, interactive WebGL and imagery.</p><p>Here is what the structure of the page would potentially look like:</p><figure><img alt="The article page wireframe showing the component layout" src="https://cdn-images-1.medium.com/max/425/1*zgnQl9g1krZPzADWWmBvag.jpeg" /><figcaption>The article page wire-frame showing the component layout</figcaption></figure><p>Each chapter’s primary component would be an “Audio Narration” section, featuring visual tracking of the story via karaoke-esque text highlighting. Users would be able to control the audio (play/pause), skip between chapters and restart when finished. The chapters would then also have a “snap-to” functionality whilst scrolling, so a user wouldn’t miss content, only when scrolling down.</p><p>Here you can see the design concept:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DaJ4tWmyRZkE&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FaJ4tWmyRZkE&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/faa652786dc6fc2da91b8671d08c35df/href">https://medium.com/media/faa652786dc6fc2da91b8671d08c35df/href</a></iframe><h4>The solution</h4><p>From this concept, we had many ideas that needed to be tested in order to gauge viability. Things to investigate focused around technical limitations from our tech stack, browsers/devices being supported, sourcing and displaying content, and performance and accessibility.</p><p>The following outlines the tech stack (not in its entirety, just connected to this feature):</p><ol><li><a href="https://nextjs.org/">Next.js</a> / <a href="https://reactjs.org/">React</a></li><li><a href="https://react-redux.js.org/">Redux</a></li><li><a href="https://www.contentful.com/">Contentful</a> (a headless <a href="https://en.wikipedia.org/wiki/Content_management_system">CMS</a>)</li><li><a href="https://www.styled-components.com/">Styled-Components</a></li></ol><p>Below is the browser and device matrix this feature had to support:</p><ol><li>Chrome, Firefox, Safari, Edge and IE11</li><li>Mobile, tablet and desktop</li></ol><h3><strong>Time to experiment</strong></h3><p>Breaking things down, there were four main aspects I needed to validate:</p><p><strong>1. Where is the text that will be displayed on the page going to come from?</strong></p><p>Content posed a big challenge. I knew that there would be an audio recording, featuring an individual being interviewed about specific parts of the products creation or features, supplied in MP3 format, and stored in our CMS, <a href="https://www.contentful.com/">Contentful</a>. The challenge, however, was converting that audio into text, as we wanted to not only play the audio, but also have the content displayed and highlighted in sync with it.</p><p>After having a very (very) long look into audio transcription solutions, most fell short of requirements. Most of these were offline Windows desktop applications, which posed compatibility issues. The online tools mostly utilized Artificial Intelligence for the audio processing, which resulted in high costs.</p><p>Eventually, I came across a platform called <a href="https://sonix.ai/">Sonix</a>, an online tool that still utilized <a href="https://en.wikipedia.org/wiki/Artificial_intelligence">AI</a>, had very competitive pricing, a wide range of language support, and an impressive web-based transcription editing feature.</p><p><strong>2. How are we going to highlight the text?</strong></p><p>A key requirement of the feature was to have some form of visual highlighting of text as the audio would be playing in the background. This would allow a user to follow along with the current chapter’s narration.</p><p>I knew the answer here would have to be <a href="https://en.wikipedia.org/wiki/Cascading_Style_Sheets">CSS</a> based, purely from wanting to keep things light, compatible and requiring as little <a href="https://en.wikipedia.org/wiki/Document_Object_Model">DOM</a> manipulation as possible. I eventually came across an interesting <a href="https://codepen.io/ariona/pen/LEEadb">solution on CodePen</a> using a pure CSS solution that was simple to apply. It works using a mixture of animation <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/animation-duration">duration</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/animation-delay">delay</a>, with each following sentence having a total delay of all previous.</p><p>The code snippet below gives an idea of how the animation works, but also shows there is a catch.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FCliffAw%2Fembed%2Fpreview%2FarQMQb%3Fheight%3D600%26slug-hash%3DarQMQb%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2FCliffAw%2Fpen%2FarQMQb&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2922009.arQMQb.small.286fb784-6bff-4e7f-9747-1269d99077f1.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c8f40df13b6076b82b0bcc629494780/href">https://medium.com/media/8c8f40df13b6076b82b0bcc629494780/href</a></iframe><p>The catch is that this approach relies on the background-size CSS property, which whilst controllable, there is an impact to performance. This comes because animating the background-size property will trigger a <a href="https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction">browser paint</a>, which inherently repaints all child layers. Luckily, here we are not dealing with many layers, so performance was consistently ~60fps when testing.</p><p>This method also meant that the styling (shown in the above concept) had to be rethought, as the desired effect was not possible with this approach.</p><p><strong>3. How can this be built in a content author-friendly way?</strong></p><p>My original plan for this feature was that a user would create a <a href="https://en.wikipedia.org/wiki/JSON">JSON</a> file containing data through a tool/application, such as Sonix, which could then be uploaded to the CMS and processed. Ultimately, however, mostly due to difficulties around file handling, this wasn’t achieved.</p><p>The final solution, whilst more manual, was still relatively straightforward:</p><ol><li>User uploads audio file to Sonix</li><li>Sonix transcribes the uploaded audio file</li><li>User makes edits to the transcription as required</li><li>User downloads transcription file in <a href="https://en.wikipedia.org/wiki/SubRip">SRT</a> format</li><li>User copies contents of transcription file, pastes into CMS text field</li></ol><figure><img alt="The user flow of the Sonix transcription process" src="https://cdn-images-1.medium.com/max/311/1*MZx9sBGg-xtaH5JyLwndtg.png" /><figcaption>The user flow of the Sonix transcription process</figcaption></figure><p>There are five steps to complete the process, which in real time takes around 12–15 minutes, including the Sonix transcribing time. Also, with the content author only needing to copy and paste the file contents into the CMS, the likelihood of erroneous data being added is reduced (but not completely protected against).</p><figure><img alt="The Sonix transciption editor interface" src="https://cdn-images-1.medium.com/max/1024/1*dpeu2z6is1scMtl-rXMPBw.jpeg" /><figcaption>The Sonix transcription editor interface</figcaption></figure><p><strong>4. How are we going to make sure the highlighted text remains in sync with the audio?</strong></p><p>Given the nature of this feature, having the text highlight and audio maintain a level of synchronization within margins, was of fairly high importance.</p><p>It was requested that this timing would be on a per sentence basis, as opposed to per word, giving a degree of buffer for the highlight word vs spoken word accuracy. Sonix does this by default, unlike most of its competitors.</p><p>One downside of Sonix, however, comes from the formats you can export the transcribed content in (at the time of developing). Ideally, JSON would have been available, but ultimately the best option I could find was <a href="https://en.wikipedia.org/wiki/SubRip">SubRip</a>. Below is an example of what to expect within such a file:</p><pre>1<br>00:00:00,620 → 00:00:07,310<br>When we first decided to make a new statement loudspeaker from Bang &amp; Olufsen, the question wasn’t, “What are we going to build?”.</pre><pre>2<br>00:00:07,700 → 00:00:12,590<br>The question was, “What do we want it to sound like when you’re sitting and listening to music?”.</pre><pre>3<br>00:00:14,020 → 00:00:17,720<br>And in order to answer that question we had to go out and listen to loudspeakers.</pre><p>As mentioned above, my preference was JSON. So using this content, I created a script which would parse and create it. The challenge this created was to then find out where best this should happen in the wider content authoring process, and/or if this introduced any limitations.</p><p>It did. The first being that the parsing couldn’t be handled in the CMS or <a href="https://en.wikipedia.org/wiki/Application_programming_interface">API</a>, meaning it would have to be client side. This had a performance impact, plus required thought around initial rendering of the component. The second was that it meant a content author would have to interact with the SubRip file content to author the chapters.</p><p>SubRip converted to JSON:</p><pre>[<br>    {<br>        “content”: “When we first decided to make a new statement                    loudspeaker from Bang &amp; Olufsen, the question wasn’t, \”What are we going to build?\”.”,<br>        “id”: “1”,<br>        “delay”: 620,<br>        “start”: 620,<br>        “duration”: 6690,<br>        “end”: 7310<br>    },<br>    {...}<br>]</pre><p>There were a few custom properties created from the data in the SubRip file including delay, start and end time, plus the duration.</p><h3>Putting this into React</h3><p>With a solution for the initial “heavy lifting” of this feature, the next step was to consume this data within our React application.</p><h4>Component Structure</h4><p>The structure that was eventually employed maintains a traditional one-to-many philosophy, without restriction on how many sentences a user could have within a narration chapter. This was due to not wanting to limit any amount of audio time that could be used.</p><p>The example below shows visually the structure of the component, called Narration, in situ on a template:</p><figure><img alt="An example of the audio narration component structure when used on a template" src="https://cdn-images-1.medium.com/max/238/1*7HL2ZdyKkJMeGWz3LR2g8g.png" /><figcaption>An example of the audio narration component structure when used on a template</figcaption></figure><p>As shown, the component is self-encompassing, making it reusable throughout the application wherever required and isolating any logic. This made it easier to test and allowed the child components to only handle what they need to.</p><h4>The Logic</h4><p>Narration is the place where you find the glue that holds everything together, acting as a central convening point for handling click events on the AudioPlayer component. These events are used to trigger functions within the NarrationParagraph via <a href="https://reactjs.org/docs/refs-and-the-dom.html">React Refs</a>, which handle the start, pause or reset of the narration highlight animation for each NarrationSentence.</p><p><strong>Narration</strong></p><p>Below is the Narration component, an organism when following the <a href="http://bradfrost.com/blog/post/atomic-web-design/">atomic</a> principles. Here are all the functions triggered via events, using component state to then managing what is the current status of the component.</p><p>handlePlayClick() handles the audio player <em>play</em> button, but within this we need to know at what state we were when the button is clicked in order to handle the <em>play/resume</em>, <em>pause</em> and <em>reset</em>. This makes things slightly more complex compared to the other controls:</p><pre>handlePlayClick = () =&gt; {<br>  const { hasPlayed, isPlaying, hasEnded } = this.state;</pre><pre>  // If not currently playing, has not played ever and has not ended, play the audio from start.<br>  if (!isPlaying &amp;&amp; !hasPlayed &amp;&amp; !hasEnded) {<br>    this.setState(<br>      {<br>        hasPlayed: true          <br>        isPlaying: true<br>      },<br>      this.narrationParagraphRef.current.startNarration()<br>    );<br>  }</pre><pre>  // If not currently playing and has not ended, but has played, resume the audio.<br>  if (!isPlaying &amp;&amp; hasPlayed &amp;&amp; !hasEnded) {<br>    this.setState(<br>      {<br>        isPlaying: true<br>      },<br>      this.narrationParagraphRef.current.resumeNarration()<br>    );<br>  }</pre><pre>  // If playback has finished, replay the audio and reset values.<br>  if (hasEnded) {<br>    this.setState(<br>      {<br>        hasEnded: false<br>      },<br>      this.narrationParagraphRef.current.resetNarration()<br>    );<br>  }<br>};</pre><p>handlePauseClick() is called with any press of the audio players <em>pause </em>button, which can only be done after pressing <em>play</em> at least once.</p><p>handleEnded() is called only when the audio track finishes playback and the <em>play</em> button is pressed. This acts as a <em>reset</em> for the component to start over.</p><p>The Narration component can be seen <a href="https://codesandbox.io/s/audio-narration-nudnd?module=/src/components/Organisms/Narration/index.tsx">here</a>.</p><p><strong>NarrationParagraph</strong></p><p>NarrationParagraph is where we have the overall control over the CSS animated highlight status, triggered by the function call in the Narration component (above). Here we use the status to apply a classname to the paragraph wrapper which cascades down to all child NarrationSentence components and changes the CSS animation-play-state to either playing or paused. This means all react at the same time, rather than having to trigger or change state of each programmatically.</p><pre>const narrationClass = classnames(&quot;m-narration&quot;, {<br>  &quot;-ready&quot;: !hasPlayed,<br>  &quot;-playing&quot;: hasPlayed,<br>  &quot;-paused&quot;: isPaused<br>});</pre><pre>return (<br>  &lt;div className={narrationClass}&gt;<br>    {data &amp;&amp; (<br>      &lt;p&gt;<br>        {data.map(sentence =&gt; (<br>          &lt;NarrationSentence<br>            data={sentence}<br>            resetState={resetState}<br>            key={sentence.id}<br>          /&gt;<br>        ))}<br>      &lt;/p&gt;<br>    )}<br>  &lt;/div&gt;<br>);</pre><p>The NarrationParagraph component can be seen <a href="https://codesandbox.io/s/audio-narration-nudnd?module=/src/components/Molecules/NarrationParagraph/index.tsx">here</a>.</p><p><strong>AudioPlayer</strong></p><p>The AudioPlayer is the component which offers the user an interaction point that will kick off the <em>“play”</em>, <em>“pause”</em> or <em>“reset”</em> states. Using the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#Events">available browser audio player events</a>, we can call the functions passed down as props from, and held within, the Narration component.</p><p>The AudioPlayer component can be seen <a href="https://codesandbox.io/s/audio-narration-nudnd?module=/src/components/Atoms/AudioPlayer/index.tsx">here</a>.</p><p><strong>NarrationSentence</strong></p><p>NarrationSentence is where we render the text. Each sentence maintains its own state to track whether it has either been read or reset, setting appropriate styles to the sentence. The isRead flag is updated as a result of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onanimationend">onAnimationEnd</a> event, made possible as a result of using CSS animations. This removes any CSS animation and swaps it for a background-color, as by this point the sentence would have been completely highlighted. The isReset flag is where the animation reverts back to its initial point, done from reapplying the animation.</p><pre>const highlightStyles = {<br>  animationDuration: `${duration}ms`,<br>  animationDelay: `${delay}ms`<br>};</pre><pre>const sentenceClassname = classnames(&quot;a-narrationSentence&quot;, {<br>  &quot;-isRead&quot;: isRead,<br>  &quot;-isReset&quot;: isRead &amp;&amp; isReset<br>});</pre><pre>if (content) {<br>  return (<br>    &lt;span<br>      className={sentenceClassname}<br>      style={highlightStyles}<br>      onAnimationEnd={() =&gt; this.onAnimationEnd()}<br>    &gt;<br>      {content}<br>    &lt;/span&gt;<br>  );<br>}</pre><pre>return null;</pre><p>The NarrationSentence component can be seen <a href="https://codesandbox.io/s/audio-narration-nudnd?module=/src/components/Atoms/NarrationSentence/index.tsx">here</a>.</p><h3>Example</h3><p>And finally, below is a CodeSandbox showing the entirety of what has been described above, exclusive of any styles. I have also left some logs in place to help track where things are triggering and to give some feedback to events.</p><p>Feel free to fork and customize it to your own needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*edSQSMkB0TNuhAU7bmce2A.png" /></figure><h3>Outcomes and learnings</h3><ol><li><a href="https://en.wikipedia.org/wiki/Proof_of_concept">POC</a>s are your friend and getting the appropriate time to do them is vital for efficient development. Having a team that understands this goes a very long way.</li><li>Scale your approach, starting with an MVP solution, but always keep in mind what you’d want to add. Don’t let MVP mean you don’t deliver the basics.</li><li>Know your target, including user, author, devices, browsers, etc. This naturally helps plan and also test.</li><li>Do things in the right places. If you have the option, explore not only the solution in the frontend, but also the entire stack. Is something being done in the right place, or can moving it somewhere else in the process improve things?</li></ol><h3>See it live</h3><ol><li><a href="https://www.bang-olufsen.com/en/story/beolab-90">A Vision of Sound</a></li><li><a href="https://www.bang-olufsen.com/en/story/the-shape-of-sound">The Shape of Sound</a></li><li><a href="https://www.bang-olufsen.com/en/story/story-of-shape">Finding Shapes</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a88c9b2acd2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/engineered-publicis-sapient/creating-immersive-product-experiences-with-audio-and-animated-text-highlighting-in-react-9a88c9b2acd2">Creating immersive product experiences with audio and animated text highlighting in React</a> was originally published in <a href="https://medium.com/engineered-publicis-sapient">Engineered @ Publicis Sapient</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>