Watson Unity SDK

Hi all,
I’m currently a developer at IBM in Austin, TX. We put out an open source Watson Developer Cloud Unity SDK over a year ago.

The Watson Unity SDK will let you add Watson services to your games and applications. You can give your applications the ability to hear speech using the Speech to Text service. You can give your game the ability to see and classify images using the Visual Recognition service. You can add the ability to comprehend natural language and classify intent using the Natural Language Understanding service. Game logic can be executed upon classifying that intent. A full list of Watson services can be found here

I added Watson services to the Survival Shooter demo to show what you can accomplish using the Speech to Text service with Natural Language Understanding. Using the Speech to Text service, your application can recognize your speech and convert it to text. It then can send the string to Natural Language Understanding to extract an intent to execute a command. In this case “I need air support” will return a trained intent of air_support and drop a bomb on the player’s position.

The SDK is also very useful in mixed reality use cases where the user does not always have access to the keyboard.

I’ve been working on a major refactor of the SDK for release to the Unity Asset store. I’d love to get some developer’s opinions on the SDK. Please let me know your thoughts on what may be confusing and how we can make the SDK better!

https://github.com/watson-developer-cloud/unity-sdk/tree/feature-config-refactor

**Note: ** This is the feature-config-refactor branch.

8 Likes

bump! Any feedback would be greatly appreciated!

Ok, so I wasn’t going to leave feedback because I’m not good at it, but might as well.
First of all, I’m keeping an eye on the thread because this is more than interesting.
Second, I was wondering if this would work with someone who speaks english, but with an accent. I’m from the Caribbean and I tend to speak with a different accent as expected. Would it still understand me correctly? Would it still be accurate?

Good question! One of the great things about Watson services is that each service instance can be trained to your particular use case. You should be able to add custom words according to how they sound. You can send this data to your speech to text instance in this format:

{
“words”: [
{
“word”: “string”,
“sounds_like”: [
“string”
],
“display_as”: “string”
}
]
}

The service is continually getting better and there will be more support for options like this in the future!

Oh, this is awesome!

I just started to explore so don’t have a full feedback. The video looks awesome. For a prototype I’m doing I’m interested in speech recognition and triggering searches on data base on the speech, can you point me in the right direction?

Hi ,

I am not able to get unity package for watson SDK from the link which you have shared.

it will be great if you can share some documentation on it

thanks,

Hi,

Would love to understand how to implement it. When I look into the documentation, it’s confusing for me to understand.

Thank you

1 Like

Looks like it moved to https://github.com/watson-developer-cloud/unity-sdk/releases/

Hi.

First of all congrats on starting this.
But… i can’t make it work. I want to use the SpeechToText, and this is the log:


Looks like the WSConnector is closing the socket connection for no reason.
I was able to grab the audio, and it is recording my microphone, however, look’s like the connection to WatsonBackend is not workin.

Any idea?

EDIT:
I was able to trace the error. This happens when i change the Scripting Runtime Version from 3.5 to 4.6.
Since my project is based in 4.6 version. Does this have a simple fix or do i have to use 3.5?

Taj - thanks for posting the how-to YouTube video:

(there is now a simplified asset in the asset store I see)

1 Like

Sorry everyone, I really wish I got notifications about these posts. Please take a look at the video series @ryan77anderson posted. The Watson Unity SDK is now available on the Unity Asset Store!

Were you able to fix it?

