Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Text to Speech to Unity project?

Tags:

c#

unity3d

I am looking for System.speech to work in unity? Is there any way how to include this DLL in unity and MonoDevelop?

Because I'm trying to make a sound text to speech without spend the money from asset store. If System.Speech Library DLL could handle this why not. Just how to make it work with unity 5.3.5 ?

Also I have already try speechLib.dll. It is work while in editor but when Build to APK it is error and can't build.

like image 562
Dennis Liu Avatar asked Mar 03 '17 07:03

Dennis Liu


People also ask

How do I add text to a mesh in Unity?

1. Using either the GameObject dropdown or right-clicking in the Hierarchy window, select UI > TextMesh Pro - Text. 2. The first time you use TextMesh Pro (TMP) in a project, Unity will offer to import the TMP Essentials and Examples & Extras packages (if you haven't already imported the TextMesh Pro asset package).


1 Answers

Dlls files don't work on Android or iOS unless it is an unmanaged dll file without Windows specified API. If it is a Windows API or a managed dll then it won't work on Android or iOS.

You have two options: Buy a plugin or make your own. If you are only targeting Android and iOS then go for this Easy TTS which cost $5.

If you want to make one yourself then the process is very similar to my Speech to Text solution. The only difference are the classes used. Making one your self is easy. The only downside is that it is time consuming to make one for each platform.

Android:

TextToSpeech class.

iOS:

AVSpeechSynthesizer class

MacOS:

NSSpeechSynthesizer class

Windows:

ISpVoice class

There are tons of examples of how to use these on the internet. You have to make plugin for the Android class using Java, Objective-C for the iOS and MacOs classes. C++ for the Windows class.

For putting them together, you should use Unity's directive to do that.

class TextToSpeech
{
  #if UNITY_ANDROID  
    Use TextToSpeech class
  #endif

  #if UNITY_IOS
    Use AVSpeechSynthesizer class
  #endif

  #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
    Use NSSpeechSynthesizer class
  #endif

  #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
    Use ISpVoice class
  #endif 
}
like image 200
Programmer Avatar answered Sep 29 '22 21:09

Programmer