Zenera Logo

Building a voice AI-Native Interface for a React app

With Zenera SDK for Web, you can create a voice AI-Native Interface and embed it to your React app. The Zenera Platform provides you with all the tools and leverages the industry's best Automatic Speech Recognition (ASR), Spoken Language Understanding (SLU) and Speech Synthesis technologies to quickly build an AI-Native Interface from scratch.

In this tutorial, we will create a simple voice enabled React app. The app users will be able to click the voice AI-Native Interface button and give custom voice commands, and Zenera will reply to them.

What you will learn

  • How to add a voice interface to a React app
  • How to write simple voice commands for a React app

What you will need

To go through this tutorial, make sure Node.js is installed on your machine.

Step 1. Sign up for Zenera Studio

First, we need to sign up for Zenera Studio — the web IDE where we will create the dialog script for our voice agent.

  1. Go to Zenera Studio.
  2. Sign up with a Google or GitHub account or with your email address.
  3. In Zenera Studio, click Create Project. Select to create an empty project and give it any name you want.

Step 2: Create a React app

Now let's create a simple React app.

  1. On your machine, navigate to the folder in which the app will reside and run the following command:
    npx create-react-app my-app
  2. Switch to the folder with the app:
    cd my-app
  3. Start the app:
    npm start

Step 3: Install the Zenera Web component

We need to add the Zenera Web component to the app. In the app folder, install the Zenera Web component with the following command:

npm i @zenera/zenera-sdk-web

Step 4: Add the Zenera AI-Native Interface to the app

Now we need to update our app to add the Zenera AI-Native Interface to it.

  1. In the src folder, open the App.js file.
  2. At the top of the file, add the import statement for the Zenera Web component:
    import zeneraBtn from "@zenera/zenera-sdk-web";
  3. We will use the Effect Hook to add the Zenera AI-Native Interface to our app. At the top of the file, add the following import statement:
    import React, { useEffect } from 'react';

    Note: For an app that uses React Class Components, you can add the Zenera AI-Native Interface with componentDidMount().

  4. In the function component, call useEffect:
    function App() {
        // Adding the Zenera AI-Native Interface
        useEffect(() => {
            zeneraBtn({
                key: 'YOUR_KEY_FROM_ZENERA_STUDIO_HERE',
                host: 'v1.alan.app',
            });
        }, []);
    }
  5. In the key field above, we need to replace YOUR_KEY_FROM_ZENERA_STUDIO_HERE with the Zenera SDK key for our Zenera Studio project. In Zenera Studio, at the top of the code editor, click Integrations, copy the value provided in the Zenera SDK Key field and paste this value to key.
    function App() {
        useEffect(() => {
            zeneraBtn({
                key: '28b4365114e0f2f67d43485dbc3cb44a2e956eca572e1d8b807a3e2338fdd0dc/stage',
                host: 'v1.alan.app',
            });
        }, []);
    }