Hi guys, this is my first time posting this and have the same problem with JPFerreira. Do you guys know how to deal with it?:(:(:(:(:frowning: Please disregard the highlighted part. Thank you.

Check this https://github.com/watson-developer-cloud/unity-sdk/issues/330 and use the updated watson SDK from asset store

Please update your SDK to v2.0.1.

I did by changing the Scripting Runtime Version from 4.6 to 3.5.
The last version available in Asset Store does not solve the issue. I’m unable to make it work with 4.6 selected.
I’ve opened a Ticket with IBM, but no feedback so far.

ERROR:

SUCCESS:

I just downloaded the IBM Watson SDK asset from the Asset Store today, and am keen to get speech-to-text working in even a demo app. But after a couple of hours with it, no luck.

I know I have my cloud service set up, and the credentials correct, because I tried the simple Curl examples here, and they work.

But the only example I could find in the asset (ServiceExample scene, ExampleSpeechToText asset) does not appear to do streamed recognition. It does run, and after much time appears to have done whatever it set out to do (except for a couple of errors because I have the Lite service), but I poked through the code and don’t see it using StartListening.

So, by crawling through the SpeechToText.cs source file, I attempted to hack out my own script that would do streaming recognition:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

using IBM.Watson.DeveloperCloud.Services.SpeechToText.v1;
using IBM.Watson.DeveloperCloud.Logging;
using IBM.Watson.DeveloperCloud.Utilities;
using IBM.Watson.DeveloperCloud.Connection;
using IBM.Watson.DeveloperCloud.DataTypes;

public class WatsonListenTest : MonoBehaviour {

    [Header("Service Credentials")]
    public string username;
    public string password;
    public string url;

    [Header("Debug Stuff")]
    public Text statusText;

    SpeechToText speechToText;
    AudioClip recording;
   
    void Start () {
        LogSystem.InstallDefaultReactors();
        UnityObjectUtil.StartDestroyQueue();
       
        //  Create credential and instantiate service
        Credentials credentials = new Credentials(username, password, url);

        speechToText = new SpeechToText(credentials);
        speechToText.OnError = OnError;
        speechToText.StreamMultipart = true;    // use Transfer-Encoding: chunked since we are sending multiple chunks to stream
        speechToText.DetectSilence = false;    // for now!
       
        if (!speechToText.StartListening(OnRecognize)) {
            Debug.LogWarning("StartListening returned false");
        } else {
            Debug.Log("StartListening OK");
        }
       
        Log.Status("Start()", "Checking whether Watson's logging system works");
    }
   
    void Update () {
        string status = "";
        if (speechToText.AudioSent) status += "Audio Sent; ";
        if (speechToText.IsListening) status += "Listening";
        else status += "Not listening";
        statusText.text = status;
       
        if (Input.GetKeyDown(KeyCode.LeftShift)) {
            Debug.Log("Recording (5 seconds)");
            recording = Microphone.Start(null, false, 5, 44100);
        }
        if (Input.GetKeyUp(KeyCode.LeftShift)) {
            Microphone.End(null);
            AudioSource audioSrc = GetComponent<AudioSource>();
            if (audioSrc != null) {
                Debug.Log("Playing recorded clip");
                audioSrc.clip = recording;
                audioSrc.Play();
            }
           
            Debug.Log("Analyzing clip");
            float[] samples = new float[recording.samples * recording.channels];
            recording.GetData(samples, 0);
            float max = 0;
            foreach (float sample in samples) if (sample > max) max = sample;
            Debug.Log(samples.Length.ToString() + " samples, max = " + max);

            Debug.Log("sending clip to Watson");
            var data = new AudioData(recording, max);
            bool result = speechToText.OnListen(data);
            Debug.Log("OnListen returned " + result);
            //            speechToText.StopListening();
        }
       
        if (Input.GetKeyDown(KeyCode.Return)) {
            Debug.Log("Stopping listening");
            if (!speechToText.StopListening()) Debug.Log("StopListening returned false");
        }
    }
   
    void OnError(string error) {
        Debug.LogWarning("Watson error: " + error);
    }
   
    void OnRecognize(SpeechRecognitionEvent results) {
        Debug.Log("Something recognized! " + results);
    }
}

But it doesn’t work. Because I have it set up to also play each recorded clip via an AudioSource, I know that the recordings are fine. And from the debug logs (I also hacked some additional debug output into SpeechToText.cs), I can see that it’s sending data to the server. But the only response I ever get from the server (i.e., the only time OnListenMessage is invoked) is with a “state: listening” message. I never get any results. (And so of course my OnRecognize callback is never called.)

This is true apparently no matter how many chunks I send, or how long I wait in between. I’m saying very simple things like “Hello,” “one, two”, etc. I must be doing something wrong, but I swear by this point I’ve looked at every method in SpeechToText, and I can’t figure out what it is.

It doesn’t help that the asset comes with no readable docs… some of them appear to be in Open Office format, and I don’t know what the heck a .shfbproj is. Can we get a simple PDF or HTML file please?

All very frustrating. Does anybody have a simple example of continuous recognition with this SDK?

OK, just to follow up for future searchers: Kimberly Siva at Mixspace kindly pointed out to me the ExampleStreaming scene, which is the one I should have tried, rather than the ExampleServices one.

After loading that one up, and editing ExampleStreaming.cs with my credentials, it just works! Seems really fast too. I’m delighted!

1 Like

Hi mediumtaj
I am making a Sci-Fi game to learn a language. I am starting to knowing Watson SDK for Unity and I would need your advice . Would It be posible?
I did the following

  • Move the Game objects by Command voice( I did the Code to do ii).
    But now I would need to récord and save this command voice and compare It with an original phrase text source. Is It possible with Watson SDK? Thanks for your time.
    Alejandro Castan