1. Get the trial subscription
a. Browse to Cognitive Service trial link here.
b. Select Speech API tab
c. Click Get API Key and click Next while region is selected (Default: United States)
d. Resulting page would show relevant API endpoint and keys.
2. Sample Console Application to test
a. Start Visual Studio 2017
b. It is required to have .NET cross-platform development workload is available.
To check go to Tools > Get Tools and Features
d. Now install Speech NuGet Package
e. Add the code as below;
using System; using System.Threading.Tasks; using Microsoft.CognitiveServices.Speech; namespace CognitiveSrvSpeech1 { class Program { static void Main() { RecognizeSpeechAsync().Wait(); Console.WriteLine("Please press a key to continue."); Console.ReadLine(); } public static async Task RecognizeSpeechAsync() { var config = SpeechConfig.FromSubscription("<Subscription Key>", "<Region>"); // Creates a speech recognizer. using (var recognizer = new SpeechRecognizer(config)) { Console.WriteLine("Please say the text you need to convert..."); var result = await recognizer.RecognizeOnceAsync(); // Checks result. if (result.Reason == ResultReason.RecognizedSpeech) { Console.WriteLine($"We recognized: {result.Text}"); } else if (result.Reason == ResultReason.NoMatch) { Console.WriteLine($"NOMATCH: Speech could not be recognized."); } else if (result.Reason == ResultReason.Canceled) { var cancellation = CancellationDetails.FromResult(result); Console.WriteLine($"CANCELED: Reason={cancellation.Reason}"); if (cancellation.Reason == CancellationReason.Error) { Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}"); Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}"); Console.WriteLine($"CANCELED: Did you update the subscription info?"); } } } } } }
Make sure you replace the <Subscription Key> and <Region> with the values you obtained in 1.d step. Region is westus, if you left default United States region when getting the trial subscription.
f. Run the application and see how what you say is converted to text. Enjoy!
Ref: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/quickstart-csharp-dotnetcore-windows
No comments:
Post a Comment