-
APIs for all Cobalt’s services are defined as a protocol buffer specification or simply a
protofile and be found in thecobaltspeech/protogithub repository. -
The
protofile allows a developer to auto-generate client SDKs for a number of different programming languages. Step by step instructions for generating your own SDK can be found below. -
We provide pre-generated SDKs for a couple of languages. You can choose to use these instead of generating your own. These are listed here along with instructions on how to install / import them into your projects.
Pre-generated SDKs
Golang
-
Pre-generated SDK files for Golang can be found in the
cobaltspeech/go-genprotorepo -
To use it in your Go project, simply import it:
import voicegenpb "github.com/cobaltspeech/go-genproto/cobaltspeech/voicegen/v1"
- An example client using the above repo can be found here.
Python
-
Pre-generated SDK files for Python can be found in the
cobaltspeech/py-genprotorepo -
The Python SDK depends on Python >= 3.5. You may use pip to perform a system-wide install, or use virtualenv for a local install. To use it in your Python project, install it:
pip install --upgrade pip
pip install "git+https://github.com/cobaltspeech/py-genproto"
Generating SDKs
Step 1. Installing buf
- To work with
protofiles, we recommend usingbuf, a user-friendly command line tool that can be configured generate documentation, schemas and SDK code for different languages.
# Latest version as of March 14th, 2023.
COBALT="${HOME}/cobalt"
mkdir -p "${COBALT}/bin"
VERSION="1.15.1"
URL="https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)"
curl -L ${URL} -o "${COBALT}/bin/buf"
# Give executable permissions and adding to $PATH.
chmod +x "${COBALT}/bin/buf"
export PATH="${PATH}:${COBALT}/bin"brew install bufbuild/buf/bufStep 2. Getting proto files
- Clone the
cobaltspeech/protorepository:
COBALT="${HOME}/cobalt"
mkdir -p "${COBALT}/git"
# Change this to where you want to clone the repo to.
PROTO_REPO="${COBALT}/git/proto"
git clone https://github.com/cobaltspeech/proto "${PROTO_REPO}"
Step 3. Generating code
-
The
cobaltspeech/protorepo provides abuf.gen.yamlconfig file to get you started with a couple of languages. -
Other plugins can be added to the
buf.gen.yamlfile to generate SDK code for more languages. -
To generate the SDKs, simply run the following (assuming the
bufbinary is in your$PATH)
cd "${PROTO_REPO}"
# Removing any previously generated files.
rm -rf ./gen
# Generating code for all proto files inside the `proto` directory.
buf generate proto
- You should now have a folder called
geninside${PROTO_REPO}that contains the generated code. The latest version of the VoiceGen API is v1. You can import / include / copy the generated files into your projects as per the conventions of different languages.
gen
├── ... other languages ...
└── py
└── cobaltspeech
├── ... other services ...
└── voicegen
└── v1
├── voicegen_pb2_grpc.py
├── voicegen_pb2.py
└── voicegen_pb2.pyigen
├── ... other languages ...
└── go
├── cobaltspeech
│ ├── ...
│ └── voicegen
│ └── v1
│ ├── voicegen_grpc.pb.go
│ └── voicegen.pb.go
└── gw
└── cobaltspeech
├── ...
└── voicegen
└── v1
└── voicegen.pb.gw.goStep 4. Installing gPRC and protobuf
- A couple of gRPC and protobuf dependencies are required along with the code generated above. The method of installing them depends on the programming language being used.
- These dependencies and the most common way of installing/ / including them are listed below for some chosen languages.
# It is encouraged to this inside a python virtual environment
# to avoid creating version conflicts for other scripts that may
# be using these libraries.
pip install --upgrade protobuf
pip install --upgrade grpcio
pip install --upgrade google-api-python-clientgo get google.golang.org/protobuf
go get google.golang.org/grpc
go get google.golang.org/genproto# More details on grpc installation can be found at:
# https://grpc.io/docs/languages/cpp/quickstart/
COBALT="${HOME}/cobalt"
mkdir -p "${COBALT}/git"
# Latest version as of 14th March, 2023.
VERSION="v1.52.0"
GRPC_REPO="${COBALT}/git/grpc-${VERSION}"
git clone \
--recurse-submodules --depth 1 --shallow-submodules \
-b "${VERSION}" \
https://github.com/grpc/grpc ${GRPC_REPO}
cd "${GRPC_REPO}"
mkdir -p cmake/build
# Change this to where you want to install libprotobuf and libgrpc.
# It is encouraged to install gRPC locally as there is no easy way to
# uninstall gRPC after you’ve installed it globally.
INSTALL_DIR="${COBALT}"
cd cmake/build
cmake \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
../..
make -j
make install