Can't reference UnityEngine.Windows.Speech - c#

I'm trying to use the speech recognition functionality in Unity, but when I try to bring it it, Visual Studio isn't recognizing it.
Here's my code:
using UnityEngine;
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Windows.Speech;
using System.Linq;
public class VoiceRecog : MonoBehaviour {
private KeywordRecognizer m_Recognizer;
public KeywordRecognizer keywordRecognizer;
protected Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
void Start() {
Debug.Log("In the Start() of VoiceRecog");
keywords.Add("go", () =>
{
GoCalled();
});
keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
keywordRecognizer.OnPhraseRecognized += KeywordRecognizerOnPhraseRecognized;
}
void KeywordRecognizerOnPhraseRecognized(PhraseRecognizedEventArgs args) {
Debug.Log("in 2nd function");
System.Action keywordAction;
if (keywords.TryGetValue(args.text, out keywordAction)) {
keywordAction.Invoke();
}
}
void GoCalled() {
Debug.Log("You just Said Go.");
}
}
Unity isn't taking the KeyWordRecognizer type. I think because it's not bringing in UnityEngine.Windows.Speech.
Any ideas about why unityengine isn't being brought in?

To use KeyWordRecognizer, you must include UnityEngine.Windows.Speech at the top. You did this but KeyWordRecognizer is not still recognized.
The possible problem is that you are using older version of Unity. You must have Unity 5.4.0 and above in other to use KeyWordRecognizer.
Unity 5.4.0 Release Note:
Windows: Added speech recognition APIs under
UnityEngine.Windows.Speech. These APIs are supported on all
Also, it is now very easy to find out which version of Unity an API was added. This is a reference for you next time you encounter this problem.
Simply search and find the API then keep bringing the version number down until your current Unity version. The number changes by 10 like 550,540,530....
Available:
Not Available:

Related

How to implement Step 5 of Firebase analytics integration Unity guide

I'm running Unity 2020.1.17f1
Complete noob question.
I'm using source code bought from the Unity asset store for a project. To integrate Firebase, I've followed the google guide here . https://firebase.google.com/docs/unity/setup#confirm-google-play-version but am unsure about Step 5 where it says to put this code at the 'start of the application'.
I think I recall reading elsewhere this step may not be needed in 2020 version of Unity. But no events are being recorded in the Firebase dashboard.
So any help in understanding how to implement Step 5?
Found the solution in the video below.
https://www.youtube.com/watch?v=SJRZOAA63aA
For step 5 I used this code which appeared in the video:
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
public class FirebaseInitializer : MonoBehaviour
{
public UnityEvent onFirebaseInitialized;
private void Awake()
{
StartCoroutine(CheckAndFixDependenciesCoroutine());
}
private IEnumerator CheckAndFixDependenciesCoroutine()
{
var checkDependenciesTask = Firebase.FirebaseApp.CheckAndFixDependenciesAsync();
yield return new WaitUntil(() => checkDependenciesTask.IsCompleted);
var dependencyStatus = checkDependenciesTask.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available)
{
Debug.Log($"Firebase: {dependencyStatus} :)");
onFirebaseInitialized.Invoke();
}
else
{
Debug.LogError(System.String.Format("Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
}
}

Is C# 7 working in VS 15 Preview 4?

I tried a simple test but it didn't like out variables
As a simple test, I wrote this (perhaps there is something simple wrong with it, but I also had trouble with patterns and with tuples)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class Program
{
static void Main(string[] args)
{
Runner runner = new ConsoleApplication2.Runner();
Point p = new ConsoleApplication2.Point();
runner.PrintCoordinates(p);
}
}
public class Point
{
int x = 20;
int y = 50;
public void GetCoordinates(out int a, out int b)
{
a = x;
b = y;
}
}
public class Runner
{
public void PrintCoordinates(Point p)
{
p.GetCoordinates(out int x, out int y);
Console.WriteLine($"({x}, {y})"); // x does not exist in current context
}
}
}
According to this post, where the PrintCoordinates example method comes from:
Note: In Preview 4, the scope rules are more restrictive: Out variables are scoped to the statement they are declared in. Thus, the above example will not work until a later release.
The new tuples suffer from a similar problem, though it seems you can partially work around that with a NuGet download:
Note: Tuples rely on a set of underlying types, that aren’t included in Preview 4. To make the feature work, you can easily get them via NuGet:
Right-click the project in the Solution Explorer and select “Manage NuGet Packages…”
Select the “Browse” tab, check “Include prerelease” and select “nuget.org” as the “Package source”
Search for “System.ValueTuple” and install it.

Cosmos "Hello world" Plug generate error

I've just installed Cosmos and tried to run the test program given by default. That's the code:
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
namespace CosmosKernel2
{
public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
}
protected override void Run()
{
Console.Write("Input: ");
var input = Console.ReadLine();
Console.Write("Text typed: ");
Console.WriteLine(input);
}
}
}
When I try to compile it, it says:
Error 8 Plug needed. System.Void System.Threading.Monitor.Exit(System.Object)
at Cosmos.IL2CPU.ILScanner.ScanMethod(MethodBase aMethod, Boolean aIsPlug) in c:\Data\Sources\Cosmos\source2\IL2CPU\Cosmos.IL2CPU\ILScanner.cs:line 663
at Cosmos.IL2CPU.ILScanner.ScanQueue() in c:\Data\Sources\Cosmos\source2\IL2CPU\Cosmos.IL2CPU\ILScanner.cs:line 779
at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod) in c:\Data\Sources\Cosmos\source2\IL2CPU\Cosmos.IL2CPU\ILScanner.cs:line 284
at Cosmos.Build.MSBuild.IL2CPUTask.Execute() in c:\Data\Sources\Cosmos\source2\Build\Cosmos.Build.MSBuild\IL2CPUTask.cs:line 239 C:\Program Files (x86)\MSBuild\Cosmos\Cosmos.targets 32 10 CosmosKernel2Boot
I'm using Visual Studio 2010, I have installed all requirements listed here: http://cosmos.codeplex.com/releases/view/123476
Thank you in advance!
"plug needed" error means that you have used some method which relies on an internal call or PInvoke, and thus Cosmos cannot compile it.
You probably use a method that has not been plugged yet or maybe missing a reference to that implementation (which makes Cosmos think it is not implemented)
Use the below guides to help you getting started:
http://www.codeproject.com/Articles/220076/Csharp-Open-Source-Managed-Operating-System-Intro
http://www.codeproject.com/Articles/29523/Cosmos-C-Open-Source-Managed-Operating-System
Update: Try using something similar to this code:
using System;
using Cosmos.Compiler.Builder;
namespace CosmosBoot1
{
class Program
{
#region Cosmos Builder logic
// Most users wont touch this. This will call the Cosmos Build tool
[STAThread]
static void Main(string[] args)
{
BuildUI.Run();
}
#endregion
// Main entry point of the kernel
public static void Init()
{
var xBoot = new Cosmos.Sys.Boot();
xBoot.Execute();
//There's supposed to be a bit of text here. Change it to Console.WriteLine("Hello world!");
}
}
}
It seems that Cosmos isn't working well with windows 8/8.1. So the only solution is to either install Windows 7 or run a virtual machine with installed Windows 7 (the latter worked for me)

