public ActionResult Post(IEnumerable<VoiceMessage> voiceMessage)
        {


            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                //    // Output information about all of the installed voices. 
                //    Console.WriteLine("Installed voices -");
                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    VoiceInfo info = voice.VoiceInfo;
                    Console.WriteLine(" Voice Name: " + info.Name);
                }
            } 

            
            
            string toBeVoiced =  string.Empty;
            try
            {
                foreach (var voice in voiceMessage)
                {
                    toBeVoiced = voice.SegmentText;
                    toBeVoiced = toBeVoiced.Replace("<p>", "");
                    toBeVoiced = toBeVoiced.Replace("</p>", "");
                    toBeVoiced = toBeVoiced.Replace("'", "");
                    toBeVoiced = toBeVoiced.Replace("'", "");
                    toBeVoiced = toBeVoiced.Replace("*", "");
                    toBeVoiced = toBeVoiced.Replace(" ", "~");
                    toBeVoiced = toBeVoiced.Replace("<br~/>", "");
                    toBeVoiced = toBeVoiced.Replace("~", " ");

                    VoiceMessage addVoiceMessage = new VoiceMessage();
                    addVoiceMessage.SegmentText = toBeVoiced;
                    addVoiceMessage.IdName = voice.IdName;
                    addVoiceMessage.SegmentName = voice.SegmentName;

                    patientRecords.AddVoicingMessage(addVoiceMessage);
                }
                return new JsonResult { Data = new { Success = true } };
            }
            catch(Exception er)
            {
                string s1 = er.Message;
                return new JsonResult { Data = new { Success = false } };
            }
        }
コード例 #2
0
 public void AddVoicingMessage(VoiceMessage voiceMessage)
 {
     //Check 1 is value numeric
     long number1 = 0;
     bool canConvert = long.TryParse(voiceMessage.IdName, out number1);
     if (canConvert == true)
     {
         if (VoicingMessageCount(voiceMessage.IdName) > 0)
         {
             //update 
             using (MySqlConnection db = new MySqlConnection(Database.ReminderConnection))
             {
                 try
                 {
                     string query =
                         "update messages"
                         + " set message = @message"
                         + " where id = @id";
                     int rowsAffectd = db.Execute(query, new
                     {
                         @id = voiceMessage.IdName,
                         @message = voiceMessage.SegmentText
                     }
                         );
                 }
                 catch (Exception er)
                 {
                     Log.LogMessage(er.ToString());
                 }
             }
         }
         else
         {
             //insert 
             using (MySqlConnection db = new MySqlConnection(Database.ReminderConnection))
             {
                 try
                 {
                     string query =
                         "insert into messages(message_id,message_name,message_type, message)"
                         + "values(@mesaage_id,@message_name,@message_type,@message)";
                     int rowsAffectd = db.Execute(query, new
                     {
                         @mesaage_id = 1,
                         @message_name = voiceMessage.IdName,
                         @message_type = "MESG",
                         @message = voiceMessage.SegmentText
                     }
                         );
                 }
                 catch (Exception er)
                 {
                     Log.LogMessage(er.ToString());
                 }
             }
         }
     }
     else
     {
         //insert 
         using (MySqlConnection db = new MySqlConnection(Database.ReminderConnection))
         {
             try
             {
                 string query =
                     "insert into messages(message_id,message_name,message_type, message)"
                     + "values(@mesaage_id,@message_name,@message_type,@message)";
                 int rowsAffectd = db.Execute(query, new
                 {
                     @mesaage_id = 1,
                     @message_name = voiceMessage.IdName,
                     @message_type = "MESG",
                     @message = voiceMessage.SegmentText
                 }
                     );
             }
             catch (Exception er)
             {
                 Log.LogMessage(er.ToString());
             }
         }
     }
 }