Here is the 10th post of the series of “Holographic App Development Using Microsoft HoloLens“. In this article you will get some insight of enabling “Text to Speech” capabilities for your Holographic applications. You can place text to speech voices around your holograms to make your applications more interactive. You can achieve it very easily with the help of “TextToSpeech” manager available with HoloLens Toolkit.
Follow the few simple steps to get it done.
Setup the Unity Project for Holographic App
Run a new instance of Unity 3D, create a new Unity Project, and Import the HoloToolkit for Unity by navigating from Import Package -> Custom Package
Once the Package is initialized and loaded successfully, you would see the “HoloToolkit” option in the main Unity menu bar. From the Configure option, apply the “HoloLens Scene Settings” and “HoloLens Project Settings” to make your project ready for holographic app.
Setting up the Holographic Project using HoloToolkit
Once the basic application setup is done follow the below steps
1. Add an Empty Object in the Object Hierarchy, and named it as “Audio Manager” (feel free to choose any other name)
Adding Audio Manager
2. Select the “Audio Manager” option from object hierarchy and from the right “Inspector” panel change the Spatial Blend” option from 2D to 3D.
3. Navigate to HoloToolkit -> Utilities ->Scripts, and Drag and Drop the “TextToSpeechManager” script over Audio manager as a component.
4. Drag the Audio Source and Attach it with the input parameter of Audio Source of “Text to Speech Manager Script”
That’s all for setting up the Text to Speech Manager
Using the Text to Speech Manager
We have already setup the Project and the Text to Speech Manager, now time to use it.
1. Add a new C# Script file and add the following script for test TextToSpeechManager
public class CustomScript : MonoBehaviour {
// Use this for initialization
void Start () {
var soundManager = GameObject.Find("Audio Manager");
TextToSpeechManager textToSpeech = soundManager.GetComponent<TextToSpeechManager>;();
textToSpeech.Voice = TextToSpeechVoice.Mark;
textToSpeech.SpeakText("Welcome to the Holographic App ! You can use Gaze, Gesture and Voice Command to interact with it!");
}
// Update is called once per frame
void Update () {
}
}
GameObject.Find() return the game object instance for the “Audio Manager” and in the next steps we are retrieving the Text To Speech Manager Components from the Audio manager.
2. Create another empty game object, say call it as Root and attach this new “CustomScript” as a component.
That’s it. Build and Run the Application !!
You can place and attach the Audio Sources related with different Holograms and enable the text to speech command when user interact with those objects. There are different set of voices which you can select from the TextToSpeechVoice enumeration.
Hello Darren, have you followed the steps 4 – “Drag the Audio Source and Attach it with the input parameter of Audio Source of “Text to Speech Manager Script” . You need to add an Audio Source which has to be refer in the script. Can you please try that and see if you still have the issue.
Hey there, had the same issue and fixed it!
First of all thanks @Abhijit Jana for this tutorial, you helped me a lot!
@Darren:
Make sure you initialize the [[TextToSpeechManager textToSpeech = soundManager.GetComponent();]] some milliseconds before you are using it [[textToSpeech.SpeakText(“Foo bar!”)]]. I just initialized the TextToSpeechManager in the start and made it an classwide accessible object. Then, when I want to use Text2Speech I just use it.
This doesn’t seem to work. I have followed every step and get the following errors when I try to perform text to speech:
“An AudioSource is required and should be assigned to ‘Audio Source’ in the inspector.”
Speech not initialized. “Hello World”
But the text to speech script does have an audio source tied to it in the inspector.
Did you ever run into this issue?
LikeLike
Hello Darren, have you followed the steps 4 – “Drag the Audio Source and Attach it with the input parameter of Audio Source of “Text to Speech Manager Script” . You need to add an Audio Source which has to be refer in the script. Can you please try that and see if you still have the issue.
LikeLike
Hey there, had the same issue and fixed it!
First of all thanks @Abhijit Jana for this tutorial, you helped me a lot!
@Darren:
Make sure you initialize the [[TextToSpeechManager textToSpeech = soundManager.GetComponent();]] some milliseconds before you are using it [[textToSpeech.SpeakText(“Foo bar!”)]]. I just initialized the TextToSpeechManager in the start and made it an classwide accessible object. Then, when I want to use Text2Speech I just use it.
I hope I was able to help you out.
LikeLike
Thank you for your post Abhijit!
Is there a way to change the input and output language?
LikeLike