I was looking for free TTS Asset (MS Windows version), but didn’t find one. I tried to make own asset and it worked on Windows Vista
=Success Story 1. TTS Unity Asset on Windows Vista works (you can do it yourself)=
Unity3d can’t use Speech API, because it is based on COM, not on .NET Framework. And somehow I found out that some Interop DLL can be created which will be like a “bridge” between Unity3d and Speech API.
Here is how I made TTS work in Unity in Windows Vista (that’s on my old Laptop)
- I started MS Visual Studio, created new C# project.
- Clicked menu “Project” → Add reference
- In COM tab I select Speech API DLL file: MS Speech Object Library (c:\Windows\System32\Speech\Common\sapi.dll)
- Click OK
- Visual Studio generated Interop.SpeechLib.dll in one of folders of C# project.
- I created new Unity3d project
- Into it’s Assets folder I copied a generated Interop.SpeechLib.dll
- Made new C# file with content:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using SpeechLib;
using UnityEngine.UI;
using UnityEngine.Windows.Speech;
public class UnityWinTTS : MonoBehaviour {
public UnityEngine.UI.Text txt;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
ButtonPress();
}
}
public void ButtonPress()
{
SpVoice voice;
voice = new SpVoice();
voice.Speak("Hello.");
voice.Speak(txt.text);
}
}
- i created a Input Field and Button on Canvas. Button runs ButtonPress function on its OnClick event.
10. I pressed run and on Button click Unity3d spoke “Hello” and text in Input-FieldWow. I was surprised, but Text-to-speech within Unity3d works on my Vista (Unity3d 4.7)
=Failure Story 2. TTS Unity Asset on Windows 10 doesn’t work (try yourself)=
On my desktop computer with Windows 10 (64-bit, Unity3d v2017) I walked the same steps as in Story 1, VS generated a DLL, I copied it into Assets folder, but Unity3d doesn’t speak on Button press.
I receive an error:
error CS0246: The type or namespace name `SpeechLib’ could not be found. Are you missing an assembly reference?
I uploaded two ZIPs:
- Win 10 Unity TTS project (Assets folder) with Speech API Interop DLL version 5.4
- Vista Interop DLL (SAPI v5.3)
Anyone can help make this work on Windows 10?
3232555–248135–Windows10 Unity TSS Effort (Assets).zip (62 KB)
3232555–248137–Interop.SpeechLib (vista).zip (55.5 KB)