I'm really really new to c# and have been trying to make a Speech Recognition dll for GM studio to use in my game, GM studio is compiled in c++ so after I made a work speech to text program, I tried to do so but without the GUI interface...and it doesn't work, It keeps throwing error in GameMakers compiler, but when I do export it to a dll, the functions have to be static in order to work....is there any way to do this? help please lol
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech.Recognition;
using System.Runtime.InteropServices;
namespace speech
{
public partial class test
{
SpeechRecognitionEngine RecEng = new SpeechRecognitionEngine();
//used in game maker to get the text from what the user says
[DllExport("Get_speech", CallingConvention.Cdecl)]
private static string Action(string str)
{
return str;
}
// picks up voice
public void record() {
RecEng.RecognizeAsync(RecognizeMode.Multiple);
}
// loads everything
private void Load()
{
Choices commands = new Choices();
commands.Add(new string[] { "say hello", "say my name" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(commands);
Grammar gram = new Grammar(gb);
RecEng.LoadGrammarAsync(gram);
RecEng.SetInputToDefaultAudioDevice();
RecEng.SpeechRecognized += speech_rec;
}
// understands text
private void speech_rec(object sender, SpeechRecognizedEventArgs e)
{
Action(e.Result.Text);
}
// stops listening
private void stop()
{
RecEng.RecognizeAsyncStop();
}
// runs everything in gamemaker
[DllExport("Run",CallingConvention.Cdecl)]
public static double run(double on)
{
test t = new test();
if (on == 1.0)
{
t.record();
}
else {
t.stop();
}
return on;
}
// loads the load funciton in game maker
[DllExport("ini_speech", CallingConvention.Cdecl)]
public static void ini_speech() {
test t = new test();
t.Load();
}
}
}