Esempio n. 1
0
 public void AddtoSpeechList(SpeechItem item)
 {
     _speechlist.Insert(0, item);
     if (_speechlist.Count() > 8)
     {
         _speechlist.RemoveAt(_speechlist.Count - 1);
     }
 }
Esempio n. 2
0
        public ActionResult <SpeechItem> Update(long id, SpeechItem item)
        {
            var speech = _context.SpeechItems.Find(id);

            if (speech == null)
            {
                return(NotFound());
            }

            speech.IsComplete = item.IsComplete;
            speech.Name       = item.Name;
            _context.SpeechItems.Update(speech);
            _context.SaveChanges();
            return(NoContent());
        }
Esempio n. 3
0
        public void SpeechList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            // Check that there is a selected item
            if (e.SelectedItem == null)
            {
                return;
            }
            // DisplayAlert("Selected", e.SelectedItem.ToString(), "OK");

            SpeechItem item = e.SelectedItem as SpeechItem;

            if (item.SpeechText != "")
            {
                TextSpeaker(item.SpeechText);
            }

            // Clear the selected item in the list
            SpeechList.SelectedItem = null;
        }
Esempio n. 4
0
        async void Record_OnClick()
        {
            try
            {
                var audioRecordingService = DependencyService.Get <IAudioRecorderService>();
                if (!isRecording)
                {
                    recording.IsVisible = true;
                    record.IsVisible    = false;
                    audioRecordingService.StartRecording();
                    //	IsProcessing = true;
                }
                else
                {
                    recording.IsVisible = false;
                    record.IsVisible    = true;
                    audioRecordingService.StopRecording();
                }

                isRecording = !isRecording;
                if (!isRecording)
                {
                    speechResult = await bingSpeechService.RecognizeSpeechAsync(Constants.AudioFilename);

                    if (!string.IsNullOrWhiteSpace(speechResult.DisplayText))
                    {
                        var result = new SpeechItem();
                        result.SpeechText = speechResult.DisplayText;
                        result.Speaker    = " - ";
                        ProcessResponse(result);
                    }
                }
            }
            catch (Exception ex)
            {
                return;
                //Debug.WriteLine(ex.Message);
            }
            finally
            {
            }
        }
Esempio n. 5
0
        public void ProcessResponse(SpeechItem item)
        {
            AddtoSpeechList(item);
            var text = item.SpeechText.ToLower();

            listviewlayout.IsVisible = false;
            controlslayout.IsVisible = false;

            if (text.Contains("say ") && text.Contains(" to "))
            {
                listviewlayout.IsVisible = true;
                var speech = new SpeechItem();
                var temp   = text.Substring(text.IndexOf(" say ") + 5);
                speech.SpeechText = temp.Substring(0, temp.IndexOf(" to ")) + " ";
                temp = text.Substring(text.IndexOf(" to ") + 4);
                speech.SpeechText += temp;
                speech.Speaker     = "CaSI";
                AddtoSpeechList(speech);
            }
            else if (text.Contains("show"))
            {
                if (text.Contains("conversation"))
                {
                    listviewlayout.IsVisible = true;
                }
                else if (text.Contains("controls"))
                {
                    controlslayout.IsVisible = true;
                }
            }
            SpeechList.ItemsSource = null;
            SpeechList.ItemsSource = _speechlist;
            if (_speechlist[0].Speaker == "CaSI")
            {
                TextSpeaker(_speechlist[0].SpeechText);
            }
        }
