Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RedKenrok · Sep 20, 2015 at 07:22 PM · errornullreferenceexceptionwindowsdll.net

SpeechRecognitionEngine.InstalledRecognizers() returns null within Unity.

Hello,

I am trying to use the speech recognition system from the .NET 3.0 framework within Unity. I therefore have imported the System.Speech.dll, from .NET 3.0 since higher version did not work, into the assets folder together with its dependencies. I know that what I am trying to do might not work because Unity uses .NET 2.0, but I still want to give it a try. It all seems to work and I can run the game fine, but when I run it I get the error:

 NullReferenceException: Object reference not set to an instance of an object
 System.Speech.Internal.ObjectTokens.RegistryDataKey.HKEYfromRegKey (Microsoft.Win32.RegistryKey regKey)
 System.Speech.Internal.ObjectTokens.RegistryDataKey.RootHKEYFromRegPath (System.String rootPath)
 System.Speech.Internal.ObjectTokens.RegistryDataKey.Open (System.String registryPath, Boolean fCreateIfNotExist)
 System.Speech.Internal.ObjectTokens.ObjectTokenCategory.Create (System.String sCategoryId)
 System.Speech.Recognition.SpeechRecognitionEngine.InstalledRecognizers ()
 VoiceCommandListener.Start () (at Assets/Scripts/VoiceCommandListener.cs:14)

The line of code is:

 SpeechRecognitionEngine speechRecognitionEngine = new SpeechRecognitionEngine(SpeechRecognitionEngine.InstalledRecognizers()[0]);

When I run the same line of code outside of Unity it works fine and just grabs the default and first recognizer, but somehow it doesn't work within Unity.

I have tried switching between using .NET 2.0 instead of .NET 2.0 subset, or running the following code block instead:

 SpeechRecognitionEngine speechRecognitionEngine = null;
 foreach (RecognizerInfo info in SpeechRecognitionEngine.InstalledRecognizers()) {
     if (info.Culture.Equals(requiredCulture) && info.Id == requiredId ) {
         speechRecognitionEngine = new SpeechRecognitionEngine(info);
         break;
     }
 }

This gives the same result and this time again at the line of code which uses "SpeechRecognitionEngine.InstalledRecognizers()".

Does anybody know why it does not return anything?

Edit: switching to Microsoft.Speech.Recognition and importing the Microsoft.Speech.dll didn't work either and gives the same type of error.

Thanks in advance.

Ron

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Devacann · Dec 13, 2015 at 02:49 PM

You need to install Language Packs on windows.

the code SpeechRecognitionEngine.InstalledRecognizers() throw NullExceptions when you dont have any recognizer installed.

See there Add Language Packs to Windows

On Windows 10 it's simple:

  • Press Windows Key;

  • type "Settings" and press 'Enter';

  • select "Time & Language" then "Region & Language";

  • on "language" section choose "English" (Or Add);

  • click in "Options" button and download the "Speech" content.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by RedKenrok · Dec 14, 2015 at 06:05 PM

I made sure it was installed and selected and still no difference. To note it works outside of Unity3D in a separate command line program just not within Unity3D itself.

Settings > Time & Language > Speech


speechselection.png (13.9 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by jorrit5477 · Jun 18, 2016 at 05:47 AM

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.

Since it runs within a regular C# console application, this has nothing to do with installed language packs.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Input Injection 0 Answers

UnityEngine.Object:op_Inequality(Object, Object) 0 Answers

How to fix Unity compiler error when building WP8.1 game? 2 Answers

Help with fixing NullReferenceException 3 Answers

Null reference exception when using lists of my object. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges