Skip to main content

Custom voice Integration

In version 2.1.5 and higher, integrating custom voices has become much easier.

In this tutorial, we will guide you through the process of integrating your own text-to-speech (TTS) device.

1. Disabling Audio Receiving

Starting from version 3.0.0, you can right click in Project tab, then select Inworld > Default Settings, and turn off audio by unchecking Audio option.

cv00

If you are using previous version, after version 2.1.6, you can turn off audio by unchecking the Can Receive Audio option in Default Settings.

See the screenshot below for more details. cv02

For users on version 2.1.5 or lower, update InworldSettings.cs by simply setting the Audio of Capabilities to false.

cv01

Note: This will prevent audio from Inworld's TTS interacting with your project, after applying this setting, the server will no longer send audio.

2. Replacing Interactions on the Character

Since we have disabled audio, our character's default InworldAudioInteraction will not work, because it requires AudioClips to generate bubbles.

We need to replace InworldAudioInteraction with InworldInteraction, which is text-based. Here are the following steps:

    1. Completely unpack the character prefab.
    1. Add the InworldInteraction component and place it at the top of the component stack, above the InworldAudioInteraction.
    1. Disable the InworldAudioInteraction component.

ReplaceInteraction

3. (Optional) Enable Log of Utterance

You can toggle the Verbose Log option under the InworldCharacter script of the attached character.

After starting the game, the character's text will be displayed on the console panel, you can extend this to a subtitle system or tie it into event triggers.

VerboseLog

4. Register your own TTS Service

You can either register the event on InworldCharacter's OnCharacterSpeak, or overwrite the script HandleText to get the text directly.

cv04

Here is an example of how to use this repo: UnityRuntimeTextToSpeech's API:

public class TestSpeech : MonoBehaviour
{
public string sayAtStart = "Welcome!";

// Start is called before the first frame update
void Start()
{
// TEST speech
Speech.instance.Say(sayAtStart, TTSCallback);

}
...

According the API above, you need to create a public function with the following:

    public void OnTTSVoice(string character, string content)
{
if (character != "Player")
Speech.instance.Say(content, TTSCallback); // Referring to your own API
}

⚠️ Note: In the OnCharacterSpeaks UnityEvent, the first parameter is the name of the speaking character, and the second parameter is the actual spoken content.

Then, add this function to InworldCharacter's OnCharacterSpeaks

cv05

Congratulations! You have successfully integrated a custom TTS into your project.

⚠️ Note: Some TTS services (like the example provided) may override the current playing audioclip. We recommend saving the incoming texts in a queue and gradually playing them once the last audio has finished.