PCMFlow722 library enables two-way real-time HD voice over ESP-NOW with G.722 audio codec

Tanaka Masayuki’s PCMFlow722 library enables (half-duplex) two-way real-time HD voice over ESP-NOW on ESP32 boards with a speaker and a microphone, effectively transforming them into walkie-talkies.

The library implements a G.722 wideband codec add-on for PCMFlow lightweight audio decode and PCM flow library for Arduino, which already supports uncompressed PCM, MP3, and FLAC audio codecs. PCM and FLAC take too much bandwidth over ESP-NOW, and MP3 is not suitable for real-time audio, so the legacy G.722 audio codec was selected instead.

ESP-NOW two-way HD audio communication

The keyword here is “HD voice,” since two-way audio over ESP-NOW was previously implemented in projects such as Atomic14’s esp32-walkie-talkie (5 years ago) and, more recently, the well-documented Adafruit ESP-NOW Walkie-Talkie project, but these typically rely on lower-quality G.711 audio or compressed audio.

The PCMFlowG722 library and G.722 codec enable HD voice with “7 kHz audio at 16 kHz sampling using the same 64 kbps wire budget as G.711 — same packet size, twice the audio bandwidth”, as explained by Tanaka. The table below compares G.711, G.722, and Opus codecs and libraries.

PCMFlowG711PCMFlowG722 (this lib)PCMFlowOpus
Audio bandnarrowband (8 kHz / ≤ 3.4 kHz)wideband (16 kHz / ≤ 7 kHz)narrow / wide / fullband (8–48 kHz)
Bitrate (voice)64 kbps fixed64 kbps fixed (Mode 1)16–32 kbps typical
Compression vs raw 16-bit PCM10–15×
Codec flash footprint< 4 KB~10 KB~150–180 KB
Codec CPUnegligiblelownon-trivial on M0/M3-class MCUs
Patent / license complexitynone (1972 standard, expired)none (1988 standard, expired); core is Public Domainroyalty-free patent grant, BSD-3-Clause source
Qualitytoll-grade telephonyHD voice (wideband telephony)wideband / fullband, far better

Opus offers lower bandwidth and full-band audio quality, but the G.722 audio codec is less complex and requires fewer resources (CPU, storage).  It’s also well suited to ESP-NOW, since the protocol carries up to 250-byte payloads, and a 20-ms G.722 voice frame at 16 kHz produces 160 bytes, the same as G.711, but with twice the audio bandwidth, while raw 16 kHz mono 16-bit PCM would require 640 bytes (G.722 compresses four times).

EspNowTransceiver

The library implements a G.722 encoder compressing 16 kHz PCM into G.722, and a decoder doing the reverse. If you want to try it on your own board, the EspNowTransceiver.ino Arduino sketch is probably what you want to try. It’s a half-duplex HD-voice transceiver over ESP-NOW, and the same firmware acts as both sender and receiver.

It’s been tested on the M5Stack Core2 boards with an ESP32 SoC, 8MB PSRAM, 16MB SPI flash, a small 2-inch display showing the EPS-NOW channel, a 1W speaker (1W-0928), and an SPM4123 microphone. While button A is held, the audio is broadcast over ESP-NOW to one or more Core2 devices, and in all other cases, the devices are set as audio receivers.

Via Adafruit

Share this:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress. We also use affiliate links in articles to earn commissions if you make a purchase after clicking on those links.

Radxa Dragon Q8B Edge AI SBC with Snapdragon 8cx Gen3 SoC

11 Replies to “PCMFlow722 library enables two-way real-time HD voice over ESP-NOW with G.722 audio codec”

  1. Hmmm g.722 sounds like an odd choice compared to opus.
    But probably those older ITU codecs are optimised for fixed point arithmetics and thus lighter on the ESP.

      1. Ok it still doesn’t let me…

        Just thinking what we did 15 years ago over narrow band satellite links (yes they were marketed as broadband)
        Leaving out crazy vocoders like ambe the best choice turned out to be the plain old all patents expired original GSM FR codec, it was very light on computational requirements and only a fraction of g.711 (or g.722) also the later EFR/AMR codec family were 8k but I guess then still patented.

        So maybe such a codec would allow greater range via BLE coded phy or IEEE 802.15.4

        Who knows maybe a nice tradeoff, HD for near distance and toll quality for long range

  2. So do you want the audio closer to natural? G.722
    More interested in distance? G.711
    All else being equal, distance increases as bandwidth narrows.

    1. g.711 has the identical on-air bandwidth of 64kbps as g.722, just the bandwidth of the voice transported is wider. Nowadays g.711 has no advantages at all, especially as the gsm codec’s perceived voice quality is about equal at <10kbps as opposed to 64kbps of 711

    1. Codec2 is a vocoder, a fantastic piece of SW, but far from HD voice codecs

      As we are already having overhead by a digital protocol/IP usially the savings of a vocoder to a traditional codec doesn’t pay off, especially with the high computational requirements in mind

    1. ESP-NOW is not exactly Wi-Fi, but it works over the Wi-Fi radio, so it’s legal everywhere.

Leave a Reply

Your email address will not be published. Required fields are marked *

Boardcon MINI1126B-P AI vision system-on-module wit Rockchip RV1126B-P SoC
Boardcon MINI1126B-P AI vision system-on-module wit Rockchip RV1126B-P SoC