Esempio n. 6
0
            /// <summary>
            /// Load the Dialogue XML Node from the Dialogue Script
            /// </summary>
            public void LoadDialogue(XmlNode _node, DialogueInstance _dialogueInstance)
            {
                foreach (XmlNode dialogueNode in _node.ChildNodes)
                {
                    if (dialogueNode.Name == "Item")
                    {
                        if (!_dialogueInstance.currentDialogue.ContainsKey((_dialogueInstance.defaultDialogueCount + 1).ToString()))
                        {
                            //Load Speech
                            SpeechItem speechItem = new SpeechItem(_dialogueInstance.defaultDialogueCount++);
                            speechItem.characterID = dialogueNode.Attributes["speaker"].Value;

                            if (dialogueNode.Attributes["audio"] != null)
                            {
                                speechItem.audioPrefabName = dialogueNode.Attributes["audio"].Value;
                                speechItem.audioPrefab     = Resources.Load <AudioClip>("Dialogue/SFX/" + speechItem.audioPrefabName);
                            }

                            if (dialogueNode.Attributes["music"] != null)
                            {
                                speechItem.musicClipName = dialogueNode.Attributes["music"].Value;
                                speechItem.musicClip     = Resources.Load <AudioClip>("Dialogue/Music/" + speechItem.musicClipName);
                            }

                            if (dialogueNode.Attributes["speed"] != null)
                            {
                                speechItem.customSpeed = float.Parse(dialogueNode.Attributes["speed"].Value);
                            }
                            else
                            {
                                speechItem.customSpeed = 1f;
                            }

                            if (dialogueNode.Attributes["size"] != null)
                            {
                                speechItem.customSize = float.Parse(dialogueNode.Attributes["size"].Value);
                                //Debug.Log("Loading #" + id + ": Size Parameter " + speechItem.customSize);
                            }
                            else
                            {
                                speechItem.customSize = 1f;
                            }

                            if (dialogueNode.Attributes["requireinput"] != null)
                            {
                                speechItem.requiresInput = bool.Parse(dialogueNode.Attributes["requireinput"].Value);
                            }
                            else
                            {
                                speechItem.requiresInput = true;
                            }

                            if (dialogueNode.Attributes["animation"] != null)
                            {
                                string[] animationParamStrings = dialogueNode.Attributes["animation"].Value.Split(':');

                                string        animationName = animationParamStrings[0];
                                List <object> parameters    = new List <object>();

                                if (animationParamStrings.Length > 1)
                                {
                                    for (int j = 1; j < animationParamStrings.Length; j++)
                                    {
                                        string        paramToParse = animationParamStrings[j];
                                        List <string> readIn       = new List <string>();
                                        string        current      = "";

                                        for (int i = 0; i < paramToParse.Length; i++)
                                        {
                                            if (paramToParse[i] == '(' || paramToParse[i] == ')' || paramToParse[i] == ',')
                                            {
                                                readIn.Add(current);
                                                current = "";
                                            }
                                            else
                                            {
                                                current += paramToParse[i];
                                            }
                                        }

                                        switch (readIn[0])
                                        {
                                        case "int":
                                            parameters.Add(int.Parse(readIn[1]));
                                            break;

                                        case "float":
                                            parameters.Add(float.Parse(readIn[1]));
                                            break;

                                        case "vec2":
                                            parameters.Add(new Vector2(float.Parse(readIn[1]), float.Parse(readIn[2])));
                                            break;

                                        case "vec3":
                                            parameters.Add(new Vector3(float.Parse(readIn[1]), float.Parse(readIn[2]), float.Parse(readIn[3])));
                                            break;

                                        default:
                                            Debug.LogError("Dialogue #" + (_dialogueInstance.defaultDialogueCount + 1).ToString() + " has a broken animation param");
                                            continue;
                                        }
                                    }
                                }

                                speechItem.animationName   = animationName;
                                speechItem.animationParams = parameters.Count > 0 ? parameters.ToArray() : null;
                            }
                            else
                            {
                                speechItem.animationName = null;
                            }

                            //Read in Text
                            if (dialogueNode.Attributes["text"] != null)
                            {
                                //TO DO
                                //- Run through Translation Manager

                                string originalText = dialogueNode.Attributes["text"].Value.Replace("\\n", "\n");

                                if (customStringSavingManager != null)
                                {
                                    originalText = customStringSavingManager.FixString(originalText);
                                }

                                string finalFormattedText = "";
                                string finalReadText      = "";

                                List <Dictionary <Effect.EffectType, Effect> > effects            = new List <Dictionary <Effect.EffectType, Effect> >();
                                Dictionary <Effect.EffectType, Effect>         currentEffectStack = new Dictionary <Effect.EffectType, Effect>();

                                if (!ReadInString(originalText, 0, currentEffectStack, ref effects, ref finalFormattedText, ref finalReadText))
                                {
                                    Debug.LogError("Dialogue #" + (_dialogueInstance.defaultDialogueCount + 1).ToString());
                                    continue;
                                }

                                speechItem.skipText           = false;
                                speechItem.finalFormattedText = finalFormattedText;
                                speechItem.finalReadText      = finalReadText;

                                //Send Effects to Speech Item
                                speechItem.textEffects = effects;
                            }
                            else
                            {
                                speechItem.skipText = true;
                            }

                            _dialogueInstance.currentDialogue.Add(speechItem.id.ToString(), speechItem);
                        }
                        else
                        {
                            Debug.LogError("Dialogue #" + (_dialogueInstance.defaultDialogueCount + 1).ToString() + "has already been declared");
                        }
                    }
                }
            }
Esempio n. 7
0
 public ActionResult <SpeechItem> Create(SpeechItem item)
 {
     _context.SpeechItems.Add(item);
     _context.SaveChanges();
     return(CreatedAtRoute("GetSpeech", new { id = item.Id }, item));
 }