Creating a speech synthesizer Dll using microsoft speech.Synthesis for unity

Hello.
So i am trying to create a speech Synthesis Dll to use with unity. this is the code for the dll. its just to test its working and will add functions to it when its works.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;

namespace WindowsFormsApplication4
{
    public partial class Form1
    {
        SpeechSynthesizer synth;
        public Form1()
        {
          
            synth = new SpeechSynthesizer();
            synth.SelectVoiceByHints(VoiceGender.Female);
            synth.Speak("123456789");
        }

     
    }
}

this is a class library project using c#. i have referenced the (.net speech.Synthesis). the dll is build as a 3.5.net framework

after building the dll i have placed it in the plugins folder and called it in a c# script in unity

void Start () {

       
        WindowsFormsApplication4.Form1 voice=new     WindowsFormsApplication4.Form1();

i was getting a internal compiler error until i placed the speech Synthesis Dll that is referanced in my dll in the plugins folder along with the dll i have created

but now i am getting this error.

Any idea ?
Thanks.

Well, your call stack suggests this is a crash from inside SelectVoiceByHints(). Does that code work from outside of Unity?

1 Like

the same code runs if it was a c# WindowsFormsApplication project.:slight_smile: but when i turn that into a dll and use it with unity that happens :frowning:

And thank you Graham for responding to my posts. i really appreciate your help .

Did you ever find a solution to this?

I am running into the same issue, but what could be the case is that the Microsoft.Win32.RegistryKey class in the shipped Mono mscorlib is not fully compatible with the Microsoft version.

Having a look with ILSpy in the System.Speech dll it shows the method in which the null reference occurs tries to obtain the non-public ‘hkey’ field of the passed RegistryKey instance using reflection. This field is not available in the mscorlib shipped with Unity.

If anybody got it working, I would be pleased to know.

Same issue