コード例 #1
0
        static void Main(string[] args)
        {
            string subKey    = "01d2f52608044953b50c6b2e29891b92";
            string tokenUri  = "https://westus2.api.cognitive.microsoft.com/sts/v1.0/issueToken";
            string regionUri = "westus2";
            string ttsUri    = "https://westus2.tts.speech.microsoft.com/cognitiveservices/v1";

            Console.WriteLine("Hello! This is PiPA!");
            Authentication authenticator = new Authentication(subKey, tokenUri);
            string         token         = authenticator.GetAccessToken();

            SpeechToText speechToText = new SpeechToText(subKey, regionUri);

            while (true)
            {
                speechToText.SpeechContinuousRecognitionAsync().Wait();

                TextToSpeech textToSpeech = new TextToSpeech(speechToText.Command, token, ttsUri);
                textToSpeech.CreateSpeech().Wait();

                speechToText.RecognizeSpeechAsync().Wait();

                if (speechToText.Command == "add task")
                {
                    textToSpeech.Command = speechToText.Command;
                    textToSpeech.CreateSpeech().Wait();

                    speechToText.RecognizeSpeechAsync().Wait();
                    if (speechToText.Command == "name task")
                    {
                        textToSpeech.Text    = speechToText.Speech;
                        textToSpeech.Command = speechToText.Command;
                        textToSpeech.CreateSpeech().Wait();

                        if (speechToText.Command == "Error")
                        {
                            textToSpeech.Command = speechToText.Command;
                            textToSpeech.CreateSpeech().Wait();
                        }
                    }
                }
                else if (speechToText.Command == "unclear")
                {
                    textToSpeech.Command = speechToText.Command;
                    textToSpeech.CreateSpeech().Wait();
                }
            }
        }
コード例 #2
0
        private async void BtnToText_Clicked(object sender, EventArgs e)
        {
            var speech = new SpeechToText("{bing speech api key goes here");

            var result = await speech.RecognizeSpeechAsync(audioRecording.GetFilePath());

            System.Diagnostics.Debug.WriteLine(lblText.Text = result.DisplayText);
        }
コード例 #3
0
        public async Task ExecuteActionAsync()
        {
            SetTargetPhrase();
            Console.Clear();
            string  instruction  = $"Please say '{targetPhrase}', to the microphone. Press ENTER when you are ready.";
            TextBox instructions = new TextBox(instruction, Program.WINDOW_WIDTH / 2, 2, Program.WINDOW_WIDTH / 4, Program.WINDOW_HEIGHT / 3);

            Console.Clear();
            instructions.SetBoxPosition(instructions.TextBoxX, instructions.TextBoxY);
            instructions.FormatText(instruction);
            if (GameEngine.UseVoiceInput)
            {
                tts.SynthesisToSpeakerAsync("Narrator", instruction).Wait();
            }
            Console.ReadLine();
            result = await SpeechToText.RecognizeSpeechAsync();

            Console.SetCursorPosition((Program.WINDOW_WIDTH - 50) / 2, instructions.TextBoxY + 7);
            string msg = "";

            if (DidPlayerSucceed())
            {
                msg = "You won, +5 points. ";
            }
            else
            {
                msg = "You lost, -5 points. ";
            }
            msg += "Press ENTER to return";
            Console.WriteLine(msg);
            if (GameEngine.UseVoiceInput)
            {
                tts.SynthesisToSpeakerAsync("Narrator", msg).Wait();
            }
            Console.ReadLine();
        }
コード例 #4
0
        public async Task ExecuteActionAsync()
        {
            guessesRemaining = 3;
            SetTargetRiddle();

            Console.Clear();
            string  instruction  = $"Here's my riddle: {targetRiddle} ";
            TextBox instructions = new TextBox(instruction, Program.WINDOW_WIDTH / 2, 2, Program.WINDOW_WIDTH / 4, Program.WINDOW_HEIGHT / 3);

            Console.Clear();
            instructions.SetBoxPosition(instructions.TextBoxX, instructions.TextBoxY);
            instructions.FormatText(instruction);

            if (GameEngine.UseVoiceInput)
            {
                tts.SynthesisToSpeakerAsync("Narrator", instruction).Wait();
            }
            while (guessesRemaining > 0)
            {
                Console.SetCursorPosition(instructions.TextBoxX, instructions.TextBoxY + 10);
                string message = $"You have {guessesRemaining} chances remaining. Press ENTER when you are ready to answer";
                Console.WriteLine(message);
                if (GameEngine.UseVoiceInput)
                {
                    tts.SynthesisToSpeakerAsync("Narrator", message).Wait();
                }

                Console.ReadLine();
                result = await SpeechToText.RecognizeSpeechAsync();

                if (!DidPlayerSucceed())
                {
                    guessesRemaining--;
                    continue;
                }
                else
                {
                    break;
                }
            }


            Console.SetCursorPosition(instructions.TextBoxX, instructions.TextBoxY + 10);
            Console.WriteLine(new string(' ', Program.WINDOW_WIDTH));

            Console.SetCursorPosition((Program.WINDOW_WIDTH - 50) / 2, instructions.TextBoxY + 10);
            string msg = "";

            if (DidPlayerSucceed())
            {
                msg = "You won, +5 points. ";
            }
            else
            {
                msg = "You lost, -5 points. ";
            }
            msg += "Press ENTER to return.";
            Console.WriteLine(msg);
            if (GameEngine.UseVoiceInput)
            {
                tts.SynthesisToSpeakerAsync("Narrator", msg).Wait();
            }
            Console.ReadLine();
        }