


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProtoBuf;
using Protobuf.Text;
using Media;
using tool;
using MessageBoxEE;
using System.Diagnostics;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using NumMachine;
using MessageBoxQR;
using System.Speech.Synthesis;

namespace terminal
{


    public partial class MainForm : Form
    {
        //任务类型
        private string tast_type;
        //项目名称
        private string project_name;
        //终端号
        private int m_ternimalID;
        //入口号
        private int m_importID;
        //单元号
        private int m_unitID;
        //号牌机IP
        private string m_numberMachine_ip;

        //rabbitmq连接参数  从配置文件读取
        private string m_rabbitmq_ip;
        private int m_rabbitmq_port;
        private string m_rabbitmq_user;
        private string m_rabbitmq_password;
        private string m_rabbitmq_ex_name;
        private string m_send_park_request_port;
        private string m_send_pick_request_port;
        private string m_recvice_park_response_queue;
        private string m_recvice_pick_response_queue;

        //自适应窗口大小
        AutoResizeForm m_auto_resize_form = new AutoResizeForm();
        //播放器
        MediaPlayer m_mediaPlayer = new MediaPlayer();
        //停车反馈接收器       
        consumer m_park_consumer = new consumer();
        //取车反馈接收器
        consumer m_pick_consumer = new consumer();
        //发送器
        producer m_producer = new producer();
        //号牌机数据
        private TimedData<NumberMachine.CarNumberInfo> m_timed_car_license = new TimedData<NumberMachine.CarNumberInfo>(new NumberMachine.CarNumberInfo());

        //获取号牌机线程
        private NumberMachine m_car_number;
        private bool m_car_number_condition;
        private Thread m_car_number_thread;
        //停车指令反馈
        private TimedData<string> m_park_command_response = new TimedData<string>("");
        //取车指令反馈
        private TimedData<string> m_pick_command_response = new TimedData<string>("");


