search
HomeWeb Front-endH5 TutorialDetailed explanation of web cross-device ultrasonic communication solution based on HTML5

Detailed explanation of web cross-device ultrasonic communication solution based on HTML5:

Foreword: Chirp The iPhone launched the prelude to audio file transfer. We no longer need MMS, Bluetooth pairing, or IM to transfer data. It shares data through the chirping of birds, which is simple and interesting, and can quickly achieve one-to-many sharing.

##        

In addition, Alipay has tried to promote "sound wave payment", using the mobile phone to send ultrasonic waves to the terminal as a transaction password to further complete the transaction. However, Alipay's technology is currently only used for payment, and it requires specific vending machines that can accept sonic payments before it can be used.

" advanced sound for game and interactive apps -webaudio api ##" Web's web with HTML5 with HTML5 Audio API implements an ultrasonic interconnection solution based on Web. In this way, there is no need to install any client, nor does Bluetooth or # With the support of ##NFC, you can connect two devices that use browsers to access the Internet and transfer pictures, music, videos and other files. This idea is cool and helps us take a big step forward in the functionality and application level of Web (Maybe you have this idea. Unthinkable, unheard of), let’s take a look at the specific principles and implementation process. ……………………………………✄……………………………………

Gorgeous separation Line

       

The phone in your pocket is a cool, beautiful tool with many functions. But when it wants to talk to other devices, such as a TV or laptop, the user experience drops significantly.

Bill BuxtonThere is a very infectious speech on this topic, describing the three stages of high-tech evolution:    

1,

Equipment work: functional integrity and stability##       2,

Device smoothness: good user experience##3.

Many devices working together

We have officially entered the

2

stage with the release of iPhone , but connecting devices is a pain. There are many ways to achieve this: Bluetooth, BluetoothLE, WiFi direct, via localWiFi Network discovery and more. This article tackles the problem from a completely unexpected angle: using ultrasound to broadcast and send data between adjacent devices. Most importantly, this approach uses the Web Audio API, making connection with pure Web possible. Demo video

            The Tower of Babel of Equipment

                        ##Airplay   and Chromecast is a great way to solve connectivity issues with devices within the same ecosystem (e.g. Apple or Google) , but common problems are still difficult to solve.

Because there are many possible technical approaches, it may happen that there is no common method among the devices you want to connect to. Even if two devices have Bluetooth, one may need to be configured, but the other does not, or supports a different version of the standard. Now this is especially common with Bluetooth, many devices support Bluetooth 4.0 (aka BTLE) on hardware, but many devices don't This latest protocol is not supported for various reasons. ##          

This situation is even worse on

Web because of the low level device connectionAPIIt is not provided due to security sandbox reasons. And since the development of Web is very slow, it is difficult to imagine that this situation can be solved in a short time.

         

Transmitting data in interesting ways                           Electric Imp The provided

Blinkup

is an interesting way to communicate across terminals. It uses a series of flashes of light to light up a smartphone and the Imp - a device that looks like a small SD card and has a light sensor. transfer data between.       Dial-up modems do something similar. They encode and decode digital data on analog telephone lines. Remember those annoying connection noises? The dial-up modem will turn on the speaker to let the user know that a handshake is taking place. If you forget these, you can review them here. Even in today's analog phones, the sound you hear when you press a number key on a keypad is equivalent to the frequency that the phone system uses for analog-to-digital conversion. This conversion uses Dual Tone Multi-frequency signal (DTMF).

Your phone and many other devices around you have speakers and microphones. Both pieces of hardware can use sound to send and receive data, similar to what a modem does on a phone line. Even better, if the operating system supports sending and receiving at a high enough frequency, we can create a silent data channel.       Transmitting data using sound

##         I should have noticed Encoding data through sound is not new. Audio Watermark

The idea is to encode the signature into the music, which the listener cannot recognize through human means, but can be understood by another device. This is a smart way to prevent piracy.

# Most ordinary speakers can produce the sound of # 44.1khz ## (This leads to the highest frequency of 22KHz - According to Shannon Sampling Theorem). This allows us to encode data not just into sound, but also to produce audio that adults cannot hear. However, children and animals may still hear it :)

##     Technically, it should be noted that microphones are sometimes not compatible with speakers, especially on mobile phones , because they are often optimized for people talking on the phone, using a lower sampling rate to make the sound better. In other cases, even if the hardware is compatible, the firmware needs to run at a lower sampling rate to ensure power supply. If this is the case, the device will not be able to receive sound waves, and sound-based connections will only work in one direction.

SONICNET.JS, an implementation of Web Audio

#      

To illustrate these concepts, I built a JavaScript library for sending and receiving via sound data. My approach does not require learning complicated audio watermarking technology, and it is even simpler than DTMF. Basically, you specify how often a range is used, and the set of letters that can be transmitted. The spectrum is divided into ranges corresponding to the specified start and end letters, with each letter / code corresponding to a portion of the entire frequency range.

       