Drawing Overlay inside DX11 Game (CryEngine) with C# and EasyHook

What I want to do:
I have a Game based on CrySDK which is DirectX11 and I want to draw an ingame overlay like the steam overlay.
-> I write C# since I don't know any C++, so I'm looking for ways to do this in C#.
-> I use EasyHook and SharpDX Libaries because it seems this is the best way to go.
-> I found a reference project which is apparently some kind of hack for SC2, I'm just interested in the overlay part however.
-> I use Visual Studio 2013
-> For now I'd be happy if I could draw random stuff inside a game at all
What I did so far:
I was looking through google and SO search results, problem is, that either the stuff is in C++, C or other, the results are from 2010 and not up to date with the current dx11, contain dead links or are unusable for any other reasons. This covers 95% of all I've turned up myself, some usuable hints have been included into my code.
I managed to create a Injector.dll and inject it into the game (at least i think it is injected, haven't had any usuable results so far)
What I have:
The file which does the injection:
...
// Try inject thingy
EasyHook.Config.Register("Star Citizen Noise.sc Client Overlay",
// "Direct3D9Hook.dll",
"SharpDX.dll",
"SharpDX.Direct3D11.dll",
"Injector.dll");
// Do the inject
RemoteHooking.Inject(scProcess.Id, InjectionOptions.DoNotRequireStrongName, "Injector.dll", "Injector.dll", "Star Citizen Noise.sc Injector.dll");
Console.WriteLine("DLL Injected.");
...
The injector.dll itself consists of this file, called Hooks/Graphics/Direct3D11Hook.cs (I tried to keep the structure similar to the oter sc2 reference project)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Runtime.InteropServices;
using EasyHook;
using SharpDX;
using SharpDX.Direct3D11;
using Rectangle = SharpDX.Rectangle;
namespace Injector.Hooks.Graphics
{
public class Direct3D11Hook : HookBase
{
private Device device = null;
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
private delegate Result EndSceneDelegate(IntPtr devicePointer);
public delegate void EndSceneEventDelegate(ref IntPtr devicePointer);
public event EndSceneEventDelegate OnEndScene;
private Result EndScene(IntPtr devicePointer)
{
try
{
//this.Log.LogMethodSignatureTypesAndValues(devicePointer);
//GetOrCreateDevice
if (this.device == null)
this.device = Device.FromPointer<Device>(devicePointer);
if (this.OnEndScene != null)
this.OnEndScene(ref devicePointer);
System.Drawing.Graphics g = System.Drawing.Graphics.FromHdc(devicePointer);
//System.Drawing.Graphics g = System.Drawing.Graphics.FromHwndInternal(devicePointer);
// lets try to draw something
Pen myPen = new Pen(System.Drawing.Color.Pink, 4);
System.Drawing.Point P1 = new System.Drawing.Point(50, 50);
System.Drawing.Point P2 = new System.Drawing.Point(500, 500);
g.DrawLine(myPen, P1, P2);
g.Dispose();
//this.device.EndScene();
return Result.Ok;
}
catch (SharpDXException ex)
{
//Log.Warn(ex);
Console.WriteLine(ex);
return ex.ResultCode;
}
catch (Exception ex)
{
//this.Log.Fatal(ex);
Console.WriteLine(ex);
return Result.UnexpectedFailure;
}
}
public override void Install()
{
try
{
EndSceneDelegate esd = new EndSceneDelegate(this.EndScene);
}
catch (Exception)
{
throw;
}
}
public override void Uninstall()
{
}
}
}
Here I tried to provide an override function for the EndScene function, because i think this is where I need to be. Needless to say, nothing appears to be drawn.
The delegate definitions are somewhat of a copypaste from the reference project however I have yet to find out how to actually hook my function into the render pipeline and/or react to events which might help my cause.
There is also this huge file [https://github.com/jasonpang/Starcraft2Hook/blob/master/Game/Hooks/Graphics/Direct3D9.cs] which defines function addresses which seems to work for DX9, I don't think that it can just be copy pasted and used for DX11 as well, so probably there are new function addresses in DX11? How can I find those? Where do I need to look? Is it something SharpDX can help me with?
TL;DR
Want to create steam-like overlay for DX11 game, need to hook into D3D stuff and magic and shit, got dll inject working, need help with pipeline injection

How do i read the Title property of a GDK.Window

I'm converting an .NET Windows application for Mono to run on Linux (Ubuntu). One of the features depends on a native library (user32.dll). The Mono guide that talks about conversion of applications (Linux Platform Differences) suggests that one approach would be to modify this code.
I'm trying to use GDK to access the Title of a Gdk.Window that I had access through the property Gdk.Global.ActiveWindow. But I found this error at compile time:
Error CS0154: The property or indexer `Gdk.Window.Title` cannot be used in this context because it lacks the `get` accessor (CS0154) (GetActiveWindow)
If i remove the code that reads de Title property of activeW, everything works fine. There is another way to read this property?
Here my unit of work:
using System;
using Gtk;
using Gdk;
using System.Threading;
namespace GetActiveWindow
{
class GdkApp : Gtk.Window
{
public static void Main ()
{
Application.Init ();
new GdkApp ();
Application.Run ();
}
public GdkApp () : base("Simple App")
{
SetDefaultSize (150, 150);
ShowAll();
while (true) {
var activeW = Gdk.Global.ActiveWindow;
Console.WriteLine("Active Window: {0}",activeW.Title); // Where my compile error happens.
Console.WriteLine("Simple App Window: {0}",this.Title); // This code works perfectily.
Thread.Sleep(1000);
}
}
}
}
I think that with Gdk is imposible. Try it with Wnck library giving to a C compiler this '-DWNCK_I_KNOW_THIS_IS_UNSTABLE' and works but with a warning: Unhandled action type _OB_WM_ACTION_UNDECORATE
Sorry I have used genie instead vala.
//valac *.gs --pkg gtk+-3.0 --pkg libwnck-3.0 -X '-DWNCK_I_KNOW_THIS_IS_UNSTABLE'
init
Gtk.init(ref args)
var ventana= new win()
ventana.inicio()
ventana.printinfo()
Gtk.main()
class win:Gtk.Window
won:weak GLib.List of Wnck.Window
def inicio()
var button= new Gtk.Button()
button.clicked.connect(printinfo)
this.add(button)
this.show_all()
def printinfo()
won= Wnck.Screen.get_default().get_windows()
won.foreach(allwin)
def allwin(w:Wnck.Window)
if w.is_skip_tasklist() or w.is_skip_pager()
pass
else
print w.get_name()

Categories