Connected Second-Screen App Experiences with PhoneGap & Audio Watermarks
Join the DZone community and get the full member experience.Join For Free
in january 2012, i started the year with a post on multi-screen applications developed with phonegap . in that post, i describe an approach for creating mobile applications that extend the app experience onto a second screen – where the mobile device drives the content on that second screen… essentially having an “external monitor” capability on a mobile device.
now, i’m going to turn things around… i’ve been experimenting with a few ideas of connected secondary-experience applications, and i figured this would be a great way to come full circle and end 2012. i see the secondary app experience as having huge potential for our connected/media-centric world. the secondary app experience is different in that the application is your “second screen”, perhaps a companion to something else that you are doing. for example, the secondary screen is a mobile application that augments the experience of watching television . perhaps it is a mobile application that augments the experience of playing a video game, along the same concept as xbox smart glass though not tied to a particular platform. the key element is that the mobile application is not only an augmented experience to the television-based content, but that it is also updated in real time as you watch the program, or as you play the game.
in this post i’ll show a proof-of-concept second screen experience where the content of a mobile phonegap application is being driven by an external source (a video) using audio watermarks . in this case, the mobile application is the “second screen”, and your tv is the primary screen. i’d also like to emphasize that this is just a proof of concept – the methods and code in this example are not yet suitable for a production-quality use case for reasons i’ll describe below, but are a great starting point for further exploration.
let’s start with the core concept: a synchronized experience between a content source (tv or other) and a mobile application. since we are talking about tv or media-based content, you can’t rely on being able to create a client-server architecture for synchronization between the media source and the mobile app. this just wouldn’t be possible due to legacy tv hardware, and the fact that there is no way to digitally synchronize the content. however, tvs are great at producing sounds, and it is very possible to use sound-based cues to invoke actions within a mobile application.
now let’s focus on audio watermarks: audio watermarks are markers embedded within an audio signal. they may be either human-imperceptible or within the range of human hearing. in general, humans can hear frequencies between 20hz and 20khz , with that range decreasing with age. while we may not be able to hear the markers, mobile devices are able to detect them. when these markers are “heard” by your device, they can invoke an action within your application.
next, let’s take a look at my proof of concept application. the proof of concept exemplifies a mobile application themed with content from the hbo series game of thrones, synchronized with the opening scene from the tv series. as castles & cities are shown in the video, the content within the mobile applications is updated to show details about each location. in a nutshell:
in the video below, you can see the proof of concept in action. it shows the synchronization between the video and the phonegap-based application, with a brief description from yours truly.
note: i have no association with game of thrones , hbo , george r.r. martin , or the book series “ a song of fire and ice “. i just thought this made a compelling example. i enjoyed both the book series and the show and recommend them. full credit for video and mobile content available.
the application implementation
there are several ways that you can do audio watermarks. the most basic of which is to embed a single tone in the audio stream, and check for the presence of that tone. the first thing that i started exploring was how to identify the dominant frequency of a sound. a quick google search yielded an answer in the first result. this post not only describes how to detect the dominant sound frequency on ios, but also has a downloadable project in github that you can use to get started. no exaggeration, i had this project up and running within minutes. it operates kind of like a guitar tuner… the application detects the dominant frequency of a sound and displays that in the ui.
at a much later time, i also discovered this sample project from apple , which also demonstrates how to detect frequencies from an audio stream (used for the frequency waveform visualization). this will be useful for maturing the concepts shown here.
once i had the sample native ios project up and running, i started exploring inaudible audio “tones” and testing what the devices could accurately detect. i initially started using tones above the 20khz frequency range, so that humans would not be able to hear the watermark. tones in the range of 20-22khz worked great for the iphone, but i quickly realized that the ipad microphone was incapable of detecting these watermarks, so i dropped down to the 18-20khz range, which the ipad was able to pick up without any problems. most adults won’t be able to hear these frequencies, but small children may hear them, and they may drive your pets crazy.
the first thing i did was create “pure” audio tones at specific frequencies using adobe audition . in audition, create a new waveform, then go to the “effects” menu and select “generate tones”. from here, you can create audio tones at any frequency. just specify your frequency and the tone duration, and hit “ok”. i used 3-second tones to make sure that the tone was long enough to be perceived by the device.
i did this for tones in the range of 18-22khz, and saved each in a separate wav file. some of which you can find in the github sample . these files were used for testing, and were embedded in the final video.
to embed the audio watermarks in the video, i fired up adobe premiere and started adding the inaudible tones at specific points in time within the video.
by playing specific tones at specific times, you can synchronize events within your application to those specific tones. this means that you can reliably synchronize in-app content with video content.
let me reiterate… this is only a proof of concept implementation. these watermarks worked great locally, but wouldn’t work in a real-world solution as-is. i also ran into a few major issues when embedding the watermarks – see the “lessons learned” below for details.
the phonegap implementation
the final product
you can view the completed project, the sample tones, and the video containing the embedded tones on github.
this was a really fun experiment, and i definitely learned a lot while doing it. below are just a few of my findings:
dominant frequency watermarks are not the way to go in a real-world solution for many reasons. the main reason being that the watermark has to be the loudest and most predominant frequency in the captured audio spectrum. if there is a lot of other audio content, such as music, sound effects, talking, etc…, then the watermark has to be louder than all of the other content, otherwise it will not be detectable. this alone is problematic. if you are normalizing or compressing your audio stream, this can cause even more problems. a multi-frequency watermark that is within the audible range, but is un-noticeable would be a more reliable solution.
high-frequency watermarks are also problematic. high-pitch frequencies may be beyond the capabilities of hardware devices. speakers may have problems playing these frequencies, or microphones may have problems detecting these frequencies, as i discovered with the ipad. high-pitch frequencies also may have issues when encoding your media. many compression formats/codecs will remove frequencies that are beyond human hearing, thus removing your watermarks. without those watermarks, there can be no synchronization of content.
time-duration or sequential tones
media production and encoding
if you are using audio frequencies that are near the upper-range of human hearing, you have to be careful when you encode your media content. if the “inaudible” sound waveforms are over-amplified and are clipped , it has the potential to cause an extremely unpleasant high frequency noise that you can hear. i strongly recommend that you do not do this – i learned this from experience.
additionally, if you are using high-frequency tones, be careful if you transcode between 16 and 32 bit formats or if you transcode sample rates. transcoding between 16/32 bit depth or between sample rates can cause the inaudible sounds to become audible with very unpleasant artifacts. i found that i had the best results if the sequence settings in premiere, the export format, and the source waveform all had the exact same bit depth (32) and sample rate (41000khz).
from this exploration, some reading, and a lot of trial and error, i think it would be better to have a multi-frequency watermark for a minimum duration. rather than having one specific frequency that dominates the audio sample, the application would detect for elevated levels of specific frequencies for a minimum period of time. this way the watermark frequencies don’t have to overpower any other frequencies, and the watermark frequencies can be within the normal range of human hearing without being noticed. this also gives you the ability to have significantly more watermarks by using combinations of frequencies. since the watermark tones would be within the normal range of human hearing, you also would be better able to rely on common hardware to be able to accurately detect those watermarks.
the main conclusion: not only is it really cool to control your mobile app from an audio source, this can be incredibly powerful for connected experiences. there are already tv shows and apps out in the real world employing the audio-watermarking technique to achieve a synchronized multi-screen experience. my guess is that you will start to see more of these experiences in the not-so-distant future. this is an inexpensive low-fi solution that has potential to work extremely well, and has applications far beyond just the synchronization of an app content with a tv show.
here are just a few ideas where this could be applied:
- tv & movies: connected app and media experiences
- video games: connected “companion” applications to augment the gaming experience
- targeted advertising: imagine you are using an app while in a retail store & you receive advertisements just be being in the store. the watermarks could be embedded within the music playing in the store.
- product placement: imagine that you area watching a movie, and your favorite actor is drinking your favorite soda… you look down at your device, and you also see an advertisement for that same brand of soda.
- museums: imagine you have a mobile app for your favorite museum. while in the museum, there is an audio track describing the exhibits, or just playing background music. when you approach an exhibit, your app shows you details about that exhibit, all triggered by the sound being played within the museum.
the applications of audio watermarking are only limited by our imaginations. this is a low-cost solution that could enable connected experiences pretty much everywhere that you go. the goal of this experiment was to see if these techniques are possible within phonegap apps, and yes, they are.
while phonegap is a multi-platform solution, you may have noticed that this proof of concept is ios only. i’m planning on developing this idea further on ios, and if successful, i’ll considering porting it to other platforms.
Published at DZone with permission of Andrew Trice, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.