google / lyra

A Very Low-Bitrate Codec for Speech Compression
Apache License 2.0
3.84k stars 355 forks source link

Implementing a Python wrapper for Lyra #107

Open fedingo opened 2 years ago

fedingo commented 2 years ago

Hi!

I'm trying to create a python binding for your project that would be easily pip-installable. To do so I am also developing a C binding. This is fairly simple, as it mainly translates C++ vectors into C structs. This is required because C++ name mangling makes it quite hard to export .so libraries directly from C++. I think, from what I gathered, that this is also required for most other programming languages to be able to access the library (I found similar methods for JAVA for example). Maybe this would be a contribution useful to other people. It would also allow making Lyra to work without using Bazel.

On another side, I'm trying to export the most useful functionalities of the library. I already made wrappers for LyraEncoder and LyraDecoder, but I'm not sure what other functionalities would be useful for people to have access to. I'm planning to tackle SoundStream next. What other functionalities do you think would be useful to expose?

Thanks!

mchinen commented 2 years ago

Hi, thanks so much for looking at this. Python compatibility is very useful, but a C wrapper would also be handy for typical library usage, especially for different toolchains. I will mention that it is possible to bridge C++ to python effectively - in other projects we have used pybind11 (and pybind11_abseil, pybind11_proto, pybind11_bazel) for this purpose since it's what we use internally for C++<->python. But the other advantages of a C wrapper are useful.

LyraEncoder and LyraDecoder are indeed the main interfaces that need support. Most use cases will be fine with just that. encoder_main_lib.cc and decoder_main_lib.cc gives an example of the other interfaces that may be useful. The C++ container/vector usage makes it a bit tricky to do this efficiently in a wrapper though.