AIMLBot (中文自动回复)文本自动回复机器人

https://github.com/chivandikwa/AIMLBot (csharp)

https://github.com/gunthercox/ChatterBot (python)

http://hci.stanford.edu/~winograd/shrdlu/

http://familyshow.codeplex.com/

https://github.com/Microsoft/CNTK/wiki/Setup-CNTK-on-your-machine

https://developer.syn.co.in/tutorial/siml/siml-aiml.html

只需改两个地方(当然,中文词库要自已处理):

1.Settings.xml :

//Settings.xml :
<item name="stripperregex" value="[^\u4e00-\u9fa5|a-zA-Z0-9]"/>   

 2.Bot.cs

this.GlobalSettings.addSetting("stripperregex", "[^\u4e00-\u9fa5|a-zA-Z0-9]"); //设置正则表达式

  

 

加上语音:

using System;
using System.Collections.Generic;
using System.Text;
using AIMLbot;
using System.IO;
using System.Speech.Synthesis;

namespace ConsoleBot
{
    class Program
    {

        /// <summary>
        /// 涂聚文
        /// Geovin Du
        /// </summary>
        public class CharRoBot
        {

            const string UserId = "consoleUser";
            private Bot AimlBot;
            private User myUser;
            /// <summary>
            /// 
            /// </summary>
            public CharRoBot()
            {

                //------I added this code just coz I love that Light Green Geeky Looking Console ;-)------
                //Console.BackgroundColor = ConsoleColor.Blue;
                Console.ForegroundColor = ConsoleColor.Green;
                //----------------------------------------------------------------------------------------

                AimlBot = new Bot();
                myUser = new User(UserId, AimlBot);
                Console.Title = "CharRoBot v1.0 - By Geovin Du (www.dusystem.com)";
                Initialize();
            }

            // Loads all the AIML files in the \AIML folder         
            public void Initialize()
            {
                string settingsPath = Path.Combine(Environment.CurrentDirectory, Path.Combine("config", "Settings.xml"));
                AimlBot.loadSettings(settingsPath);
                AimlBot.isAcceptingUserInput = false;
                AimlBot.loadAIMLFromFiles();
                AimlBot.isAcceptingUserInput = true;
            }

            // Given an input string, finds a response using AIMLbot lib
            public String getOutput(String input)
            {
                Request r = new Request(input, myUser, AimlBot);
                Result res = AimlBot.Chat(r);
                return (res.Output);
            }
        }

        static CharRoBot bot;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {

            //1.第一种
            //string settingsPath = Path.Combine(Environment.CurrentDirectory, Path.Combine("config", "Settings.xml"));
            //Bot myBot = new Bot();
            //myBot.loadSettings(settingsPath);
            //User myUser = new User("consoleUser", myBot);
            //myBot.isAcceptingUserInput = false;
            //myBot.loadAIMLFromFiles();
            //myBot.isAcceptingUserInput = true;
            //while (true)
            //{
            //    Console.Write("You: ");
            //    string input = Console.ReadLine();
            //    if (input.ToLower() == "quit")
            //    {
            //        break;
            //    }
            //    else
            //    {
            //        Request r = new Request(input, myUser, myBot);
            //        Result res = myBot.Chat(r);
            //        Console.WriteLine("Bot: " + res.Output);
            //        //Make the bot Speak
            //        SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            //        synthesizer.Volume = 100;  // 0...100
            //        synthesizer.Rate = -2;     // -10...10
            //        var output = res.Output;
            //        // Synchronous
            //        synthesizer.Speak(output);
            //    }
            //}

            //2.第二种
            string input = "start";
            while (input != "exit")
            {

                bot = new CharRoBot();
                Console.Write("You: ");
                input = Console.ReadLine();
                var output = bot.getOutput(input);

                //Console.WriteLine(input);
                Console.WriteLine("Bot: " + output);

                //Make the bot Speak
                SpeechSynthesizer synthesizer = new SpeechSynthesizer();
                synthesizer.Volume = 100;  // 0...100
                synthesizer.Rate = -2;     // -10...10

                // Synchronous
                synthesizer.Speak(output);

                // Asynchronous
                // synthesizer.SpeakAsync(output);

            }

        }
    }
}

  

转载于:https://www.cnblogs.com/geovindu/p/6485496.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值