Text to Speech [Dll] for Windows Desktop.

Hi,

Unity (Indie and Pro) can speak now. Sorry, only for Windows standalone :wink:

Need a Voice Recognition solution? Try this


[EDIT 05/01/18 NEW VERSION HERE…]( Text to Speech [Dll] for Windows Desktop. page-4#post-3340957)

Your are free to include this DLL in any app or project you want.
You are free to modify and change anything you want. Yes, even the copyright and my name. :stuck_out_tongue:


The “VoiceSpeaker.CS” file

// Voice Speaker  (c) ZJP
//
// Windows 32B >> Copy 'Voice_speaker.dll' in windows\system32 folder
// Windows 64B >> Copy 'Voice_speaker.dll' in windows\SysWOW64 folder
// Remember to release "Voice_speaker.dll" with your final project. It will be placed in the same folder as the EXE
//
    // Voice Speaker  (c) ZJP //
    using UnityEngine;
    using System;
    using System.Collections;
    using System.Runtime.InteropServices;
 
    public class VoiceSpeaker : MonoBehaviour
    {
        [DllImport ("Voice_speaker.dll", EntryPoint="VoiceAvailable")] private static extern int    VoiceAvailable();
        [DllImport ("Voice_speaker.dll", EntryPoint="InitVoice")]      private static extern void   InitVoice();
        [DllImport ("Voice_speaker.dll", EntryPoint="WaitUntilDone")]  private static extern int    WaitUntilDone(int millisec);
        [DllImport ("Voice_speaker.dll", EntryPoint="FreeVoice")]      private static extern void   FreeVoice();
        [DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceCount")]  private static extern int    GetVoiceCount();

        // Unity V4.x.x
        [DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceName")]   private static extern IntPtr GetVoiceName(int index);
        //  other Unity version
        // [DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceName")]   private static extern string GetVoiceName(int index);

        [DllImport ("Voice_speaker.dll", EntryPoint="SetVoice")]       private static extern void   SetVoice(int index);
        [DllImport ("Voice_speaker.dll", EntryPoint="Say")]            private static extern void   Say(string ttospeak);
        [DllImport ("Voice_speaker.dll", EntryPoint="SayAndWait")]     private static extern void   SayAndWait(string ttospeak);
        [DllImport ("Voice_speaker.dll", EntryPoint="SpeakToFile")]    private static extern int    SpeakToFile(string filename, string ttospeak);
        [DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceState")]  private static extern int    GetVoiceState();
        [DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceVolume")] private static extern int    GetVoiceVolume();
        [DllImport ("Voice_speaker.dll", EntryPoint="SetVoiceVolume")] private static extern void   SetVoiceVolume(int volume);
        [DllImport ("Voice_speaker.dll", EntryPoint="GetVoiceRate")]   private static extern int    GetVoiceRate();
        [DllImport ("Voice_speaker.dll", EntryPoint="SetVoiceRate")]   private static extern void   SetVoiceRate(int rate);
        [DllImport ("Voice_speaker.dll", EntryPoint="PauseVoice")]     private static extern void   PauseVoice();
        [DllImport ("Voice_speaker.dll", EntryPoint="ResumeVoice")]    private static extern void   ResumeVoice();
 
        public int voice_nb = 0;
 
        void Start ()
        {
            if( VoiceAvailable()>0 )
            {
                InitVoice(); // init the engine
         
                if (voice_nb > GetVoiceCount()) voice_nb = 0;
                if (voice_nb < 0) voice_nb = 0;

                // Unity V4.x.x *******************************************
                IntPtr pStr = GetVoiceName(voice_nb);
                string str = Marshal.PtrToStringAnsi(pStr);
                Debug.Log ("Voice name : "+str); // Voice Name
                // Unity V4.x.x *******************************************

                //Debug.Log ("Voice name : "+GetVoiceName(voice_nb)); // Voice Name other Unity version

                Debug.Log ("Number of voice : "+GetVoiceCount()); // Number of voice
        
                SetVoice(voice_nb); // 0 to voiceCount - 1
                Debug.Log ("Voice Rate : "+GetVoiceRate());
                SetVoiceRate(2);
        
                //Debug.Log ("Voice name : "+GetVoiceName(voice_nb));
                Say("All system nominal. Engine, online, weapons, online.. We are ready. 9.,.8.,.7.,.6.,.5.,.4.,.3.,.2.,.1.,.0.,. Go,.Take off");
                // Say("Tout les systèmes sont opérationnels. Moteurs, en ligne. Armement, en ligne. Nous sommes prêt. 9.,.8.,.7.,.6.,.5.,.4.,.3.,.2.,.1.,.0.,. .Décollage" );
            }
            Application.Quit();
        }
 
        void OnDisable()
        {
            if( VoiceAvailable()>0 )
            {
                FreeVoice();
            }
        }
    }

Have fun,

JP

Edit :

Do not forget : executing Windows\sysWOW64\speech\SpeechUX_SAPI.cpl_ brings up a Window that displays all of the 32 bit Voices and the current single 64 bit Voice “Anna”.

RealSpeak Solo de Nuance (Scansoft). Free Voice

(French - Virgine) http://www.mta.alainlapierre.com/res/RSSolo4FrenchVirginie.zip
(German) - Steffi) http://www.mta.alainlapierre.com/res/RSSolo4GermanSteffi.zip
(Italia) - Silvia) http://www.mta.alainlapierre.com/res/RSSolo4ItalianSilvia.zip
(Spanish) - Isabel) http://www.mta.alainlapierre.com/res/RSSolo4SpanishIsabel.zip
(English) - Emily) http://www.mta.alainlapierre.com/res/RSSolo4UKEnglishEmily.zip
(Us - Jennifer ) http://udm4.com/Windows/RealSpeak_Solo_Direc-391899

EDIT 12-18-15.
NEW VERSION (WITH SOURCES) HERE

357731–12430–$voice_speaker_879.zip (204 KB)

I saw this post over at http://www.unity3d-france.com - Nice one!

TX :slight_smile:

Hi,

.CS file updated with news functions in post one.

JP

Bien ahí pibe!!!.. good work!!!
There is a voice known as “Jorge Loquendo”… of course, from Loquendo company. It is possible to assign that voice to the voice system?

Greets

Hi,

Works with all SAPI engines. http://www.loquendo.com/en/technology/tts_specifications.htm (SAPI 4 and 5 (Win 32) :smile:

JP

Edit : I “saw” the demo. Very good engine.

It’s very impresive… Jorge’s voice (spanish) it one of the best.
I will markup this thread :smile:

Thanks for your work!

Hi,

The French voices are amazing too. But I have not seen prices. :cry:

JP

Public apology to Unity Techology for having treated them as “pettiness” for disabling the “System.Runtime.InteropServices” allowing access to native DLLs.
It works again. Thanks guys :wink: :wink:

JP

Dear ZJP,

Thank you for sharing the DLL and the C# code.
That was very easy to use.
Is there also some other utility/tool to achive lips sync to “Say” (said/spoken words)?

Thanks!

-Adamo

Is there a way to implement TTS for 64 bit windows running unity as well?

This beatiful. ROFL.

Can you make manual like, change voice and tips.
This is awesome.

Thanks for share man.

It’s make my day cool!

Hi!! Thanks for the great work with this DLL… I’ve been experiencing some performance problems (the words are not played fluently) in computers with limited hardware capabilities while playing text with more than 6 or 7 words.

Is there something I must consider when using your functions? Or things I could do for increasing performance.

I first get all the voices installed with GetVoiceCount() and GetVoiceName(int index)
Then when I want to play some text, I set the voice with SetVoice(int index) and after that I call the Say(string ttospeak) function with the text I want.

If someone with the same problem could help me or point me in some direction, I would really appreciate it.

Dear JZP,

I would find your code very useful since I am developing a project involving TTS. Yet I seem unable to get Unity to see the dll. I copy it as you suggested to the system32 folder (and I even tried to copy it in my assets folder). Yet when I try to run your example script I get a DllNotFoundException.

I am quite a new user of Unity so forgive me if I am asking somthing that I should know :slight_smile:

Thanks again for the code

Oops, got the solution. For people who are on a Win 7 x64 system. Don’t copy the dll in the system32 forlder but in the SysWOW64 one.

Any chance of this working on ios?

Nice. Thx for the tip :wink:

No. Sorry :frowning:

JP

where is the file, a necessary licenses?

Is there a guide?

Very nice, ill have to check it out when i get home.

Has anyone worked with this recently? It works for me, but crashes Unity about 80% of the time (working great the other 20%) upon hitting “Play.”

I am currently using it. You need to make sure you call Init and set the voice. Also if you Free the voice you will need to Init again and set the voice again.