        private Process m_process = null;
        private string m_image_path;
        private static readonly object Lock = new object();
        public MainForm()
        {
            InitializeComponent();
            //初始化json文件操作
            json_file_operation.Instance.json_file_operation_init();
            //读取项目配置
            tast_type = json_file_operation.Instance.read_json_string("taskType");
            project_name = json_file_operation.Instance.read_json_string("projectName");
            m_ternimalID = int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber"));
            m_importID = int.Parse(json_file_operation.Instance.read_json_string("importId"));
            m_unitID = int.Parse(json_file_operation.Instance.read_json_string("unitNumber"));

            //读取rabbitmq相关配置
            m_rabbitmq_ip = json_file_operation.Instance.read_json_string("RabbitMQ_ip");
            if (m_rabbitmq_ip != null)
            {
                m_rabbitmq_port = int.Parse(json_file_operation.Instance.read_json_string("RabbitMQ_port"));
                m_rabbitmq_user = json_file_operation.Instance.read_json_string("RabbitMQ_user");
                m_rabbitmq_password = json_file_operation.Instance.read_json_string("RabbitMQ_password");
                m_rabbitmq_ex_name = json_file_operation.Instance.read_json_string("RabbitMQ_ex_name");
                m_send_park_request_port = json_file_operation.Instance.read_json_string("RabbitMQ_send_park_request_port");
                m_send_pick_request_port = json_file_operation.Instance.read_json_string("RabbitMQ_send_pick_request_port");
                m_recvice_park_response_queue = json_file_operation.Instance.read_json_string("RabbitMQ_recvice_park_response_queue");
                m_recvice_pick_response_queue = json_file_operation.Instance.read_json_string("RabbitMQ_recvice_pick_response_queue");
                //初始化发送指令
                m_producer.producer_init(m_rabbitmq_ip, m_rabbitmq_port, m_rabbitmq_user, m_rabbitmq_password);
            }

            //初始化播放器
            m_mediaPlayer.MediaPlayerInit(this, ref this.ImagePictureBox, ref this.vlcControl1, ref this.time_label, ref this.date_label_1, ref this.date_label_2);

            m_image_path = System.AppDomain.CurrentDomain.BaseDirectory + "./Resource/";

            if (tast_type == "park")
            {
                m_numberMachine_ip = json_file_operation.Instance.read_json_string("numberMachine_ip");

                //获取号牌线程
                m_car_number = new NumberMachine(m_numberMachine_ip);
                m_car_number_condition = true;
                m_car_number_thread = new Thread(get_car_number_thread);
                //初始化消费指令
                if (m_rabbitmq_ip != null)
                    m_park_consumer.consumer_init(m_rabbitmq_ip, m_rabbitmq_port, m_rabbitmq_user, m_rabbitmq_password, m_recvice_park_response_queue, park_response_thread);
                this.pickupBtn.BackgroundImage = Image.FromFile(m_image_path + "fetchingBtn_gray.BackgroundImage.png");
                this.pickupBtn.Enabled = false;
                this.pickupBtn.Visible = false;
                //Point t = this.parkingBtn.Location;
                //t.X = t.X + 170;
                //this.parkingBtn.Location = t;
            }
            else if (tast_type == "pick")
            {
                this.parkingBtn.BackgroundImage = Image.FromFile(m_image_path + "parkingBtn_gray.BackgroundImage.png");
                this.parkingBtn.Enabled = false;
                this.parkingBtn.Visible = false;
                Point t = this.pickupBtn.Location;
                t.X = t.X - 330;
                this.pickupBtn.Location = t;
                //初始化消费指令
                if (m_rabbitmq_ip != null)
                    m_pick_consumer.consumer_init(m_rabbitmq_ip, m_rabbitmq_port, m_rabbitmq_user, m_rabbitmq_password, m_recvice_pick_response_queue, pick_response_thread);
            }
            else if (tast_type == "parkAndpick")
            {
                m_numberMachine_ip = json_file_operation.Instance.read_json_string("numberMachine_ip");

                //获取号牌线程
                m_car_number = new NumberMachine(m_numberMachine_ip);
                m_car_number_condition = true;
                m_car_number_thread = new Thread(get_car_number_thread);
                if (m_rabbitmq_ip != null)
                {
                    m_park_consumer.consumer_init(m_rabbitmq_ip, m_rabbitmq_port, m_rabbitmq_user, m_rabbitmq_password, m_recvice_park_response_queue, park_response_thread);
                    m_pick_consumer.consumer_init(m_rabbitmq_ip, m_rabbitmq_port, m_rabbitmq_user, m_rabbitmq_password, m_recvice_pick_response_queue, pick_response_thread);
                }
            }
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.weather_panel.Visible = false;
            m_auto_resize_form.controllInitializeSize(this);

            this.terminal_number_label.Text = "厦门市政停车终端" + json_file_operation.Instance.read_json_string("ternimalNumber").ToString() + "号机";
            this.terminal_number_english_label.Text = this.terminal_number_english_label.Text + json_file_operation.Instance.read_json_string("ternimalNumber");
            //if (MessageBox.Show("是否最大化？", "tip", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
            //{
            //    //设置最大化
            //    this.WindowState = FormWindowState.Maximized;
            //}
            this.WindowState = FormWindowState.Maximized;
            //启动播放器
            m_mediaPlayer.mediaplayer_run();


            if (tast_type == "park")
            {
                if (project_name == "ct" || this.m_unitID == 31 || this.m_unitID == 32)
                {
                    //启动子程序
                    Process[] myprocess = Process.GetProcessesByName("node");
                    if (myprocess.Count() == 0)
                    {
                        try
                        {
                            m_process = new Process();//创建一个新的进程
                            m_process.StartInfo.FileName = @".\pyqt_ui\node.exe"; ;//要启动的应用程序
                            m_process.Start();
                        }
                        catch (Exception) { }
                    }
                }
                //启动号牌机
                m_car_number.Start();
                m_car_number_thread.Start();
                if (m_rabbitmq_ip != null)
                    m_park_consumer.run();

            }
            else if (tast_type == "pick")
            {
                if (m_rabbitmq_ip != null)
                    m_pick_consumer.run();
                Process[] myprocess = Process.GetProcessesByName("node");
                if (myprocess.Count() == 0)
                {
                    try
                    {
                        m_process = new Process();//创建一个新的进程
                        m_process.StartInfo.FileName = @".\process_ui\node.exe"; ;//要启动的应用程序
                        m_process.Start();
                    }
                    catch (Exception) { }
                }
            }
            else if (tast_type == "parkAndpick")
            {
                if (project_name == "ct" || this.m_unitID == 31 || this.m_unitID == 32)
                {
                    //启动子程序
                    Process[] myprocess = Process.GetProcessesByName("node");
                    if (myprocess.Count() == 0)
                    {
                        try
                        {
                            m_process = new Process();//创建一个新的进程
                            m_process.StartInfo.FileName = @".\pyqt_ui\node.exe"; ;//要启动的应用程序
                            m_process.Start();
                        }
                        catch (Exception) { }
                    }
                }
                //启动号牌机
                m_car_number.Start();
                m_car_number_thread.Start();
                //启动打印机
                //PrintManual.Instance.Start();
                if (m_rabbitmq_ip != null)
                {
                    m_park_consumer.run();
                    m_pick_consumer.run();//启动接受反馈
                }
            }
        }
        public string randomNumer()
        {
            Random r = new Random();
            char E1 = (char)r.Next(65, 90);
            char E2 = (char)r.Next(65, 90);
            int N1 = r.Next(10, 99);
            string n1 = N1.ToString();
            int N2 = r.Next(9);
            string n2 = N2.ToString();
            int N3 = r.Next(9);
            string number = "鄂" + E1 + n1 + E2 + n2 + N3;
            return number;
        }
        /// <summary>
        /// 字符串转16进制字符
        /// </summary>
        /// <param name="_str">字符串</param>
        /// <param name="encode">编码格式</param>
        /// <returns></returns>p
        private string StringToHexString(string _str, Encoding encode)
        {
            //去掉空格
            _str = _str.Replace(" ", "");
            //将字符串转换成字节数组。
            byte[] buffer = encode.GetBytes(_str);
            //定义一个string类型的变量，用于存储转换后的值。
            string result = string.Empty;
            for (int i = 0; i < buffer.Length; i++)
            {
                //将每一个字节数组转换成16进制的字符串，以空格相隔开。
                result += Convert.ToString(buffer[i], 16);
            }
            return result;
        }

