Skip to main content
Skip table of contents

Generate and start the VDK Service

Overview

This guide empowers you to create and manage voice applications using VDK Service, an extension of the Voice Development Kit (VDK). VDK Service simplifies the development and deployment process for voice-driven experiences.

Create and export a project with the VDK Service interaction mode

To generate the vdk-service we need to follow these steps:

  1. Create a project:
    Initiate a new custom project and specify the 'VDK Service' interaction mode during project setup.

  2. Integrate technologies:
    Integrate the desired technologies into your project and configure them accordingly.

  3. Export your project:
    Export your project to the designated target folder. This will generate three directories: 'config,' 'data,' and 'vdk-service'.

    BASH
    $ tree -d -L 1
    .
    |-- config
    |-- data
    `-- vdk-service
    3 directories

Starting the VDK Service

Windows/Linux

Use the command below to start the service:

BASH
$ ./vdk-service/bin/vdk-service.exe -f config/vsdk.json

Where the parameter -f is used to specify the configuration file location. If you want to load the configuration file later, start by launching the service without specifying the configuration file and later use the route localhost:39806/v1/configuration-path to load the configuration file.

BASH
$ ./vdk-service/bin/vdk-service.exe &
$ curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"path":"config/vsdk.json"}' \
  http://localhost:39806/v1/configuration-path
Android

First of all, move the data exported from the VDK Studio into your Android project:

  • assets to app/src/main/assets

  • lib.jar to app/libs

Then, you will need to configure the network access into your Android Manifest.

First, add the permission below to AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

Then, we will need to configure the network security. Create a file into res/xml named network_security_config.xml and paste the content below in it:

CODE
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">127.0.0.1</domain>
    </domain-config>
</network-security-config>

Finally, add to tag <application> into the Manifest: `

CODE
android:networkSecurityConfig="@xml/network_security_config"

It will allow the vdk-service to use spawn a HTTP webserver.

Now that everything is configured, you can start the vdk-service using, for example, a Runtime:

CODE
    private void readLogs(BufferedReader reader) {
        new Thread(() -> {
            try {
                String tmp;
                while ((tmp = reader.readLine()) != null) {
                    Log.e(getLocalClassName(), tmp);
                }
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();
    }
    private void exec(String command) {
        try {
            // Retrieve bin dir
            final String dir = getApplicationInfo().nativeLibraryDir;
            final String app = dir + "/vdk-service";
            // Retrieve `vsdk.json` configuration path from assets
            final String configPath = getFilesDir().getAbsolutePath() + "/vsdk/config/vsdk.json";
            // Start process specifying config path AND port so we can communicate with it later
            process = Runtime.getRuntime()
                        .exec(new String[]{app, "-p", "39666", "-f", configPath},
                                new String[]{"LD_LIBRARY_PATH=" + dir});
            // Read logs from binary. Not mandatory
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(process.getInputStream())
            );
            BufferedReader errorReader = new BufferedReader(
                    new InputStreamReader(process.getErrorStream())
            );
            readLogs(reader);
            readLogs(errorReader);
            process.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

The vdk-service should now run and start a webserver listening on 127.0.0.1:39666.

The configuration path can be loaded just once either with terminal argument or with REST api route.

Different starting options:

Option

Value range

Default value

Description

-h, --help

-

-

Prints usage then exits

-p, --port

[1-65535]

39806

Port the web server will listen to (HTTP & WebSocket).

-c, --cpu-count

[0, 2-255]

0

Number of logical cores used (0 means hardware count).

-d, --websocket-close-delay

[0-65535]

0

Amount of milliseconds spent before closing a websocket.

-f, --config-path

-

""

Path to a VSDK configuration file to starts with.

-L, --plugin-path

-

../plugins/

Path to the dynamic libraries.

-v, --verbosity

[off, trace, debug, info, warning, error, critical]

debug

Minimum log level that can be printed.

Stopping the VDK Service (Safely)

Two methods are available for safe termination of the VDK service:

  1. Using quit route

BASH
$ curl --header "Content-Type: application/json" \
  --request POST \
  --data '{}' \
  http://localhost:39806/v1/quit
  1. Sending SIGINT or SIGTERM to the application.
    This method involves sending the appropriate signal to the application process.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.