问题 语音识别DLL.

JRCarey.

新成员
加入
2017年9月15日
消息
1
编程经验
3-5
我真的很新的c#,一直试图为gm工作室进行语音识别dll在我的游戏中使用,gm工作室是在c ++中编译的,所以在我对文本程序作出工作演讲后,我试过这样做但是没有GUI界面......它不起作用,它会在GameMakers编译器中抛出错误,但是当我将其导出到DLL时,函数必须静态以工作....有没有办法去做这个?帮忙请大声笑
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();
        }
    }
}
 
最佳 底部