        private void parkingBtn_Click(object sender, EventArgs e)
        {
            if (m_rabbitmq_ip == null)
            {
                string test = randomNumer();
                MessageBoxCar tbox = new MessageBoxCar(this.m_ternimalID);
                tbox.SetText(test);
                tbox.ShowDialog();
                PrintManual.Instance.PrintTicket("abcdefghijkl", test);
                return;
            }

            string car_license = "";
            if (!m_timed_car_license.IsTimeout() && m_timed_car_license.Value.plate_number != "")
            {
                car_license = m_timed_car_license.Value.plate_number;
                //m_timed_car_license = new TimedData<NumberMachine.CarNumberInfo>(new NumberMachine.CarNumberInfo());
                //car_license = randomNumer();
            }
            //else
            //{
            //    car_license = randomNumer();
            //}
            //if (car_license == "")
            //{
            //    MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
            //    messageBoxEe.Show("未拍摄到号牌，请退出重进！");
            //    return;

            //}
            MessageBoxTip messageBoxTip = new MessageBoxTip(this.m_ternimalID);
            messageBoxTip.SetText1("车辆是否已熄火，拉手刹，全员下车？");
            messageBoxTip.SetText2("收后视镜，收天线");
            if (messageBoxTip.ShowDialog() != DialogResult.OK)
                return;
            messageBoxTip = new MessageBoxTip(this.m_ternimalID);
            messageBoxTip.SetText1("是否已携带随身物品？");
            messageBoxTip.SetText2("如手机，医保卡等");
            if (messageBoxTip.ShowDialog() != DialogResult.OK)
                return;
            MessageBoxCar messageBoxCar = new MessageBoxCar(this.m_ternimalID);
            messageBoxCar.SetText(car_license);
            if (messageBoxCar.ShowDialog() != DialogResult.OK)
                return;
            //ParkType parkType = new ParkType(this.m_ternimalID, "park");
            //if (parkType.ShowDialog() == (DialogResult)ParkType.Parktype.No)
            //    return;


            //创建一个停车表单
            park_table park_Table = new park_table();
            park_Table.Statu = new table_statu();
            park_Table.Statu.ExecuteStatu = STATU.ENormal;
            park_Table.Statu.StatuDescription = "正常";
            park_Table.TerminalId = m_ternimalID;
            park_Table.UnitId = m_unitID;
            park_Table.CarNumber = messageBoxCar.car_number;
            //park_Table.CarNumber = car_license;

            if (project_name != "ct")
            {
                park_Table.ImportId = m_importID;
                park_Table.CarNumberInfo = new plate_number_info();
                park_Table.CarNumberInfo.PlateNumber = park_Table.CarNumber;
                park_Table.CarNumberInfo.PlateColor = m_timed_car_license.Value.plate_color;
                park_Table.CarNumberInfo.PlateConfidence = m_timed_car_license.Value.plate_confidence;
                park_Table.CarNumberInfo.PlateType = m_timed_car_license.Value.plate_type;
                park_Table.CarNumberInfo.RecognitionTime = m_timed_car_license.Value.recognition_time;
                park_Table.CarNumberInfo.PlateFullImage = m_timed_car_license.Value.plate_full_image;
                park_Table.CarNumberInfo.PlateClipImage = m_timed_car_license.Value.plate_clip_image;
            }
            m_park_command_response = "";
            m_park_command_response.Set_timeout_ms(5000);
            if (m_producer.send(park_Table.ToText(), m_rabbitmq_ex_name, m_send_park_request_port) == false)
            {
                MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                messageBoxEe.Show("服务器连接失败！请联系管理员！");
                return;
            }
            this.parkingBtn.BackgroundImage = Image.FromFile(m_image_path + "parkingBtn_gray.BackgroundImage.png");
            this.parkingBtn.Enabled = false;

            while (!m_park_command_response.IsTimeout())
            {
                if (m_park_command_response.Value != "")
                    break;
            }
            if (m_park_command_response.IsTimeout() && m_park_command_response.Value == "")
            {
                MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                messageBoxEe.Show("反馈超时，请重试或联系管理员！");
            }
            else
            {
                try
                {
                    park_table response_Table = park_table.Parser.ParseText(m_park_command_response.Value);
                    if (response_Table.Statu.ExecuteStatu == STATU.ENormal)
                    {
                        //PrintManual.Instance.PrintTicket(response_Table.PrimaryKey, response_Table.CarNumber);
                        MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                        //speak(" 停车成功！");
                        messageBoxEe.Show(response_Table.CarNumber + " 停车成功！");
                        Task.Factory.StartNew(() =>
                        {
                            Thread.Sleep(5000);
                            //停车成功需要清除车牌号
                            lock (Lock)
                            {
                                m_timed_car_license = new TimedData<NumberMachine.CarNumberInfo>(new NumberMachine.CarNumberInfo());
                            }
                        });
                    }
                    else
                    {

                        MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                        messageBoxEe.Show(response_Table.Statu.StatuDescription);
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                    messageBoxEe.Show("反馈解析失败！\n" + ex.StackTrace);
                }
            }
            m_park_command_response = "";
            this.parkingBtn.BackgroundImage = Image.FromFile(m_image_path + "parkingBtn.BackgroundImage.png");
            this.parkingBtn.Enabled = true;

        }
        private void pickupBtn_Click(object sender, EventArgs e)
        {
            //ParkType parkType = new ParkType(this.m_ternimalID, "pick");
            //if (parkType.ShowDialog() == (DialogResult)ParkType.Parktype.No)
            //    return;
            FetchingFrom fetchingFrom = new FetchingFrom();
            fetchingFrom.StartPosition = FormStartPosition.CenterScreen;
            fetchingFrom.BringToFront();
            fetchingFrom.ShowDialog();
            if (fetchingFrom.m_is_return)
                return;
            if (m_rabbitmq_ip == null)
            {
                MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                messageBoxEe.Show("唯一码内容:" + fetchingFrom.m_key);
                return;
            }
            //创建一个取车表单
            pick_table pick_Table = new pick_table();
            pick_Table.Statu = new table_statu();
            pick_Table.Statu.ExecuteStatu = STATU.ENormal;
            pick_Table.Statu.StatuDescription = "正常";
            pick_Table.PrimaryKey = fetchingFrom.m_key;
            pick_Table.TerminalId = m_ternimalID;
            m_pick_command_response = "";
            m_pick_command_response.Set_timeout_ms(5000);
            if (m_producer.send(pick_Table.ToText(),m_rabbitmq_ex_name, m_send_pick_request_port) == false)
            {
                MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                messageBoxEe.Show("服务器连接失败！请联系管理员！");
                return;
            }
            this.pickupBtn.BackgroundImage = Image.FromFile(m_image_path + "fetchingBtn_gray.BackgroundImage.png");
            this.pickupBtn.Enabled = false;

            while (!m_pick_command_response.IsTimeout())
            {
                if (m_pick_command_response.Value != "")
                    break;

            }
            if (m_pick_command_response.IsTimeout() && m_pick_command_response.Value == "")
            {
                MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                messageBoxEe.Show("反馈超时，请重试或联系管理员！");
            }
            else
            {
                try
                {
                    pick_table response_Table = new pick_table();
                    response_Table = pick_table.Parser.ParseText(m_pick_command_response.Value);
                    if (response_Table.Statu.ExecuteStatu == STATU.ENormal)
                    {
                        MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                        messageBoxEe.Show(response_Table.Statu.StatuDescription);
                    }
                    else
                    {
                        if (response_Table.Statu.StatuDescription.Contains("缴费"))
                        {
                            string[] tip_str = response_Table.Statu.StatuDescription.Split(';');
                            if (tip_str.Length >= 2)
                            {
                                Image img = PrintManual.Instance.GetQRcode(tip_str[1]);
                                MessageBoxQr messageBoxQr = new MessageBoxQr(this.m_ternimalID);
                                messageBoxQr.SetImage(img);
                                messageBoxQr.Show(tip_str[0]);
                            }
                        }
                        else
                        {
                            MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                            messageBoxEe.Show(response_Table.Statu.StatuDescription);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
                    messageBoxEe.Show("反馈解析失败！\n" + ex.StackTrace);
                }
            }
            m_pick_command_response = "";
            this.pickupBtn.BackgroundImage = Image.FromFile(m_image_path + "fetchingBtn.BackgroundImage.png");
            this.pickupBtn.Enabled = true;
        }
        //停车反馈线程
        void park_response_thread(string msg, ref IModel channel, ref BasicDeliverEventArgs args)
        {
            Console.WriteLine("停车反馈：" + msg);
            if (msg != null && msg != "")
            {
                m_park_command_response = msg;
                m_park_command_response.Set_timeout_ms(3000);
            }
            //返回消息确认
            channel.BasicAck(args.DeliveryTag, true);
        }
        //取车反馈线程
        void pick_response_thread(string msg, ref IModel channel, ref BasicDeliverEventArgs args)
        {
            Console.WriteLine("取车反馈：" + msg);
            if (msg != null && msg != "")
            {
                m_pick_command_response = msg;
                m_pick_command_response.Set_timeout_ms(3000);
            }
            //返回消息确认
            channel.BasicAck(args.DeliveryTag, true);

        }
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {

            Process[] proc = Process.GetProcessesByName("node");
            for (int i = 0; i < proc.Length; i++)
            {
                proc[i].Kill();  //逐个结束进程.
            }
            //关闭播放器
            m_mediaPlayer.mediaplayer_uninit();
            if (tast_type == "park" || tast_type == "parkAndpick")
            {
                //关闭打印机
                //PrintManual.Instance.Close();
                //关闭号牌机连接
                m_car_number.Close();
                m_car_number_condition = false;
                if (m_car_number_thread.IsAlive)
                {
                    m_car_number_thread.Abort();
                }
            }
        }


        /// <summary>
        /// 获取号牌线程
        /// </summary>
        private void get_car_number_thread()
        {
            while (m_car_number_condition == true)
            {
                NumberMachine.CarNumberInfo number = m_car_number.GetCarNumberInfo();
                //Console.WriteLine("号牌机接收到号牌："+number);
                if (number.plate_number != null && number.plate_number != "")
                {
                    lock (Lock)
                    {
                        m_timed_car_license = number;
                        m_timed_car_license.Set_timeout_ms(900000);
                    }
                    //   MessageBoxEe.Show(m_timed_car_license.Value);
                }
                if (!m_timed_car_license.IsTimeout() && m_timed_car_license.Value.plate_number != "")
                {
                    terminal_node_statu terminal_Node_Statu = new terminal_node_statu();
                    terminal_Node_Statu.TerminalId = m_ternimalID;
                    terminal_Node_Statu.CarNumber = m_timed_car_license.Value.plate_number;
                    if(project_name != "ct")
                        terminal_Node_Statu.ImportId = m_importID;
                    m_producer.send(terminal_Node_Statu.ToText(), "statu_ex", "terminal_node_" + m_ternimalID.ToString() + "_statu_port");
                }

                Thread.Sleep(500);
            }
        }


        //设置天气
        public void set_weatherLab_text(string str)
        {
            //this.weather_label.Text = str;
        }
        //设置气温
        public void set_temperatureLab_text(string str)
        {
            //this.temperature_label.Text = str;
        }

        private void vlcControl1_VlcLibDirectoryNeeded(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e)
        {
            var currentAssembly = Assembly.GetEntryAssembly();
            var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;

            if (currentDirectory == null)
                return;
            if (IntPtr.Size == 4)
                e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x86\"));
            else
                e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x64\"));

            if (!e.VlcLibDirectory.Exists)
            {
                var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
                folderBrowserDialog.Description = "Select Vlc libraries folder.";
                folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
                folderBrowserDialog.ShowNewFolderButton = true;
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    e.VlcLibDirectory = new DirectoryInfo(folderBrowserDialog.SelectedPath);
                }
            }

        }

        private void parkingBtn_KeyDown(object sender, KeyEventArgs e)
        {
            MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
            messageBoxEe.Show("取车请先点击取车按钮再扫码！");
        }

        private void pickupBtn_KeyPress(object sender, KeyPressEventArgs e)
        {
            MessageBoxEe messageBoxEe = new MessageBoxEe(this.m_ternimalID);
            messageBoxEe.Show("取车请先点击取车按钮再扫码！");
        }

        private void MainForm_SizeChanged(object sender, EventArgs e)
        {
            m_auto_resize_form.controlAutoSize(this);
        }
        /// <summary>
        /// 语音提示
        /// </summary>
        /// <param name="APIType">要获取的类型的 ProgID</param>
        /// <param name="content">语音内容</param>
        private void speak(string content)
        {
            Task.Factory.StartNew(() =>
            {
                SpeechSynthesizer speech = new SpeechSynthesizer();
                try
                {
                    speech.Speak(content);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"报错:{ex?.Message}");
                }
            });
        }

        private void zhixiang_pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}
