Search code examples
dependenciesembeddedcross-compilingcodec

Google Lyra on bare metal microcontroller


Google Lyra provides 3 kbps speech encoding. I'd like to use it on a bare metal microcontroller: no OS (libc is available, though). I can find no information about the feasibility of this, or even a clear list of its dependencies.

The source code shows many dependencies which won't be available in such an environment. However, many (if not all) of these are for build and test, which don't need to be included in a cross-compiler. The logger could be omitted as well.

Lyra uses Google's internal build system, which I'm not familiar with, further complicating things.

How can I understand the dependencies and port it to bare metal? At the least, how can I determine the full set of dependencies, and whether they're needing at run-time?


Update

My goal is low bandwidth speech. The lower the better, as long as it remains intelligible; it's a resource constrained environment. The source is 8 KHz 12 bit mono, but I don't desire to retain that, only to remain clearly intelligible, both with and without ambient noise.


Solution

  • Computational complexity is reduced by using a cheaper recurrent generative model, a WaveRNN variation, that works at a lower rate, but generates in parallel multiple signals in different frequency ranges that it later combines into a single output signal at the desired sample rate. This trick, plus 64-bit ARM optimizations, enables Lyra to not only run on cloud servers, but also on-device on mid-range phones, such as Pixel phones, in real time (with a processing latency of 100ms). https://github.com/google/lyra

    This performance is outside of what microcontrollers are designed for. If you keep reading that page you will also see that the project relies on Matrix-Vector multiplication accelerators, and it "enables real time performance on phones". Which in turn means, without vector multiplication support, even a Smartphone CPU couldn't realistically run lyra(Encode) in real-time.

    Alas, as a starting point I would try to use the pre-built Android App first, then look at the source code of it. Which leads you to either the lyraEncoder or lyraDecoder APIs. Since these are just a header each, you can probably try to compile it in your project (if it supports C++) by simply copying the relevant source files into your project, minding lyra specific compiler flags which you can extract from the bezel files. Maybe you could even link the whole thing in CMake, but mixing CMake and bezel sounds like headache.

    How can I understand the dependencies and port it to bare metal? At the least, how can I determine the full set of dependencies, and whether they're needing at run-time?

    They state their dependencies on the github page. You only need to have the sparse_matmul library, which lyra includes as source file, and glog, though that is arguably optional.

    All of it relies heavily on the stdlib though, so I would first try to compile lyra as-is on linux, with the same C++ version that is used on the target microcontroller, and see if it works.