Created
June 30, 2018 04:54
-
-
Save itechnotion/b959351e68a9c47bc1848c83bf2367e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Microsoft.CognitiveServices.Speech; | |
namespace SpeechToTextConsol | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
RecognitionWithFileAsync().Wait(); | |
Console.ReadLine(); | |
} | |
public static async Task RecognitionWithFileAsync() | |
{ | |
// <recognitionFromFile> | |
// Creates an instance of a speech factory with specified | |
// subscription key and service region. Replace with your own subscription key | |
// and service region (e.g., "westus"). | |
var factory = SpeechFactory.FromSubscription("318d1a2242e849aa888d57c95ed3d76a", ""); | |
// Creates a speech recognizer using file as audio input. | |
// Replace with your own audio file name. | |
using (var recognizer = factory.CreateSpeechRecognizerWithFileInput(@"/Users/avkash/Projects/dotnet/SpeechToTextConsol/SpeechToTextConsol/audio.wav")) | |
{ | |
// Starts recognition. It returns when the first utterance is recognized. | |
var result = await recognizer.RecognizeAsync().ConfigureAwait(false); | |
// Checks result. | |
if (result.RecognitionStatus != RecognitionStatus.Recognized) | |
{ | |
Console.WriteLine($"There was an error. Status:{result.RecognitionStatus.ToString()}, Reason:{result.RecognitionFailureReason}"); | |
} | |
else | |
{ | |
Console.WriteLine($"We recognized: {result.Text}"); | |
} | |
} | |
// </recognitionFromFile> | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment