SpeechLib.SpVoiceClass:GetVoices does crash my Unity executable - c#

I created a project with Unity (version 4.5.3f3).
I only wrote a simple script as follow:
using UnityEngine;
using System.Collections;
using SpeechLib;
public class SpeechTest : MonoBehaviour
{
private SpVoice voice;
void Start()
{
voice = new SpVoice();
voice.GetVoices("","");
}
// Update is called once per frame
void Update()
{
if (Input.anyKeyDown)
{
voice.Speak("Hello, world!", SpeechVoiceSpeakFlags.SVSFlagsAsync);
}
}
}
Here you can download the test project for Unity: https://dl.dropboxusercontent.com/u/12184013/TextToSpeech.zip
When I try to play (in Unity editor), the game runs without problems.
Instead, when I build and run the game, it crashes.
When i comment this line
ISpeechObjectTokens voices = voice.GetVoices();
the game doesn't crash after I rebuilt it.
I need to call GetVoices method, because I want to set a new voice in the "SpVoice voice" object.

Here is the solution: http://forum.unity3d.com/threads/speechlib-spvoiceclass-getvoices-does-crash-my-unity-executable.268011/#post-1772720
In a nutshell the library [Unity Install Directory]\Editor\Data\Mono\lib\mono\2.0\CustomMarshalers.dll should be included in the Unity project (adding it as a asset).

Related

My visual studio script is not working in Unity

I just started game development and got into a problem
whenever I load my Visual Studio code into Unity it says
The refrenced script unknown on this behaviour is missing
This is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VirtualManMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Hello, World!") ;
}
// Update is called once per frame
void Update()
{
}
}
I need a solution for this
This may happen is the file name does not match the class name. Make sure that the file containing this script is also named VirtualManMovement.cs
Make sure in Unity you go to edit -> preferences and see that you have Unity External tools in Your IDE Selected.
Ensure your Code File Name is the same as your Class to prevent confusion.
I was confused as well when I first started. Hopefully, you find this useful

How to use Naudio in Unity

I'm trying to use some functions of NAudio in my Unity project but don't know how to install NAudio in Unity.
What I tried:
· use NugetforUnity, installed Naudio, Naudio.core
· download Naudio-Unity.dll, put it in assets/Plugin/
When I add a script on a gameobject in my scene, write some code like:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
using Naudio-Unity;
public class NewBehaviourScript : MonoBehaviour
{
void Start()
{
for (int n = -1; n < WaveOut.DeviceCount; n++)
{
var caps = WaveOut.GetCapabilities(n);
Debug.Log($"{n}: {caps.ProductName}");
}
}
void Update()
{
}
}
There are still compile errors, Unity cannot recongnize WaveOut. Any help on this issue? Thanks in advance.
I recently encountered the same problem. The intuition thought is to download the dll file from NuGet Gallery. When I first copy to Plugins folder the Unity report error because of the windowsform api. I decided to download individual dll file and it can work.
NAudio dll in Unity Plugins folder

Unity- vs code error: if ($?) { dotnet run $Player_Movement } (Solved)

Hi I am getting "cd "c:\Users\UMUT\Desktop\Unity Projects\Newest\Assets" ; if
($?) { dotnet run $Player_Movement }" message and I get this error message "Couldn't find a project to run. Ensure a project exists in C:\Users\UMUT\Desktop\Unity Projects\Newest\Assets, or pass the path to the project using --project." in my Vs code Unity project. İn my another old project I have a C# script named Player_Movement but I am getting this error in my new Unity Project when I try to debug the project.I downloaded C# extension.I downl Any solutions or reason why it is happening?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class New : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("hi");
}
// Update is called once per frame
void Update()
{
}
}
I resetted Vs code settings and change my C# extension to older version and error fixed.
I reseted Vs code settings to default and my problem is fixed.

Visual Studio Intellisense for UnityEngine not working

I am trying to write a script for Unity in C#. I created the script and then I opened it. When I typed in Ge, I don't get Unity methods (I only see GetHashCode and GetType). I am looking for GetComponent. I tried writing the script (from a tutorial) and it works fine in Unity, so only the intellisense is not working. It also doesn't work for new Vector3().
I am using Visual Studio Community 2019 (v 16.5.2).
The complete script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddConstantVelocity : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetComponent<Rigidbody>().velocity = new Vector3(2, 10, -6);
}
}
You need to specify VS Code as the default editor.
Edit > Prefernces > External tools > External Script Editor

Monobehaviour scripts in the file, or their names don't match the file name on newly made script

Why all my newly created script always have this error? Even though i had put in my intended code, all my script always show like this.
my code is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Testing : MonoBehaviour
{
public GameObject obj;
// Start is called before the first frame update
void Start()
{
obj = GetComponent<GameObject>();
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
collision.transform.position = obj.transform.position;
}
}
Welcome to Stackoverflow!
This issue is mostly caused when you create a script outside the Unity Editor, i.e. in your IDE or editor of choice. Whenever you want to create a script, you need to create it inside the Editor, by right-clicking in your project folder and selecting "New C# Script".
If you do create your script inside Unity, you need to make sure that the class name (in your case, "Testing") is the same as the script file name.
Regardless of whether these solutions work for you, please make sure to search for answers before posting, as there are multiple duplicate issues in the Unity forums.

Categories