The sending end converts each character that needs to be sent into the midpoint value of the corresponding frequency range, and sends the frequency within a time interval. The receiving end will perform a discontinuous Fourier transform on the signal (Yu Jie's note: My undergraduate major is information and communication engineering, friends who have studied digital signal processing should know this very well), and look for peaks within the specified frequency range. After finding a peak within a signal interval, it converts the frequency back into characters. This is basically a Single Tone Multi-Frequency Signal (STMF) scheme.

         

There is a question of sending timing: on the sending end, how long should it take to send a character; on the receiving end, how long should it take to receive it? We used a simple scheme to avoid adjacent repeated characters.

       

I designed a API## similar to socket #Used for acoustic communication. The client code looks like this: ##

ssocket = new SonicSocket({alphabet: '0123456789'});
function onButton() {
 ssocket.send('31415');
}


Service The end looks like this:

##

sserver = new SonicServer({alphabet: '0123456789'});
sserver.on('message', function(message) {
  //Expect message to be '31415'.
 console.log(message);
});
sserver.start();

##                  

JS


Library support

github.

      Of course, using it requires an implementation of Web Audio (mostly using OscillatorNode## on the sending side #, use AnalyserNode at the receiving end). I've tried Macbook on Chrome to Chrome, as well as Transfer case from Mac Chrome to Android Chrome.

      I wrote a pair of examples to illustrate this idea. They appear in the video demonstrated at the beginning of this article. The first example allows you to send emoticons from one device to another. It uses a very small character set, including only 6 characters, each corresponding to 1 expressions. You can choose one of the 6 emoticons, and the corresponding character will be sent through the sonic network and received and displayed at the other end.

# Sonicnet.js The more realistic application is this chat Apply , generate a unique 5 digit token and use it to communicate between 2 devices Create connection. This is done with the help of a pairing server, which establishes a proxy connection between the two devices via WebSocket. Once the connection is established, the conversation itself is sent over WebSocket. Server-side code is hosted on nodejitsu.

          Conclusion and expectations

##               Web Audio APIIt has evolved to make such applications possible, which is a major progress. I'm obsessed with sonicnet.js implementation on the Internet of Things. This is pure Web technology that can be used to pair devices. The combination of ubiquitous browsers and audio hardware will be a huge win, and even at the hardware level, Webplatforms don't need to wait for Bluetooth or other near-field connectivity technologies at all Mature.

      If this article has piqued your interest, you can try to use sonicnet.js to write an application. As I mentioned before, receiving high frequency audio is not available on all devices due to hardware/firmware limitations, so I'd love to know which ones are available and which ones are not. Can't. My expectation is that most phones should only be able to send, while most laptops should be able to receive and send at the same time. If you tried the emoticon demo on your device, please fill out this form. At the time of writing this article, the Chrome Beta version on the Android platform does not support real-time input, so transferring data from mobile phone to laptop is the only option.

The above is the detailed content of Detailed explanation of web cross-device ultrasonic communication solution based on HTML5. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
H5: The Future of Web Content and DesignH5: The Future of Web Content and DesignMay 01, 2025 am 12:12 AM

H5 (HTML5) will improve web content and design through new elements and APIs. 1) H5 enhances semantic tagging and multimedia support. 2) It introduces Canvas and SVG, enriching web design. 3) H5 works by extending HTML functionality through new tags and APIs. 4) Basic usage includes creating graphics using it, and advanced usage involves WebStorageAPI. 5) Developers need to pay attention to browser compatibility and performance optimization.

H5: New Features and Capabilities for Web DevelopmentH5: New Features and Capabilities for Web DevelopmentApr 29, 2025 am 12:07 AM

H5 brings a number of new functions and capabilities, greatly improving the interactivity and development efficiency of web pages. 1. Semantic tags such as enhance SEO. 2. Multimedia support simplifies audio and video playback through and tags. 3. Canvas drawing provides dynamic graphics drawing tools. 4. Local storage simplifies data storage through localStorage and sessionStorage. 5. The geolocation API facilitates the development of location-based services.

H5: Key Improvements in HTML5H5: Key Improvements in HTML5Apr 28, 2025 am 12:26 AM

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

HTML5: The Standard and its Impact on Web DevelopmentHTML5: The Standard and its Impact on Web DevelopmentApr 27, 2025 am 12:12 AM

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

H5 Code Examples: Practical Applications and TutorialsH5 Code Examples: Practical Applications and TutorialsApr 25, 2025 am 12:10 AM

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

The Connection Between H5 and HTML5: Similarities and DifferencesThe Connection Between H5 and HTML5: Similarities and DifferencesApr 24, 2025 am 12:01 AM

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

The Building Blocks of H5 Code: Key Elements and Their PurposeThe Building Blocks of H5 Code: Key Elements and Their PurposeApr 23, 2025 am 12:09 AM

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

HTML5 and H5: Understanding the Common UsageHTML5 and H5: Understanding the Common UsageApr 22, 2025 am 12:01 AM

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function