Ecere SDK/eC Forums
http://ecere.com/forums/
Print view

Bindings for Voce library
http://ecere.com/forums/viewtopic.php?f=10&t=207
Page 1 of 1
Author:  mothdragon [ Sun Oct 23, 2011 8:48 am ]
Post subject:  Bindings for Voce library

I've found a library for Voice Synthesis and Voice Recognition called Voce. Unfortunately, the library is written natively in Java(yeuch!), however it does have wrappers for C++(Yay!) I'd like to be able to use this library in eC instead, (cuz eC rocks!), and was wondering how exactly do I go about writing a wrapper for the eC language. It seems to me that it should be a fairly straightforward thing to write an eC function to call the C++ function which in turn calls the Java function, but I have no idea how to begin looking into this at all. I've tried looking up how to right bindings on the net but didn't get anything particularly helpful...

There's not very many functions in the API for this library, so it really won't take long to do this once I know how...

After the wrapper/bindings are written, they could then be submitted to the people developing Voce to help them with expanding their project. They have it listed on their list of things to do, as port Voce to other languages, as many as possible, so that everyone can easily use it. If this is submitted to them, then this would also have the benefit of advertising eC out there in a group of people who may have previously been unaware of eC. I think that would be cool too. :D
Author:  jerome [ Sun Oct 23, 2011 10:46 am ]
Post subject:  Re: Bindings for Voce library

Hi Charlie,

As I mentioned on IRC, here's what you have to do:

The way to call C++ from eC right now...
1. you write C bindings with extern "C"
2. you write eC classes that call those C functions (optional)
ideally that would become an automated process in the future :) As part of this milestone


1. It's very simple, you write a C function that calls the C++ method, but it needs an extra 'this' parameter for the class objects (You write this in a .cpp file, that includes the Voce library C++ header file)

Code: Select all

extern "C" int MyClass_MyMethod(MyClass * this, int par1, char * par2)
{
   this->MyMethod(par1, par2);
}
2. and if you want to do the eC one you turn that back into OO: (You write this in a .ec file, with a prototype for the above function, 'default' is necessary if you are inside a defined eC namespace)

Code: Select all

default int MyClass_MyMethod(MyClass * this, int par1, char * par2);
 
class MyClass
{
   int MyMethod(int par1, char * par2)
   {
      return MyClass_MyMethod(this, par1, par2);
   }
}
Author:  mothdragon [ Mon Oct 24, 2011 12:44 pm ]
Post subject:  Re: Bindings for Voce library

So does this need to get compiled as library? Or is this just a file that gets imported into the project?
Author:  jerome [ Mon Oct 24, 2011 8:23 pm ]
Post subject:  Re: Bindings for Voce library

Both these files ( the .cpp and .ec file ) can be packaged in whatever way you want.

You could e.g. bundle them together with a static library from the library you're wrapping around (if you're so lucky to have such a static library) into one shared library (.dll/.so), and then the user would simply do e.g. import "voce".

You can also simply put them all into your application project, and link in the third-party library from there.

-Jerome
All times are UTC-05:00 Page 1 of 1