private async void Speak(SpeechMessage speech)
        {
            var service = new Speech();

            await this.dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async() =>
            {
                try
                {
                    if (speech.Action != null && speech.Action.Equals("STOP"))
                    {
                        this.player?.Stop();
                    }
                    else
                    {
                        service.Speak(this.player, speech);
                    }
                }
                catch (Exception e)
                {
                    await
                    this.SendResult(new ResultMessage(speech)
                    {
                        Result = e.Message, ResultId = e.HResult
                    });
                }
            });
        }
Esempio n. 2
0
        public new bool TryDoSocialChat()
        {
            if (PAL == null)
            {
                Log.ErrorOnce("PAL is already null...", 927594);
            }
            if (Find.TickManager.TicksGame < lastTalkTime + MinPreferredTalkInterval)
            {
                return(false);
            }
            if (PAL == null || PAL.Destroyed || !PAL.HasPower)
            {
                return(false);
            }

            var source = Find.ListerPawns.AllPawns.Where(TalkUtility.CanTalk).ToArray();

            foreach (Pawn current in source.InRandomOrder())
            {
                if (current == null || !current.SpawnedInWorld)
                {
                    continue;
                }

                SpeechMessage speech = new SpeechMessage( // TODO: hook up trait for hating mechanoids
                    false ? ThoughtDefOf.AbrasiveTalk : ThoughtDefOf.SocialTalk);

                if (TryTalkTo(speech, current))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        public async void Speak(MediaElement audioPlayer, SpeechMessage speech)
        {
            var synth     = new SpeechSynthesizer();
            var ttsStream = await synth.SynthesizeTextToStreamAsync(speech.Message);

            audioPlayer.SetSource(ttsStream, "");
            audioPlayer.CurrentStateChanged += async(object sender, Windows.UI.Xaml.RoutedEventArgs e) =>
            {
                await MainPage.Instance.SendResult(new ResultMessage(speech) { ResultId = (int)audioPlayer.CurrentState, Result = Enum.GetName(typeof(MediaElementState), audioPlayer.CurrentState) });
            };
        }
 public new bool TryTalkTo(SpeechMessage speech, Pawn talkee)
 {
     if (!CanTalkTo(talkee))
     {
         return(false);
     }
     if (speech.ThoughtDef != null && talkee.needs.mood != null)
     {
         Thought_Memory thoughtMemory = (Thought_Memory)ThoughtMaker.MakeThought(speech.ThoughtDef);
         thoughtMemory.powerFactor = 1f;
         talkee.needs.mood.thoughts.TryGainThought(thoughtMemory);
     }
     MoteThrower.MakeSpeechOverlay(pawn);
     lastTalkTime = Find.TickManager.TicksGame;
     return(true);
 }
Esempio n. 5
0
    private void onMessage(IBasicConsumer sender,
                           BasicDeliverEventArgs args)

    {
        var body    = args.Body;
        var message = Encoding.UTF8.GetString(body);

        // Debug.Log (message);
        if (this.eventHandlers.ContainsKey(args.RoutingKey))
        {
            // var body = args.Body;
            // var message = Encoding.UTF8.GetString(body);
            // Debug.Log (message);

            switch (args.RoutingKey)
            {
            case EventType.Speech:
                SpeechMessage spMsg = JsonUtility.FromJson <SpeechMessage>(message);
                this.eventHandlers[args.RoutingKey](spMsg);
                break;

            case EventType.Hotword:
                HotwordMessage hwMsg = JsonUtility.FromJson <HotwordMessage>(message);
                this.eventHandlers[args.RoutingKey](hwMsg);
                break;

            case EventType.MidAirTokens:
                MidAirTokenMessage midAirTokenMessage =
                    JsonUtility.FromJson <MidAirTokenMessage>(message);
                this.eventHandlers[args.RoutingKey](midAirTokenMessage);
                break;

            default:
                break;
            }
        }

        // if(this.eventHandlers.ContainsKey(args.RoutingKey)) {
        //     this.eventHandlers[args.RoutingKey](sender, args);
        // }
    }