using Microsoft.CognitiveServices.Speech; using Microsoft.CognitiveServices.Speech.Audio; 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; namespace WindowsFormsApp5 { public partial class Form1 : Form { private const string cKey = "key"; private const string cRegion = "region"; public static async Task SpeechToTextAsync() { var config = SpeechConfig.FromSubscription(cKey, cRegion); using (SpeechRecognizer 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?"); } } } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { SpeechToTextAsync().Wait(); //Console.WriteLine("Please press enter to exit."); //Console.ReadLine(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)