Hey guys I managed to get some code what works fine but it uses console application

I have tried to convert it by hand and change things around to get it to work but with no avail!

I'm certain it should be simple but I may be wrong :(

Thanks guys
ignore the vb.net

If you think I'm trying to be spoon fed I can post my converted code but it doesn't work and probably 99.9% wrong

Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;

namespace ConsoleApp1

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
         private const string cKey = "key";

    private const string cRegion = "region";


    public static async Task SpeechToTextAsync()

    {

        var config = SpeechConfig.FromSubscription(cKey, cRegion);

        using (var recognizer = new SpeechRecognizer(config))

            await Recognize(recognizer);

    }

    private static async Task Recognize(SpeechRecognizer recognizer)

    {

        var result = await recognizer.RecognizeOnceAsync();


        if (result.Reason == ResultReason.RecognizedSpeech)
        {

            Console.WriteLine($"Recognized: {result.Text}");

            SendKeys.SendWait(result.Text);
        }

        else if (result.Reason == ResultReason.NoMatch)

            Console.WriteLine("Speech could not be recognized.");

        else if (result.Reason == ResultReason.Canceled)

        {

            var cancellation =

                CancellationDetails.FromResult(result);

            Console.WriteLine

                ($"Cancelled due to reason={cancellation.Reason}");

            if (cancellation.Reason == CancellationReason.Error)

            {

                Console.WriteLine

                    ($"Error code={cancellation.ErrorCode}");

                Console.WriteLine

                    ($"Error details={cancellation.ErrorDetails}");

                Console.WriteLine

                    ($"Did you update the subscription info?");

            }

        }

    }

    static void Main()

    {

        SpeechToTextAsync().Wait();
        Console.WriteLine("Please press enter to exit.");
        Console.ReadLine();

    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.